Repository navigation
fix(native-chat): save a Codex message's receipt from either of Codex's reports of it, not only the first - #30403
Conversation
…ed and which turn took it, with the turn's end Codex's exact-ID echo of a message and its answer naming the turn that took a message are kept until the journal holds them, saved at once and nonfatally, and any still unsaved go into the turn end's transaction and every exit's settlement. Turn ends record who ended them, whether receipt capture was complete, and a hook reason attributed to the turn.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
420bac12-ed49-46be-9877-d17d3d5ac5ee
📒 Files selected for processing: 52
src/main/codex/codex-journal-command-turn.tssrc/main/codex/codex-structured-dispatch-observations.tssrc/main/codex/codex-structured-dispatch-test-support.tssrc/main/codex/codex-structured-journal-contracts.tssrc/main/codex/codex-structured-journal-settlement.tssrc/main/codex/codex-structured-journal-sink.tssrc/main/codex/codex-structured-journal-thread-item-routing.tssrc/main/codex/codex-structured-journal-translation-settlement.test.tssrc/main/codex/codex-structured-journal-translation-turn-boundaries.tssrc/main/codex/codex-structured-journal-translation-turn-lifecycle.test.tssrc/main/codex/codex-structured-journal-translation-turn-settles-once.test.tssrc/main/codex/codex-structured-journal-translation-turns.tssrc/main/codex/codex-structured-journal-translation.test.tssrc/main/codex/codex-structured-journal-translation.tssrc/main/codex/codex-structured-journal-turn-endings-replay.test.tssrc/main/codex/codex-structured-session-acquire.tssrc/main/codex/codex-structured-session-adapter.tssrc/main/codex/codex-structured-session-close.tssrc/main/codex/codex-structured-session-journal.tssrc/main/codex/codex-structured-session-state.tssrc/main/codex/codex-structured-turn-start.tssrc/main/native-chat/agent-session-journal/journal-lifecycle-batch-appender.tssrc/main/native-chat/agent-session-journal/journal-observed-sends.tssrc/main/native-chat/agent-session-journal/journal-reducer.tssrc/main/native-chat/agent-session-journal/journal-row-schema.tssrc/main/native-chat/agent-session-journal/journal-row-unusable-annotations.tssrc/main/native-chat/agent-session-journal/journal-stop-and-resume-rows.tssrc/main/native-chat/agent-session-journal/journal-store-contracts.tssrc/main/native-chat/agent-session-journal/journal-store.tssrc/main/native-chat/agent-session-timeline/agent-journal-turn-row-revision.tssrc/main/native-chat/agent-session-wire/agent-session-journal-batch.tssrc/main/native-chat/agent-session-wire/structured-agent-session-adapter.tssrc/main/native-chat/agent-session-wire/structured-agent-session-child-exit.tssrc/main/native-chat/agent-session-wire/structured-agent-session-command-turn.tssrc/main/native-chat/agent-session-wire/structured-agent-session-dead-generation-settlement.test.tssrc/main/native-chat/agent-session-wire/structured-agent-session-event-recovery.tssrc/main/native-chat/agent-session-wire/structured-agent-session-host-types.tssrc/main/native-chat/agent-session-wire/structured-agent-session-host.tssrc/main/native-chat/agent-session-wire/structured-agent-session-late-dispatch.tssrc/main/native-chat/agent-session-wire/structured-agent-session-leftover-settlement.tssrc/main/native-chat/agent-session-wire/structured-agent-session-queued-command-refusal.tssrc/main/native-chat/agent-session-wire/structured-agent-session-stale-turn-verdict.test.tssrc/main/native-chat/agent-session-wire/structured-agent-session-stale-turn-verdict.tssrc/main/native-chat/agent-session-wire/structured-agent-session-transition.tssrc/main/native-chat/agent-session-wire/structured-agent-session-unexpected-exit.test.tssrc/main/runtime/structured-agent-session-codex-held-sends.test.tssrc/main/runtime/structured-agent-session-codex-opening-send-hold.test.tssrc/main/runtime/structured-agent-session-dispatch-followups.tssrc/main/runtime/structured-agent-session-lifecycle-delivery.tssrc/main/runtime/structured-agent-session-runtime.tssrc/shared/agent-session-journal-item-key.tssrc/shared/agent-session-journal-types.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.
…im for the rest of that child A per-turn record of lost receipts had to guess which turn a lost receipt belonged to, and an older Codex can answer a send with one turn while recording it in another. Capture now keeps one flag per child process: any loss (overflow, a receipt the journal can no longer take, a damaged frame, a user item with no readable id, a cleared capture) means no later turn end of that child claims every receipt was saved. Only a turn end that saves the held receipts with itself may write the claim.
…rn, not only when it blocks
Review loop status: head ba3d44f (full path)The problem. When Codex reports that it received a message (it echoes the message back with Orca's exact id), Orca saved that report in a separate write. If that write failed, the report was lost for good, so a message Codex actually ran could later look unconfirmed. Codex's answer naming which turn took a message wasn't saved at all, and a turn's end didn't record who ended it or whether every report for that turn had been captured. What changes for users. Nothing visible yet. Orca now keeps those reports until they're saved, writes any leftovers in the same database transaction as the turn's end (or in the cleanup when the chat exits), and saves who ended each turn, the answered-turn marks, and a prompt hook's block reason. The later change that turns these facts into "sent", "not sent" or "couldn't confirm" reads them. Fixed in review
Deferred / known gaps (listed in the PR body)
Verified
Not verified
Seen on both builds, not caused by this PR: a message sent during a running turn joins that turn and Codex's answer to the first request never appears; after Stop the chat keeps showing "Monitoring background tasks" until the next turn; the repo's default tab doesn't open; a promo covers the "Resume interrupted chats?" dialog. For Brennan's review
Places where a human judgment matters:
|
…om any echo of it Drop the completeness certificate, the answered-turn row, end provenance, the saved hook reason and the retention map with its turn-end retry and exit carry; none has a reader any more. A Codex echo now saves its send's receipt whenever the journal shows that send handed to this child and still unsettled, so the second echo retries a failed first save.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
b8f61dad-aa01-4b01-9844-1947d9d13f85
📒 Files selected for processing: 4
src/main/codex/codex-structured-session-acquire.tssrc/main/codex/codex-structured-session-journal.tssrc/main/native-chat/agent-session-wire/structured-agent-session-transition.tssrc/main/runtime/structured-agent-session-codex-held-sends.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
…al queue Codex now reports either exact live echo of a send, and the journal writes the acceptance only if the send is still unsettled when the write reaches its turn in the queue. A second echo therefore retries a receipt whose first save failed, and repeated receipts for any agent add no row or publication. This replaces the adapter-side check that read the journal at echo time, with its fence and handover conditions and the armed-entry fallback. Adapter tests that pinned "an unarmed echo settles nothing" now leave that to the journal, which ignores receipts for absent or settled sends.
…ho settling nothing An exact echo read after the child's exit is now reported like any other; the journal decides whether the send still owes a receipt.
…ecycle-codex-observations # Conflicts: # src/main/acp/acp-structured-host-lifecycle.test.ts # src/main/native-chat/agent-session-wire/structured-agent-session-late-dispatch.ts
Review loop status: finished on 88c07c0The problem. When you send Codex a message, Codex reports the message's id back twice, once when it starts recording it and once when it finishes, and Orca saves the first report as proof the message arrived. Orca decided whether that proof was still owed from an in-memory list, and the first report removes the message from it. So if the first save failed (a rare failed database write), the second report was ignored and the proof was lost. The user then saw a message that never got its confirmation, and after a Stop a direct send didn't lift the pause on queued messages. What changes for the user. One failed save no longer loses the proof: Codex's second report saves it. In that case a direct send after Stop now lifts the queue pause, as it already does when the first save works. Nothing else is different: no new label or wording, and withdrawn, refused or failed messages stay that way even if a report arrives later. How. Both reports are passed on. The chat's saved history decides inside its own write queue whether the receipt is still owed, so two reports save once. The PR is now about +27/-7 production lines; it was +763 before this rework, and it adds no saved field or wire change. What the loop did
Verified
Not verified
For Brennan's review
Three places where judgment matters:
|
…(fix red main) (#30865) * test(codex): the stopped-send receipt guarantee lives in the journal since #30403 #28046's dispatch-boundary tests pinned that the Codex adapter drops an echo for a stopped or refused send. #30403 moved that rule to the journal's queued late-accept write. Pin it there through the host's Stop path, and keep the adapter tests asserting what still holds at the adapter: no fallback or second turn/start write, and the earlier send's receipt survives an abandoned wait. * test: pin that a receipt after Stop adds no dispatch row
…ecycle-queue-derived-cards Conflicts, resolved so main's change stands and queued messages stay in the chat's journal, sent again only on proof the agent never got them: - #28046 (choices fixed per accepted message): its options type and its one reader reach the journal's queue row and the card fold too; the queued_messages writers it retyped stay deleted. - #30403 (Codex late receipt): the late settlement keeps both main's accept-at-its-turn path and this branch's unrun proof for a card. - A drain logging test main deleted stays deleted.


















ELI5
When Codex takes a message you sent, it repeats the message's id back to Orca, and Orca writes that down as proof the message arrived. Today Orca only tries to write it down once. If that one write fails, the proof is lost, even though Codex repeats the id a second time a moment later. This change lets Orca use either of Codex's repeats, so one failed write no longer loses the proof.
What Changed
The problem. Codex reports every message it records twice, back to back: once when it starts recording it and once when it finishes. Each report carries the message's id. Orca saves the first report as the message's receipt, the record that says "Codex got this". But Orca decided whether a receipt was still owed from an in-memory list of sends it was waiting on, and the first report removes the send from that list. So if the first save failed (a rare failed database write), the second report found nothing waiting and was ignored. The failure was only logged.
What a user saw in that case: the message never got its confirmation, and after a Stop, sending a message directly did not lift the pause on queued messages; they stayed held.
The user-facing change.
The mechanism. Orca still releases the send from its in-memory list on each exact report of its id; that is what tells the chat Codex is no longer holding it. Both reports are now passed on, and the chat's saved history decides whether a receipt is still owed, at the moment the write reaches its turn in the chat's write queue: the receipt is written only if the message is still waiting for a delivery answer, so two reports save once. This decision lives in the shared late-receipt path used by every agent, so for Claude, Pi and ACP agents too, a repeated receipt for a message that is already settled no longer writes an extra (ignored) saved row or sends clients an identical update.
Changed files:
codex-structured-session-journal.ts(pass on both reports),journal-submission-writer.tsandjournal-store.ts(the one "accept if still owed" write), andstructured-agent-session-late-dispatch.ts(route late receipts to it).Why
Earlier revisions of this PR built much more: a saved "every receipt for this turn is complete" marker, a saved "which turn answered this message" row, a record of who ended each turn, a saved prompt-hook reason, and an in-memory retention list whose entries were re-saved with the turn's end and when Codex exited. All of that existed so Orca could one day conclude "not sent" from a missing receipt. The decision since then is that Orca never says "not sent" because a receipt is missing; a message counts as sent only on Codex's exact report of its id. With that ruling none of those pieces has a reader, so this PR removes all of them before they ship. No new saved field or wire change remains.
Two narrower designs were considered. Keeping a separate retry list for failed receipt saves was rejected: the common pattern keeps the receipt in one place and clears remaining doubt later from the agent's own history, which is needed anyway for a crash before any save. Checking "still owed" in the Codex adapter when the report arrives (an earlier revision of this rework) was also rejected: the check ran before the write reached the queue, so two reports arriving while the queue was busy could both write, and it needed extra plumbing and a test-only fallback. Deciding inside the queued write is smaller and has one source of truth.
Known gaps (unchanged from main). A receipt whose save fails on both reports, a crash before any save, and a report Orca could not read at all leave the message without a confirmation, exactly as today. They are cleared by the planned positive replay of Codex's history.
Differences from the common pattern:
Linked Issue
Part of the native-chat send lifecycle work, after #29907 and #29922. Not a GitHub issue.
Visual Proof
Nothing new is drawn; these show the changed flows look the same on main and on this branch. Real Electron QA with the real Codex CLI in the chat view, on macOS (driven by an automated QA agent) and on Windows (send, steer, Stop then a direct send, quit and reopen). The main side is the commit this branch started from; the branch side is this PR's head. On both, every message got exactly one saved receipt and no duplicates. A failed first save can't be forced in the real app; the held-sends test covers it.
The queued-message flows couldn't be exercised: the message queue is switched off in this build, so a send during a reply steers it instead.
Testing
structured-agent-session-codex-held-sends.test.ts, through the shipped host, journal and Codex adapter with only the Codex process faked: one send, Codex reports it twice (started, then completed), and the first receipt save is made to fail. The send is still waiting after the first report and accepted after the second, in the host's saved record and in what clients receive. Fails on main.structured-agent-session-late-settlement.test.ts: two identical receipts at once plus a different one for an accepted send add no saved row (main wrote three); a receipt that arrives after a send was withdrawn leaves it withdrawn.Notes
Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)Author: @BrennanKB5