Skip to content

core: Consolidate Responses API Codex metadata#27122

Merged
owenlin0 merged 3 commits into
mainfrom
owen/consolidate_responsesapi_request_metadata
Jun 11, 2026
Merged

core: Consolidate Responses API Codex metadata#27122
owenlin0 merged 3 commits into
mainfrom
owen/consolidate_responsesapi_request_metadata

Conversation

@owenlin0

@owenlin0 owenlin0 commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

What

Introduce a CodexResponsesMetadata struct that defines all the core metadata we send to Responses API. Example fields are thread_id, turn_id, window_id, etc.

Going forward, client_metadata["x-codex-turn-metadata"] will be the canonical way Codex sends metadata to Responses API across both HTTP and websocket transports.

For now, we continue to emit the existing top-level HTTP headers and top-level client_metadata fields from the same CodexResponsesMetadata struct for compatibility reasons.

Also, app-server clients who specify additional responsesapi_client_metadata via turn/start and turn/steer will have those fields merged into client_metadata["x-codex-turn-metadata"], but cannot override the reserved fields that core uses (i.e. the fields in CodexResponsesMetadata).

Why

Responses API request instrumentation is the source of truth for downstream Codex analytics that join requests by Codex IDs such as session, thread, turn, and context window. Before this change, those values were assembled through several request-specific paths: HTTP request bodies, websocket handshake headers, websocket response.create payloads, compaction requests, and the rich x-codex-turn-metadata envelope all had their own wiring.

That made metadata propagation easy to drift across API-key/direct Responses API requests, ChatGPT-auth/proxied requests, websocket requests, and compaction requests. It also made additions like window_id error-prone because a field could be added to one transport projection but missed in another.

What changed

  • Added CodexResponsesMetadata as the core-owned snapshot for Codex metadata sent to ResponsesAPI.
  • Render client_metadata["x-codex-turn-metadata"], flat client_metadata projections, and direct compatibility headers from that same snapshot.
  • Include the known Codex-owned fields in the turn metadata blob, including installation/session/thread/turn/window IDs, request kind, lineage, sandbox/workspace metadata, timing, and compaction details.
  • Treat app-server responsesapi_client_metadata as enrichment for the Codex turn metadata blob while preventing those extras from overriding Codex-owned fields.
  • Use the same metadata path for normal turns, websocket prewarm, local compaction, remote v1 compaction, and remote v2 compaction.
  • Keep websocket connection-only preconnect metadata separate so handshakes carry compatibility identity headers without inventing a fake turn metadata blob.

Verification

  • cargo check -p codex-core
  • just fix -p codex-core

@owenlin0 owenlin0 changed the title consolidate responsesapi request metadata Consolidate Responses API request identity metadata Jun 9, 2026
@owenlin0 owenlin0 changed the title Consolidate Responses API request identity metadata Consolidate Responses API Codex metadata Jun 9, 2026
@owenlin0 owenlin0 force-pushed the owen/consolidate_responsesapi_request_metadata branch from 0cfe73b to fb11500 Compare June 9, 2026 21:21
@owenlin0 owenlin0 changed the title Consolidate Responses API Codex metadata core: Consolidate Responses API Codex metadata Jun 9, 2026
@owenlin0 owenlin0 marked this pull request as ready for review June 9, 2026 21:24
@owenlin0 owenlin0 requested a review from a team as a code owner June 9, 2026 21:24
owenlin0 added a commit that referenced this pull request Jun 9, 2026
Comment thread codex-rs/core/src/client.rs Outdated
- "thread_id": "<UUID>",
- "turn_id": "<UUID>",
- "x-codex-installation-id": "<UUID>",
- "x-codex-turn-metadata": "{\"installation_id\":\"<UUID>\",\"session_id\":\"<UUID>\",\"thread_id\":\"<UUID>\",\"turn_id\":\"<UUID>\",\"window_id\":\"<UUID>:0\",\"request_kind\":\"turn\",\"sandbox\":\"<SANDBOX>\",\"turn_started_at_unix_ms\":<UNIX_MS>}",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this feels excessive

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the fact that we are repeating same values this many times.

I assume they are also repeated in request headers

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pakrym-oai yeah, I am planning to delete the top-level ones once i make sure codex-backend and responsesapi don't rely on them. my goal is x-codex-turn-metadata is the source of truth

@owenlin0 owenlin0 Jun 10, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately it looks like i'm adding these fields here for compaction requests, but that's just because I'm trying to make the metadata consistent for all the requests we make to responsesapi and we currently send these on responses generate calls too

Comment thread codex-rs/app-server/tests/suite/v2/client_metadata.rs Outdated
@owenlin0 owenlin0 force-pushed the owen/consolidate_responsesapi_request_metadata branch 5 times, most recently from 14dfdbb to a5a6129 Compare June 10, 2026 16:57
owenlin0 added a commit that referenced this pull request Jun 10, 2026
@owenlin0 owenlin0 force-pushed the owen/consolidate_responsesapi_request_metadata branch from 3d0ac57 to 2637659 Compare June 11, 2026 20:11
@owenlin0 owenlin0 merged commit 14df0e8 into main Jun 11, 2026
31 checks passed
@owenlin0 owenlin0 deleted the owen/consolidate_responsesapi_request_metadata branch June 11, 2026 20:42
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 11, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants