Repository navigation
fix(native-chat): hold a queued message until the turn ahead opens (follow-up to the Stop-event plan, fixes STA-9348) - #25217
Conversation
…keeps it paused Red on main: Codex's turn end withdraws the steered hand-off and the queue sends the card again as a new host turn, with no pause recorded.
… still unanswered A card sent now into the running turn was still pending when Stop judged the pause, so nothing was recorded; the interrupt then withdrew the hand-off, the card went back to waiting unpaused, and the queue sent it again as a new turn. The pause now counts a hand-off that may still return to waiting, judged with the appended row applied, so a withdrawal lands under the pause and an acceptance retires it in that same write. Codex and Claude both hit it.
…the test's budget
…ry path that ends it The provider's answer, the provider dying, the chat closing, a restart, a withdrawal still owed at open, and a /clear (refused until the hand-off ends, then carrying every waiting card paused 'cleared'); each ends with the queue sending again.
…op-keeps-steered-card
… queued receipt's card
…op-keeps-steered-card
…journal rows Stop now appends one journal row where it takes effect, before the interrupt, whatever the queue holds; Resume appends its own. The pause is a pure function of the fold: the latest Stop with no later Resume and no later accepted turn a person asked for. A /clear's carried cards name their source, which is the replacement's 'cleared' pause. Host-origin turns never lift either. One predicate decides which cards a pause holds; by default every waiting card without a hold of its own, including one queued after the Stop. The drain's consume re-judges it inside its own transaction. The rows are tombstones of an id no item takes, carrying the mark: a released host reads an unknown row kind as corruption and truncates the journal there. Deletes the stored pause (recordPause, the retire hook on every appended row, the settle-before-record step, mayReturnToWaiting and its row overlay) and the tests that only proved it retires. The queued_message_pauses table stays in the schema, unread and unwritten, for downgrade safety.
…ead of held ones A Stop's pause now holds only the cards queued before its row, plus a steer it withdrew, which returns to its own place. Each card records the journal position it was queued at, and the one hold rule compares that with the Stop row. A card queued after the Stop is a new instruction: it sends as usual, but the drain still stops at the first held card, so it never overtakes them. /clear's pause holds the cards it carried. Holding every card again is a one-line switch in that rule.
… in its transaction The drain's pick and its consume now read one function, nextSendableQueuedCard, so a Stop row that lands between them holds a newer card behind an older held one exactly as the pick would. Notes why Stop and Resume ride a tombstone row.
…op-keeps-steered-card
The queue's pause is derived from journal rows, so nothing reads or writes queued_message_pauses. It was still created on every open "for downgrade safety", but an older build creates it itself when it opens the database, so the table only sat empty in every new database. The tests now pin that no pause table exists.
A Stop holds only the cards queued before it. The pause derivation still returned the Stop alone whenever it was in force, so the restart pause was never considered: a card queued after the Stop, written by a host process that has since exited, sent by itself after Orca restarted, with no pause header and no Resume. A /clear pause that held nothing could hide it the same way. Every pause in force is now derived. A card is held if any of them holds it, and it names the first that does. The drain's pick, the consume transaction's re-check and the published header all read that one rule; the header names the pause holding the first card Resume would send.
- The Claude and Codex Stop-withdraws-a-steer tests checked "not sent again" at one instant, before a queue ignoring the pause re-sends. They now wait for the stopped turn to end and re-check after a quiet window. - The deleted-card test read a card queued after the Stop, which sends whether or not a person's turn lifts it; it now reads the Stop's pause before and after that turn. - Unit cases pin that a Stop holds a card with no recorded position and one queued before a rewind.
…op-keeps-steered-card
…turn and caller
The Stop row that paused the queue becomes the general Stop event
{ reason, turnId?, at, caller? }, whose reason is the host's existing stop
cause. It still rides a tombstone of a host-only id (a released host deletes
the journal from the first unknown row kind), and Resume keeps its own marker
on its own id. Only a person's Stop (reason user-stop) pauses the queue.
…states the same Stop event
… the at-start stop Through the real host: the event names the turn and who asked and is in the journal when the interrupt reaches the agent; at an agent still starting it is there before the start is ended and holds a card queued before it; an idle Stop writes one only when it withdrew a send; and the queue's claim re-judges a pause that landed after its pick.
…the Stop's timing Also says precisely what the claim's in-transaction pause check defends against: the Stop and the drain share one serialized lane.
… Stop events Replays this build's rows from the released build's own journal database: every row is kept, the history after the Stop still folds, and an older client is sent only removed ids no item uses.
…op-keeps-steered-card
…op-keeps-steered-card
… a writable downgrade The Stop-event downgrade test ran in no CI lane: unit shards exclude the cross-version folder, and the cross-version lane runs a fixed file list that did not name it. It is now on that list. Its only case replayed the rows into a release's own fresh database, because that release cannot open the current host database. A second case opens the journal this build wrote with a main build that shares the database: it opens writable, keeps every row, appends, and this build then reopens it with the person's Stop still pausing the queue.
A Stop reaching a running agent wrote a Stop event on every press. Two presses before the first interrupt landed wrote two events, so a card queued between them counted as before the latest Stop and was held, though a card queued after a Stop should send normally. A Stop naming a turn that had already ended, as a phone sends late, also wrote an event for a turn it never stopped. It now writes one only when it withdrew a queued send, or stops something no event records yet: not a turn the journal no longer runs, and not the live turn a Stop still in force already names, unless a card was handed over into it since, which this Stop's interrupt sends back and must hold. The interrupt and the "already finished" note are unchanged. A Stop at a starting agent still always writes.
…r lifts a person's Stop
…2025/waiting-send-hold # Conflicts: # src/shared/native-chat-turn-membership.ts
…n every snapshot Every snapshot projects each item through the Stop-note read, and each new snapshot rebuilds the index of Stop notes by turn. Both parsed every item's key first; they now check the row's kind and turn scope (and, for the projection, its unconfirmed-stop failure) before the parse. Every Stop note is a status row, so what each finds is unchanged.
…2025/waiting-send-hold
… the stopped send's turn never opened
…nconfirmed one leaves the turn opening
…em; type the test's failure note
Review status: ready, base
|
…the provider opened before answering it
…send-hold # Conflicts: # src/shared/native-chat-turn-membership.ts # src/shared/native-chat-types.ts
…ch arguments main now requires
…ens stays after that turn, with its stop row; move the rows that wait behind the live turn into their own module
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review. 📝 WalkthroughWalkthroughThe change adds journal checks that hold queued sends while a handed-over send is opening a turn. Codex event handling records opened turns and settles certain final errors for turns that were not opened. Shared turn membership and transcript projection use opening-send and submission data to determine message placement. Tests cover provider behavior, Stop handling, delivery, turn membership, and renderer and mobile transcript rows. Priority: ➖ Normal Merge Risk: 🔵 Low · up to A Codex child that returns 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 2📝 Generate docstrings 💡
🛠️ Fix failing CI checks 💡
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 |
…send-hold # Conflicts: # src/main/native-chat/agent-session-wire/structured-agent-session-queued-pause-lift.test.ts # src/main/native-chat/agent-session-wire/structured-agent-session-queued-stop-row.test.ts # src/main/native-chat/agent-session-wire/structured-agent-session-stop-event-binding.test.ts
…send-hold # Conflicts: # src/main/native-chat/agent-session-wire/structured-agent-session-conversation-stop.test.ts
…real journal database, in the Node runtime project
…ld gets only the first message; a failed start still rejects both in its words
Takes main's notice card (#25835) as main has it; the chat's send errors reach it through controller.error. The outbox Stop-withdrawal module stays deleted: #25217 only exported its Retry test for the projection's awaitsRetry flag, and no in-memory send ever waits on a Retry. Main's opening-send test is ported to optimistic messages, minus its two waiting-on-Retry cases. Also: a launch text handed back by a Stop before publish (or a failed start) is guarded like the sender's hand-back, so a draft write that throws is reported and never skips the Stop; the Stop-before-publish cases for a notes launch, an already-sent launch and a throwing hand-back are tested; the legacy outbox comment no longer names a build number.
…ver opened (follow-up to #25217) (#26105) * fix(native-chat): a Stop the agent took settles the message whose turn never opened When Codex takes a person's Stop on a turn it never opened, no turn-ended event follows, so the message stayed pending: the chat read Working with Stop shown, and the next turn's clock counted from that message. The Stop's settle now handles that case from its own answer: when the provider names the turn it took and that turn has no record, the sends it was for are withdrawn by the same rule a Codex child's end after a Stop already uses. The send's own row then says it was stopped before the agent started, and Working, the clock and the opening-send hold follow from it being settled. Deletes the opening-send hold's special case for a taken Stop's note, which this makes dead, and moves the Stop note key back next to its only users. * test(native-chat): a Claude Stop before the echo settles the send through the CLI's end, and the next message goes out * fix(native-chat): an interrupted Codex turn that never started records nothing, and the withdrawal reads from the handover Codex can abort a turn before it starts: it answers the interrupt, then sends turn/completed for a turn that never sent turn/started. The translator wrote an empty interrupted turn for it, so the person saw that turn beside the message's own "Stopped before the agent started" row, and when the end was read before the interrupt's answer the Stop's settle found a record and withdrew nothing. Codex records a turn's prompt only once the turn starts, so an interrupted turn this child never started, with no item or prompt read, now gets no record. Failed ends keep theirs. The withdrawal now asks whether a turn opened since the send's handover row, the same point the opening-send hold reads, rather than since its acceptance: a turn record written in between is not the send's turn. * test(native-chat): say why the item-read case pins only that the send is not taken back
A follow-up to the Stop-event plan (fixes STA-9348). Base
main: #24864 and #24369 are onmain.ELI5
If you sent two messages close together, or both waited behind
/compact, the second one could show up inside the agent's reply to the first, above text the agent was still writing. It stayed there even after a Stop. The cause was not how the chat draws. The host passed the second message to the agent before the first message's turn had started, and recorded it as belonging to no turn, though the agent actually added it to that turn. Now the host waits until that turn has started, then passes the message in as part of it. The chat draws it where it really went.What Changed
The problem: the wrong turn was recorded at handover.
handOverSubmission,structured-agent-session-turns.ts).turn/startbut not sentturn/started, or Claude has not yet echoed the first message. The second message's row then says "no turn".codexRunningOrOpeningTurn). A real-host run of the shape below recordsanswers 2, steers 1.Before / after:
/compact; the first's turn is openingstructured-agent-session-chat-stop.ts:77-86), and it is never sentUser-facing change: a message sent while the turn ahead of it is still opening waits at the bottom of the chat, after that turn's live "Working for Ns" status and its "Working…" line, in the existing queued look. It then joins that turn. Desktop and phone draw it the same way; there is no new notice, and the composer is never blocked.
Drawing the wait. Live testing found the waiting message drawn as an ordinary bubble above the live "Working for Ns" header, on #24369 too. Two causes, both fixed in the shared drawing code:
openingTurnKey,native-chat-turn-membership.ts).nativeChatMessagesWaitingBehindLiveTurn), the rule that already draws a message held behind/compactor a Stop after the live activity. While Stopping, the rows a Stop holds and the rows behind the opening turn both wait. A send that only the user's Retry sends again is not held by the host, so it never waits: the projection marks it (awaitsRetry), and it stays where it is.src/shared/structured-agent-session-opening-send.ts). Nothing new is stored.structuredAgentTurnAnchors,native-chat-turn-membership.ts). Until Codex echoes that message, the turn record cannot name it, so the chat falls back to the first message handed over and not yet echoed ahead of the record./compact, or sent while Stopping, are both accepted before the first is handed over, so the second's row sits above the first's handover. The hold then makes the first send's turn record land before the second is handed over. The fallback counted the queued second message as handed over, so it took the turn. Fix: a message still queued, not yet handed over, is never that fallback.Mechanism.
structured-agent-session-opening-send.tsdecides whether a send ahead is still opening its turn. All of these must hold:pending, handed over by this child, at this fence;structuredAgentSessionNextHandover), right after feat(native-chat): the chat reads "Stopping…" from your Stop until the turn actually ends #24369's Stopping check. While a send is opening, the answer is "none", and the loop stops.unknownat once;pending. After a Stop that took, the next message is a new instruction, not one for that turn, so it goes out as its own turn. A Stop that was refused or not confirmed writes its note with the failure, and the turn may still open, so the next message keeps waiting for it. A Stop also withdraws every message still queued (structured-agent-session-chat-stop.ts:77-86), so a message held at the moment of the Stop is withdrawn with the queue.main's new "delivers a newly accepted message after Stop withdraws the prior send" test (Fix Codex chat creation after its own model listing fails #25754): before this rule, an accepted Stop on a send whose turn never opened held every later message forever, so the chat stopped answering. The Stop-note key check moved tosrc/shared/structured-agent-session-stop-note-key.tsso the host and both clients read the same rule (the host module re-exports it). The samemaintest file's "stalled catalog" case now hands its standalone Codex adapter the host's event sink, as the runtime does, so the host sees the turn open.errornaming the turn (willRetry: false), and noturn/completed. Anerrorlike that, naming a turn Codex never opened, is now read as that turn's failed end, so the send answered into it is refused in Codex's own words, exactly as aturn/completedreporting the failure would settle it (codex-structured-turn-end-settlement.ts,unopenedTurnFailure).turn/startanswer itself, so no send is bound to the turn theerrornames, and theerrorsettles nothing. The rule is not version-gated; it simply only finds a send to settle on older Codex.turn/started(codex-structured-dispatch-echo.ts,opened). Anerrorfor a turn that did open is left to that turn's ownturn/completed.turn/completed, and between an aborted turn and the next picked turn, so that report does not prove a picked turn will never open.unknownwhen the CLI goes idle.Known limits (no timer, by design):
turn/startand then sends nothing more (noturn/started, noerror, noturn/completed; a hung child) holds the next message until a Stop or the child's exit. The Stop withdraws the held message with the queue, and, because the turn may still open, ends the child, which settles the send ahead. The person is never blocked.error, which would leave its sendpendingand hold the next message until a Stop. Review could not show Orca reaching that shape, so it is listed here unverified.Existing tests changed, and why the old shape did not match the real provider. None of these weakens an assertion about what the test is for.
structured-agent-session-claude-unproven-stop-send.test.ts, 3 tests ("holds the message with its reason…", "retries once per new message…", "queues a follow-up as a draft by default…"):structured-agent-session-queued-repeat-press.test.ts("Send-now pressed twice…"),structured-agent-session-queued-pause-lift.test.ts("a card sent now before the Stop and taken anyway…"), andstructured-agent-session-queued-stop-row.test.ts(2 tests: "a card the Stop withdrew comes back once…" and "survives a host crash…"):openRigTurnFor, a new fixture module, because the rig fixture is at its line limit). Where the test ends the working send, it also ends that turn.structured-agent-session-codex-turn-end-settlement.test.ts("joins that turn once it opens, on a Codex that names a steered start falsely, so a Stop withdraws both"):structured-agent-session-send-restarts-failed-start.test.ts("restarts the child and admits the message against it before it has proven its start"):send-agent-turn-host.test.ts("has anowsend join the running turn, never the queue", from main's orchestration work):openRigTurnFor) before thenowsend. The assertions are unchanged.codex-turn-lifecycle-fake.ts: a turn's end now publishes the thread idle ahead ofturn/completed, as Codex does (captured in__fixtures__/codex-app-server-turn-endings.jsonl), so every Codex test runs the real order.pendingwith no turn forever, which no provider does. Each now settles that send the way the provider would (withdrawnByStoporopenRigTurnForin the new fixture module):structured-agent-session-steer-while-stopping.test.ts:structured-agent-session-stop-event-binding.test.ts:structured-agent-session-stop-event.test.ts, both "a second press after a card sent into the turn…" tests: the turn the working send started opens after the first, turnless Stop, and the card goes into it.Why
The common pattern: a message that joins a turn is never handed to the provider before that turn has started; it waits until the turn starts. An accepted steer is then drawn where the provider took it, inside the turn. This PR adopts that delivery rule.
Differences from the common pattern:
/compactor a Stop this way, and every client draws the queued message from the same journal.Alternatives considered:
unknownwould show "Message delivery is unconfirmed." on a slow but healthy start. Orca's rule is thatunknowncomes only from a process fact.Mixed versions
Linked Issue
Fixes STA-9348 (https://linear.app/stably/issue/STA-9348).
Visual Proof
Live QA on a separate Mac against background builds, driving a native Codex chat backed by a stand-in Codex that can hold its answer to a turn-start request (here for 10 s) and fake a
/compact. Desktop only. A Claude case was not run live; it's covered by tests.The phone draws the held message from the same shared rule, which is covered by tests; live phone QA of the hold is still to come.
This round (live, at
38279c36782, which carriesmain's #25051): a Stop before the turn opens. Same separate Mac and stand-in Codex; driven by an opencode agent over the browser debugging port. The later merges toa6885ae1a1bchanged none of this PR's files except one type file (a new field frommain) and one test.main: the stopped first message is never settled, so the chat keeps reading "Working…" with Stop shown, and the next turn's clock counts from the first message. That is the existing "is the agent working" rule, not this PR's hold; a follow-up is proposed.Earlier rounds:
A second message sent before the first message's turn has opened.
Before this PR, the second message was handed over at once and recorded outside the turn it then joined, so the turn split into two identical headers with the message between them. With this PR it waits until the turn opens, then joins it.
While it waits, the held message is drawn at the end of the chat, after the live "Working…" line. Before, it was drawn above that line.
Two messages queued behind
/compact. Both wait at the end while the compaction runs, and nothing reaches Codex until it ends. The first then starts its turn, and the second joins that turn once it opens. The turn's header stays on the first message throughout, checked every 100 ms around the moment the turn opens.Two messages typed while "Stopping…". Both wait at the end until the stopped turn ends. Then the first runs as its own turn and the second joins it. No "Message delivery is unconfirmed." appears.
A Stop pressed while a message is held takes that message back with the rest of the queue. It never reaches the agent, and its text returns to the composer.
Testing
At
6a6283adb46(basemain): CI 16 pass, 16 skipped, 0 fail, mergeable. Locally: the hold rule's new unit test, steer-while-stopping, conversation-stop, the Stop-note host tests, both opening-send hold tests and the subscribers test (9 files, 85 tests) pass. Removing the taken-Stop condition turns the replacement-send test red. tc:web, tc:node, phone tsc and the phone tests-typecheck ratchet pass. oxlint is clean on every changed file.I manually tested these changes locally
Automated tests added/updated, or explained why not below
New tests, through the real host and journal:
structured-agent-session-codex-opening-send-hold.test.ts, with the Codex stand-in:turn/started, then steered in, its row scoped to that turn and drawn in it as the turn streams on;turn/startanswer releases the next message at once;error) releases the hold, the send ahead refused in Codex's words;turn/completed: a steer taken back by a Stop, and a turn's own send stopped before its echo, settle only as withdrawn, never as doubt first; a turn that completes with its send echoed raises no doubt.NativeChatMessageList.opening-send.test.tsx, the desktop frame while the turn ahead opens:/compact, or sent while Stopping): still queued at the turn record, the first message echoed while it is still queued, handed over, the steer echoed, then the first message echoed. In every frame the second message is drawn under the first message's live status and above "Working…", and the live status stays on the first message.structured-agent-session-codex-opening-send-hold.test.tsalso runs the steer-echoed-first order through the real host: Codex echoes the steer before the first message, and the client still draws both messages in the first message's turn, with that turn live.native-chat-turn-membership.test.ts: a running turn stays on the message that opened it when a steer into it is echoed first, when a message is still queued above it (before and after the opener's echo), and, for a host that hands over two messages before the turn opens, when the opener is echoed and the later one is not.use-mobile-native-chat-turn-disclosure-opening-send.test.tsx, on the phone. The phone keeps no outbox. Its rows are the ones the host recorded, plus its own echo of a send the host accepted, shown until that send's row arrives. This file covers those: a queued message waits after the live status; the phone's echo of a send waits too, Stopping or not, and beside a queued B the Stop holds; a Stop withdraws a queued B; and both turn-open orders from their recorded step on. The list is built the way the phone's view builds it: the shared projection, which puts a queued message after the delivered ones, the phone's fold, which keeps that order, and its echoes.structured-agent-session-claude-opening-send-hold.test.ts, with the Claude fake fed the CLI's captured early-steer order:Each rule was checked by breaking it and watching its tests fail, each run over the same 1,501 test files (every delivery, queue, Stop, settlement, Codex and runtime test, including the new ones):
errornaming an unopened turn not read as its end: 1;errorread as the end even for a turn Codex opened: 1 (an existing test, "is accepted when Codex records it after the error that fails its turn").turn/completed" tests go red (2) against this PR's previous idle-based release, which this round replaced.Run locally:
native-chat-turn-membership.ts, resolved transitively from imports: 1,130 desktop files (12,210 tests), the 15-file cross-version and e2e unit set run serially (85 tests), and 47 mobile files (2,078 tests). All pass.native-chat-types.ts, which nearly every test imports), plus every delivery, queue, Stop, settlement, Codex, runtime and drawing test. 70,350 tests pass. Five files fail identically on feat(native-chat): the chat reads "Stopping…" from your Stop until the turn actually ends #24369's head on this machine and are unrelated: two browser-manager files, a relay test missing thepgpackage locally, and two hosted-review integration tests that time out under load and pass on a re-run.tc:node,tc:web,tc:cli, mobiletscand the mobile tests typecheck ratchet pass.AI Disclosure
Review
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
use-mobile-native-chat-turn-disclosure.tspasses the submissions). Its own test covers the frames the phone can show: recorded rows, and its own echo of an accepted send.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)