Skip to content

[codex] Send request-scoped turn state over WebSocket - #27996

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

[codex] Send request-scoped turn state over WebSocket#27996
aibrahim-oai merged 1 commit into
mainfrom
codex/turn-state-all-transports

Conversation

@aibrahim-oai

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

Copy link
Copy Markdown
Contributor

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.

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

Copy link
Copy Markdown
Contributor Author

@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: 8923c8c496

ℹ️ 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
@aibrahim-oai
aibrahim-oai force-pushed the codex/turn-state-all-transports branch from 8923c8c to 03b5d17 Compare June 13, 2026 01:30
@aibrahim-oai aibrahim-oai changed the title [codex] Send turn state on all model requests [codex] Send request-scoped turn state over WebSocket Jun 13, 2026
@aibrahim-oai

Copy link
Copy Markdown
Contributor Author

Stack continues in #28002. @codex review

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 03b5d176bd

ℹ️ 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 4e2195a to 3acc4ee Compare June 13, 2026 02:32
@aibrahim-oai

Copy link
Copy Markdown
Contributor Author

Pruned unrelated HTTP-only coverage; this PR now tests only the WebSocket behavior it changes. @codex review

Comment thread codex-rs/codex-api/src/sse/responses.rs Outdated
@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 merged commit 640d61b into main Jun 13, 2026
45 of 47 checks passed
@aibrahim-oai
aibrahim-oai deleted the codex/turn-state-all-transports branch June 13, 2026 07:44
@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