Expand description
Task 10A: trace wiring for the OpenAI-compatible transports — Chat
Completions (broker-proxied) and Responses/Codex (broker-proxied xAI and
direct ChatGPT-backend). Mirrors the Anthropic seam in trace::anthropic
and runtime/api.rs:
- Exact bytes only. The wire digest/length always come from the one
buffer serialized by the transport. Broker-backed sends pass that same
buffer through the typed
ProxyRequest::body_byteshandoff, whichLocalBrokersends verbatim. On a remote broker the daemon re-serializes the JSON value out of process, so those records carrywire: NoneandTransportKind::CloudProxy— never a digest of bytes this process did not send. - One record per actual HTTP send/attempt, sharing a request ID with
strictly increasing attempt ordinals (rule documented in
trace::emit). - Validated identity only. Error codes are static literals or
http_<status>; provider request IDs passTraceIdvalidation; normalized stop reasons come from a closed mapping. Raw provider text never enters a record. - Correctness firewall. Everything degrades to no-ops when the context is disabled or identity is unrepresentable.
Structs§
- Stream
Attempt - Per-attempt trace state for one OpenAI-compatible request: the optional tracer plus this attempt’s monotonic clock. Every method is a no-op when tracing is disabled; nothing here can fail the request.
Functions§
- attachment_
translation_ losses - Metadata-only attachment rewrites. Native image/file bytes survive, but origin labels and tool-result lifts synthesize user blocks; text documents are lowered from documents to ordinary input text. Never record filenames, tool outputs, URLs, or source payloads in this report.
- begin_
openai_ tracer - Begin tracing one OpenAI-compatible request. Returns
Nonewhen tracing is disabled or any structural identity is unrepresentable — tracing can never fail the request. - broker_
error_ status - Extract the upstream HTTP status from a redacted broker proxy error
(
… provider request failed: <status> <reason>). Returns only a parsed numeric status — never any provider-authored text. - capture_
request_ content - Text documents lose structural provenance on the OpenAI wire. Never let that lowering bypass attachment privacy: consume the optional content arm visibly without a bundle (metadata tracing still proceeds normally).
- provider_
request_ id_ from_ headers - Validate a provider-assigned request ID from response headers into a
bounded
TraceId. Invalid or hostile values are omitted — never copied raw into a trace record. - provider_
usage - Provider-reported usage for a trace record.
Noneinputs stay absent — zeros are only recorded when the provider actually reported them. - renamed_
tool_ losses - Translation-report entries for the rewrites the OpenAI adapter is known to perform today: tool names sanitized for the OpenAI wire grammar. Element IDs are the original names when they fit the bounded safe grammar; otherwise the entry stands without an ID (never raw text). The full per-element OpenAI IR report is incremental follow-up work (Task 9 allows per-provider reports to land incrementally) — but a known rename is never silently claimed lossless.
- retry_
class_ for_ status - Map an OpenAI-compatible HTTP failure status to a coarse retry class.
- stop_
reason_ from_ finish_ reason - Normalize an OpenAI Chat Completions
finish_reasoninto the trace enum. Unknown values collapse toOther— the raw string is never stored.