Repository navigation
fix(codex): a message whose turn was stopped before Codex took it is withdrawn, not stuck - #23618
Conversation
…fter that turn's rows A settlement that says a streamed turn ended waits for the session's event sink to drain before writing its dispatch row. The journal reducer still refuses to overwrite an accepted or rejected send.
…into The turn/start answer names the turn that holds a send. The send's echo entry now keeps that binding, in memory only. If the bound turn is interrupted without echoing the send, the send is withdrawn: Codex clears a turn's pending input on interrupt, so the model never saw it. If the turn fails first, the send is rejected in Codex's words. A completed turn settles nothing, since Codex records pending input when it finishes and the echo is still due. An answer read after its turn already ended is settled by that end. The echo is still the acceptance and carries the item key.
…t into The fake Codex keeps 0.157's turn bookkeeping, and can deliver the turn/start answer after turn/started or after turn/completed. The tests cover: - a Stop before any echo withdraws the send, and the working rule reads idle; - a steered follow-up is withdrawn when the turn is interrupted; - a failed turn rejects the send in Codex's words; - a completed turn leaves the send to its echo; - a normal echo and a late echo; - two steered sends in one turn; - an answer read after the turn ended; - a timed-out answer; - child-thread turns; - how a binding dies.
…ettlement Nothing reads the order of a dispatch row against the turn's terminal row: the reducer keeps a settled send terminal and the working state is derived from both. The echo acceptance on the same path never waited either, and the wait could drop the settlement on a failed sink barrier.
Codex keeps a failed turn's pending input and records it after the error frame, before turn/completed. Settling at the error rejected a steered follow-up the model had in fact received, so a Retry would send it twice.
Codex records a completed turn's pending input before `turn/completed`, so a bound send that turn never echoed is left for recovery, not awaiting an echo. The comments and one test title said the echo was still due.
… or completed A failed turn that ended before the answer rejects the send in Codex's words, once; a completed one leaves it admitted and still armed for its echo.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This settles a Codex send whose turn ended without echoing it, replacing a wait that only ended when the Codex process exited.
- Turn binding (
codex-structured-dispatch-echo.ts) — armed sends gain an optionalturnkey;bindTurnrecords the turn Codex answered into and returns any already-recorded end, andendTurnrecords recent ends (bounded at 64) and returns the sends that end settles. Only non-completedends settle, matching Codex echoing a completed turn's input before it ends. - Settlement policy (
codex-structured-turn-end-settlement.ts) — reads the end from aturn/completed, mapsinterrupted→cancelled(withdrawn) andfailed→providerRejectedwithturn.error.message, ignores non-primary threads and other frames.codexDispatchRejectionmoved here fromturn-start.ts. - Dispatch path (
codex-structured-turn-start.ts) —startCodexTurnreturns the answered turn; an answer read after that turn already ended returns the ending's rejection directly. - Adapter wiring — settlements fire on an already-admitted notification and route through the existing late-settlement path; the deps union and
settleStructuredAgentSessionLateDispatchalready handle the rejected arm, and the journal reducer keeps accepted/rejected terminal for idempotence. - Tests — unit coverage for the echo/end orderings, late answers, timeouts, child threads, and process-exit clearing; host end-to-end coverage that a quick Stop and a stopped follow-up both end withdrawn with nothing owed.
I verified the load-bearing Codex contract against its source: TurnCompletedNotification { thread_id, turn }, Turn.status, and Turn.error.message on a failed turn (the completion handler in bespoke_event_handling.rs populates turn.error from the turn's recorded last_error), so the failed-turn reason is real and not only on the separate error frame. The retry queue is FIFO, so an accepted echo cannot be overtaken by the turn's completion.
pnpm test on both new files (18 passed) and pnpm tc:node are clean. The documented residual gaps (a send into a completed turn that never echoes; a turn/start answer that timed out is never bound) are pre-existing limits, not regressions.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Incremental review of the one commit pushed since the prior review (3380874e).
- Typed failed-turn reason reader — the failed-turn reason moved from a local
field/errorDetailpair incodex-structured-turn-end-settlement.tstoreadCodexTurnErrorMessageoncodex-structured-thread-facts.ts, readingpayload.turn.error.messagethrough the existingrecord/nonEmptyStringhelpers and rejecting empty strings. The settlement now mapsfailed→providerRejectedwith that detail. Behavior-preserving; the sentence builder already trimmed an empty detail to nothing, so no user-visible change.
No other files changed. The core mechanism reviewed earlier is untouched.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
StatusReady for review. Head The failure: Orca marks a Codex message delivered only when Codex repeats it back. If the turn it was sent into is interrupted first, Codex discards it (it clears the turn's pending input on interrupt), so the message stayed waiting until the Codex process exited and the chat read Working. The fix: it removes that cause rather than guarding it. Each message is linked, in memory, to the turn Codex's answer named, and it is settled from how that turn ended: interrupted means withdrawn; failed means refused with Codex's reason and Retry; completed means left to its echo, which Codex sends before reporting the turn completed. Nothing new is saved, and nothing on the wire changes. Review
Validation
Known, not in this PR
Review session at
|
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (10)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review. 📝 WalkthroughWalkthroughTurn-start responses now provide a turn ID that dispatch sends can bind to. Matching interrupted and failed turn-end notifications settle bound sends as rejected; completed turns leave un-echoed sends pending. The adapter reports late settlements, and unit and runtime tests cover turn-end outcomes, delayed responses, echoes, and Stop scenarios. Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to The turn-end settlement change is mergeable after normal checks; no actionable issue remains from this review. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change is confined to Codex message settlement within an existing session. No new external access or expanded privileges were identified. Rare delayed responses and failure recovery remain uncertain. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…3614) into #23059 Conflicts, resolved to keep main's mechanism and #23059's turn facts: - Codex turn boundaries and translator: main's #23682 wins; the error-driven `fail` end and the oversized-notification settler are gone, and only `turn/completed` ends a turn, a command's turn included. - Codex adapter: the compaction tracker stays deleted; #23618's settlement of sends in an ended turn is kept, and `codexDispatchRejection` is imported from its new home. - Journal reducer: main's per-item creating fence (#23456) moves into the item and submission folds this branch split out of the reducer. - Stale-turn verdict: main's proof-of-death revision; every turn revision states the thread scope. - Failure words: main's retry-control rules (#23608) with this branch's any-command retry step; `commandRefused` drops its retry step beside a Retry, as hostFault does. - Delivery: both the commit wake and main's death-evidence resettle and dispose. - Fold row and transcript slots: both the turn-outcome flag and main's `agentId`. - pr.yml and pnpm-lock.yaml taken from main. Beyond the conflicts, the merged files needed: - use-structured-agent-session: both sides added the same `submissions` key; one kept. - structured-agent-session-projection: the root-item import main still used is unused here. - The desktop message list and the mobile chat view each grew past the line limit from both sides' additions: the turn-membership memo moves into its own hook, and the mobile list footer (live status, then waiting rows) into its own helper.
Main now settles a Codex send from the turn it was answered into (#23618, #23679, #23850): an interrupted or failed turn that never echoed a send withdraws or refuses it, and a completed turn leaves it to its echo, which Codex records before turn/completed. That replaces this branch's own mechanism, so every conflict resolves to main: - journal-level terminal settlement (ownerEndedClientMessageIds, multi-row enqueueMany, terminalTurnFences, canResolveDispatch, hasTerminalTurn, turn_settled_before_acknowledgement) and the sink's onCommitted/onAbandoned/onDiscarded plumbing - the dispatch-echo ownership model (start candidates, started evidence, terminal snapshots) and the late-settlement retry - the connection's onResult response observer - the shared-predicate command admission, which main expresses with its own fence and handover rules (#23524) Codex's turn/steer, the part the host-owned queue still needs, is re-expressed on main's model in the following commit.

ELI5
In a Codex chat, if you pressed Stop just as Codex started, or sent a follow-up while Codex was answering and then pressed Stop, the chat could get stuck saying "Working…" forever and the message stayed as "sent". Codex had thrown that message away, but Orca kept waiting for Codex to confirm it. Now, when the turn a message was sent into ends without Codex taking it, Orca takes the message back and the chat goes idle.
What Changed
Before
turn/startrequest first, and repeats the message a little later. A follow-up sent during a turn is folded into that turn and repeated later still.main: 3 of 6 quick Stops right after a first message, and 3 of 3 follow-ups stopped mid-answer, were still stuck up to 14 minutes later, when the test ended.After
turn/start, Orca notes in memory which turn that message went into. For a follow-up, that is the running turn.Mechanism
startCodexTurnreturns the turn id from the answer.bindTurn(codex-structured-dispatch-echo.ts) records it on that message's pending-echo entry, for the main thread only.settleCodexSendsInEndedTurn(codex-structured-turn-end-settlement.ts) runs on each main-threadturn/completedand settles that turn's un-echoed messages through the existing late-settlement path. The journal already refuses to change a message once it is settled, so an echo that arrives later changes nothing.turn/completed, not at itserrorframe. Codex keeps a failed turn's pending input and repeats it before reporting the turn complete, so settling at the error would reject a message Codex actually kept. Retry would then send it twice.Nothing new is saved. The message-to-turn link lives only in memory, for the life of the Codex process. The settlements use outcomes the journal already stores.
Why
The waiting state had no way to end except the Codex process exiting, and nothing in Orca watched the one fact that decides it: how the turn carrying the message ended. Codex's own rule is simple. An interrupted turn discards its pending input, and a finished or failed one records it first. So reading the turn's ending gives a true answer for every message, with no timer and no guess.
Alternatives considered:
turn/start. Orca did this before fix(codex): settle a structured send on admission, and stop minting a colliding identity #20138 and removed it. A follow-up is answered with the running turn's id, so two messages ended up with the same saved identity, which rewind, restore and turn timing all rely on being unique. It would also record as delivered a message the model never received.Differences from the common pattern
turn/start, and keeping the per-message link in memory only.maintoday.Linked Issue
No issue. Found in live QA of #23026 against real Codex. It reproduces on
mainwithmain's own Stop.Visual Proof
Live QA on this laptop with the real Codex app-server (0.157), in structured Codex chats, with an isolated app profile. Before is
main, after is this PR; both also carry #23552 for the test rig.main)Before: a follow-up stopped mid-answer, still "Working" 80 s later:
After: the stopped turns stay, the withdrawn follow-ups are gone, and the composer shows Send:
Before: a Stop right as the turn opened, stuck:
After: the same Stop, settled:
What a user sees with this PR alone: the withdrawn message leaves the transcript, and its text does not come back. Returning it to the message box is #23026's job. The "Cancellation requested." row and the tab's red interrupted dot are
main's existing design.Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
codex-structured-turn-end-settlement.test.ts(16 tests):errorframe is accepted;structured-agent-session-codex-turn-end-settlement.test.ts(host, end to end): a quick Stop and a stopped follow-up both end withdrawn, and the session reads idle.codex-turn-lifecycle-fake.ts: a fake Codex that refuses an interrupt beforeturn/started, as Codex 0.157 does, and that can deliver its answer out of order withturn/startedandturn/completed.Each behaviour was removed in turn, and its own test failed by assertion, not by timeout: 13 ablations across three review rounds.
pnpm tc:nodeandtc:cli, fulloxlinton every changed file,check:code-quality:changedandcheck:react-doctor:changedpass. The related Codex test files (dispatch echo and admission, session adapter, session close, turn timing) pass.Live: the table above. The real
~/.codexand~/.claudefiles were checked before and after every run (65 checks) and never changed.Not run: SSH, Windows and Linux. The change is in the Codex adapter on the machine that runs Codex, so it behaves the same on an SSH host.
AI Disclosure
Review
Three review rounds.
errorframe), and removed an unneeded wait before the settlement write.Mixed versions
Nothing on the wire changes. The rows are existing states: a withdrawn message and a refused message, each with an existing reason. An older client already shows both. It now sees one of them where it used to see a message stuck as sent.
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)Author: @BrennanKB5