[codex] Use unique IDs for realtime-routed turns#28826
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d760327b23
ℹ️ 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".
| let turn_id = loop { | ||
| let event = test.codex.next_event().await?; | ||
| if let EventMsg::TurnStarted(turn_started) = event.msg { | ||
| break turn_started.turn_id; |
There was a problem hiding this comment.
Capture TurnStarted before it can be discarded
When the routed realtime turn wins the scheduling race, route_realtime_text_input can spawn the task and emit TurnStarted before the fanout sends the HandoffRequested realtime notification; the preceding wait_for_event_match then consumes and drops that TurnStarted, so this loop waits for a second one that never arrives and the test hangs. Capture the turn id in a single event-draining loop (or start waiting for TurnStarted before waiting for the handoff notification) so either event order passes.
Useful? React with 👍 / 👎.
Why
A durable realtime voice orchestrator can reconnect and resume through multiple fresh
Sessioninstances. Realtime handoffs were using the Session-localauto-compact-Ncounter as their turn identity, but that counter restarts at zero for every resumed Session. The durable thread could therefore accumulate duplicate turn IDs, violating the uniqueness assumptions made by app-server and web clients. In Codex Apps, a new delegated response stream could be attached to an older turn with the same ID, placing live output higher in history and putting turn-scoped actions at risk.Persisted rollout and reconstructed model-context order were already correct because raw response items remain append-only and chronological. This change restores unique identity for reconstructed and live turn surfaces.
What changed
auto-compact-Nidentity path unchanged for actual internal auto-compaction turns.turn/started.Verification
just test -p codex-core inbound_handoff_request_starts_turnjust fix -p codex-corejust fmt