[codex] add compaction metadata to turn headers#24368
Merged
Merged
Conversation
This was referenced May 25, 2026
jif-oai
reviewed
May 26, 2026
|
|
||
| #[derive(Clone, Copy, Debug, Serialize)] | ||
| #[serde(rename_all = "snake_case")] | ||
| enum TurnMetadataRequestKind { |
Collaborator
There was a problem hiding this comment.
We shouldn't need this. We should re-use the session source or turn source or something else... this feels odd to add this. What about the other turn? Reviews for example? Or guardian
Contributor
Author
There was a problem hiding this comment.
I think these are orthogonal. Source identifies the originating thread/worker (e.g., review or guardian), while request_kind identifies the model action (turn, prewarm, compaction, memory). A review or guardian thread can issue different request kinds, so turn kind still matters. Does this make sense?
cdec59d to
1882e93
Compare
1882e93 to
716342e
Compare
jif-oai
approved these changes
May 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
request_kindvalues for foreground turn, startup prewarm, compaction, and detached memory model requests./v1/responses/compact, and remote v2 compact requests.window_idon turn-owned model request metadata.request_kind="memory"in non-git/no-sandbox workspaces.Root Cause
x-codex-turn-metadatahas more than one producer. Foreground turns and compaction requests own a real turn and should carry that turn identity. Detached memory stage-one requests do not own a foreground turn, so absent identity fields are valid rather than missing data. Startup websocket prewarm is also a model request, but it hasgenerate=falseand must not be counted as a foreground turn.thread_sourceor session source identifies where a thread came from (for example review, guardian, or another subagent).request_kindidentifies what the current outbound model request is doing (turn,prewarm,compaction, ormemory). A review or guardian thread can issue either a normal turn request or a compaction request, so source cannot replace request kind.Behavior / Impact
request_kind="turn", their real identity fields, andwindow_id="<thread_id>:<window_generation>".request_kind="prewarm"so they are not counted as foreground turns.request_kind="compaction", their real owning turn identity, the existingwindow_id, andcompaction.{trigger,reason,implementation,phase,strategy}.request_kind="memory"withoutsession_id,thread_id,turn_id, orwindow_id; when no workspace metadata exists, the kind-only header is still emitted.session_id,thread_id,turn_id, andwindow_idremain optional in the header schema because detached memory requests do not own a foreground turn or context window.window_idis not a new ID system: it is copied from the already-sentx-codex-window-id/ WS client metadata value at model-request dispatch time.x-codex-window-idHTTP/WS emission, value format, generation advancement, resume behavior, and fork reset behavior are unchanged.request_kind,window_id, and upstream turn-owned identity fields remain schema-owned; inputresponsesapi_client_metadatacannot replace their canonical values._metaschema changes are included.A compaction attempt stopped by a pre-compact hook issues no model request and therefore has no request header; its outcome remains in analytics events. Status, error, duration, and token deltas also remain analytics fields rather than request-header fields.
Future detached-memory attribution using a real initiating turn ID as
trigger_turn_idis intentionally not part of this PR.Sync With Main
716342e79is rebased ontoorigin/main@0d37db4b2.#24160, which addedforked_from_thread_idon the sameturn_metadatasurface. Resolution preserves that field and its protection from client metadata override alongside this PR's request-kind, compaction, and window-id fields.Latency / User Experience Boundary
prewarm.Validation
On conflict-resolved head
1d35c2cfbbased onorigin/main@487521733:just fmt(passed)just fix -p codex-core(passed)git diff --check origin/main...HEAD(passed)just test -p codex-core -E 'test(turn_metadata) | test(websocket_first_turn_uses_startup_prewarm_and_create) | test(responses_stream_includes_turn_metadata_header_for_git_workspace_e2e) | test(responses_websocket_forwards_turn_metadata_on_initial_and_incremental_create) | test(remote_compact_v2_retries_failures_with_stream_retry_budget) | test(window_id_advances_after_compact_persists_on_resume_and_resets_on_fork)'(23 passed;bench-smokepassed)just test -p codex-app-server -E 'test(turn_start_forwards_client_metadata_to_responses_request_v2) | test(turn_start_forwards_client_metadata_to_responses_websocket_request_body_v2) | test(auto_compaction_remote_emits_started_and_completed_items)'(3 passed;bench-smokepassed)just test -p codex-memories-write(29 passed;bench-smokepassed)After those tests completed,
origin/mainadvanced by#24658, whose only changed file iscodex-rs/core/src/goals.rs; the PR rebased cleanly to final pushed head716342e79. On that final pushed head:just fmt(passed)git diff --check origin/main...HEAD(passed)An earlier full
just test -p codex-coreattempt on a preceding base failed with broad unrelated environment symptoms (test_stdio_servermissing and shell/unified-exec timeouts); the focused metadata, websocket, compaction, and window tests listed above passed after the actualturn_metadataconflict resolution.