Skip to content

[codex] Send turn state through compact requests - #28002

Merged
aibrahim-oai merged 1 commit into
mainfrom
codex/compact-turn-state-all-transports
Jun 13, 2026
Merged

[codex] Send turn state through compact requests#28002
aibrahim-oai merged 1 commit into
mainfrom
codex/compact-turn-state-all-transports

Conversation

@aibrahim-oai

@aibrahim-oai aibrahim-oai commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Context

Inline compaction is part of the active logical turn. Compact requests and the sampling requests around them should use the same turn state, including when compaction is the first request to establish it.

Change

Pass the turn-scoped OnceLock directly to inline v1 compaction so /responses/compact includes an established value in the existing HTTP header. Capture x-codex-turn-state from the compact response into that same lock, allowing pre-turn compact to establish the value that subsequent sampling reuses.

V2 compact already uses the normal Responses HTTP/WebSocket path and continues to share the same OnceLock without separate plumbing. The first returned value wins for the logical turn.

Test plan

Integration coverage verifies that:

  • pre-turn v1 compact can establish state for the first sampling request
  • inline v1 compact receives established state over HTTP
  • inline v2 compact reuses established state over HTTP
  • inline v2 compact reuses established state over WebSocket

CI validates the full change.

@aibrahim-oai
aibrahim-oai requested a review from a team as a June 13, 2026 01:31
@aibrahim-oai

Copy link
Copy Markdown
Contributor Author

Stacked on #27996. @codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d698cbb176

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/core/tests/suite/compact_remote.rs
@aibrahim-oai
aibrahim-oai force-pushed the codex/compact-turn-state-all-transports branch from d698cbb to 5e518a9 Compare June 13, 2026 01:40

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5e518a9aa4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/core/tests/common/Cargo.toml Outdated
@aibrahim-oai
aibrahim-oai force-pushed the codex/compact-turn-state-all-transports branch from 5e518a9 to c7e0373 Compare June 13, 2026 02:01
@aibrahim-oai

Copy link
Copy Markdown
Contributor Author

Updated the response-capture model to always pass the turn-state lock and gate writes by explicit request type. @codex review

@aibrahim-oai
aibrahim-oai force-pushed the codex/compact-turn-state-all-transports branch from c7e0373 to 87ab079 Compare June 13, 2026 02:20
@aibrahim-oai

Copy link
Copy Markdown
Contributor Author

Replaced the parallel request-type field with a single TurnState handle that owns the lock and capture policy. @codex review

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 87ab079d82

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@aibrahim-oai
aibrahim-oai force-pushed the codex/compact-turn-state-all-transports branch from 87ab079 to 2009ed4 Compare June 13, 2026 02:29
@aibrahim-oai

Copy link
Copy Markdown
Contributor Author

Removed the request classification and wrapper entirely. V2 now keeps the existing first-value-wins behavior; PR2 only adds v1 compact propagation and integration coverage. @codex review

@aibrahim-oai
aibrahim-oai force-pushed the codex/turn-state-all-transports branch from 4e2195a to 3acc4ee Compare June 13, 2026 02:32
@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 2009ed44c7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@aibrahim-oai
aibrahim-oai force-pushed the codex/compact-turn-state-all-transports branch from 2009ed4 to 8addb95 Compare June 13, 2026 02:32
@aibrahim-oai

Copy link
Copy Markdown
Contributor Author

Pruned pre-turn and standalone tests that exercised unchanged behavior; retained v1 HTTP, v2 HTTP, v2 WebSocket, and cross-transport coverage. @codex review

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 8addb953de

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@aibrahim-oai
aibrahim-oai force-pushed the codex/turn-state-all-transports branch from 3acc4ee to 572f6ee Compare June 13, 2026 02:36
@aibrahim-oai
aibrahim-oai force-pushed the codex/compact-turn-state-all-transports branch from 8addb95 to f7f8215 Compare June 13, 2026 02:37

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f7f8215f01

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/core/src/client.rs
Comment thread codex-rs/core/src/compact_remote.rs Outdated
Comment thread codex-rs/core/tests/common/responses.rs
@aibrahim-oai
aibrahim-oai force-pushed the codex/turn-state-all-transports branch from 572f6ee to 00c8016 Compare June 13, 2026 07:12
@aibrahim-oai
aibrahim-oai force-pushed the codex/compact-turn-state-all-transports branch from 8509717 to 1252e17 Compare June 13, 2026 07:14
aibrahim-oai added a commit that referenced this pull request Jun 13, 2026
## Context

Turn state is scoped to one logical turn, but the WebSocket path
currently exchanges it through upgrade headers, which are scoped to the
physical connection. A connection may be reused across turns, so its
handshake cannot represent the turn lifecycle reliably.

## Change

Exchange turn state on each WebSocket response request instead:

- send an established value in `response.create.client_metadata`
- read the returned value from the existing `response.metadata` event
- retain the first value in the turn-scoped `ModelClientSession`
`OnceLock`
- start the next logical turn without state, even when it reuses the
same WebSocket connection

This gives WebSocket requests the same first-value-wins contract as the
existing HTTP path.

## Test plan

Integration coverage verifies that:

- WebSocket replays returned state on same-turn follow-ups
- later response metadata does not replace the first value
- state resets at the logical turn boundary without requiring a
reconnect

CI validates the full change.

## Stack

This is 1/2. #28002 builds on this request-scoped transport to carry
established state through compact requests.
Base automatically changed from codex/turn-state-all-transports to main June 13, 2026 07:44
@aibrahim-oai
aibrahim-oai force-pushed the codex/compact-turn-state-all-transports branch from 1252e17 to a568cdb Compare June 13, 2026 07:45
@aibrahim-oai
aibrahim-oai merged commit f297b9f into main Jun 13, 2026
46 of 47 checks passed
@aibrahim-oai
aibrahim-oai deleted the codex/compact-turn-state-all-transports branch June 13, 2026 08:28
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 13, 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