Skip to content

fix(native-chat): hold a queued message until the turn ahead opens (follow-up to the Stop-event plan, fixes STA-9348) - #25217

Merged
brennanb2025 merged 243 commits into
mainfrom
brennanb2025/waiting-send-hold
Oct 7, 2026
Merged

brennanb2025 merged 243 commits into
mainfrom
brennanb2025/waiting-send-hold

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

A follow-up to the Stop-event plan (fixes STA-9348). Base main: #24864 and #24369 are on main.

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.

  • Orca queues every send and passes queued messages to the agent one after another (the "handover").
  • The handover writes the message's row with the turn running at that moment. If none is running, the row belongs to no turn (handOverSubmission, structured-agent-session-turns.ts).
  • But the first message's turn is often not open yet: Codex has answered turn/start but not sent turn/started, or Claude has not yet echoed the first message. The second message's row then says "no turn".
  • The agent does not treat it that way:
    • Codex waits for the first turn to open, then sends the second message in as a steer, into that same turn (codexRunningOrOpeningTurn). A real-host run of the shape below records answers 2, steers 1.
    • The Claude CLI folds the second message into the cycle that is already running.
  • So the journal recorded a turn member as a message of its own, written before the turn record. The chat drew it between the first message and its reply, as its own exchange, above the reply that actually answered it. The placement came from the journal, so it stayed wrong after a reload, on the phone, and after a Stop.

Before / after:

Situation Before After
Two messages queued behind /compact; the first's turn is opening "first", "second" (as its own exchange), then the reply to the first "second" waits at the bottom of the chat as a queued message, then joins the first's turn as soon as it opens, drawn inside that turn
A Claude follow-up sent before Claude echoed the first message the follow-up drawn above the reply that answered it, as a message the agent never answered held until the echo opens the turn, then folded into it and drawn inside it, above the reply
A Stop pressed while the second message waits the second message had already been handed over, and could end up "unconfirmed" it is still queued, so the Stop withdraws it with the rest of the queue (structured-agent-session-chat-stop.ts:77-86), and it is never sent
A message sent while a turn is already running a steer into that turn unchanged

User-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:

  • The live turn was taken to be the newest user message, which was the waiting one, so the live status was drawn under it. While a send ahead is opening, its turn is now the live one (openingTurnKey, native-chat-turn-membership.ts).
  • A queued message keeps the place of the row that accepted it, which is above the handover that moved the send ahead; a message this client sent that the host has not recorded yet has no place. While a send ahead is opening, both now wait behind the live turn (nativeChatMessagesWaitingBehindLiveTurn), the rule that already draws a message held behind /compact or 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.
  • Both read the same journal fact as the host's hold, from one shared function (src/shared/structured-agent-session-opening-send.ts). Nothing new is stored.
  • At the moment the turn opens, the waiting message could jump above the live status, which restarted at "Working for 0s", then go back under it. Live testing caught one way; review found a second. Both come from how the chat picks the message that opened a turn (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.
    • A message still queued above the first send. Two messages queued behind /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.
    • A steer echoed first. The held message is steered in a few milliseconds after the turn opens, and Codex can echo that steer before the message that opened the turn. Codex gives every message in a turn the same item key, and the chat took the first message to carry that key as the opener, which was the steer. Fix: while a message handed over ahead of the record is still unechoed, a message steered into that turn does not take the turn from it.
    • Both fixes read what each row already records (whether it was handed over, its turn, and whether it was echoed); nothing new is stored.
    • The steer rule applies only when the turn is matched through Codex's shared key. A history restored from Codex names each turn's opening message directly, and a restored opening message is written after its turn record and scoped into it, the same shape as a steer. A first version that ignored this broke grouping of restored histories; the restore grouping test caught it.
    • Both frames could happen before this PR when the host's delivery stalled. The hold makes them common: every held message is handed over, and steered in, right after the turn record.
    • Considered and not used: also drawing every queued message after a running turn's live activity. The turn-open frames already draw the message where it lands. That rule would also make an ordinary steer jump: below "Working…" while it is queued, then back above it once handed over.

Mechanism.

  • structured-agent-session-opening-send.ts decides whether a send ahead is still opening its turn. All of these must hold:
    • the send is pending, handed over by this child, at this fence;
    • its handover row belongs to no turn;
    • since that handover, the journal has written no turn record and no note from a Stop that took (see below).
  • The delivery loop asks it for the next message to hand over (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.
  • Nothing is stored and there is no timer. Every way the hold ends is already a journal commit, and any commit wakes the loop:
    • the turn record;
    • the echo;
    • a refusal;
    • a lost turn/start answer, which is written as unknown at once;
    • the child ending;
    • a Stop that took. Its note ("Cancellation requested.", no failure) ends the hold even when the stopped send's turn never opens and that send stays 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.
    • Found by 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 to src/shared/structured-agent-session-stop-note-key.ts so the host and both clients read the same rule (the host module re-exports it). The same main test 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.
  • A Codex turn that fails before it opens. Codex before 0.148 reports such a turn's failure with only a final error naming the turn (willRetry: false), and no turn/completed. An error like 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 a turn/completed reporting the failure would settle it (codex-structured-turn-end-settlement.ts, unopenedTurnFailure).
    • On 0.148 and newer the same failure is refused in the turn/start answer itself, so no send is bound to the turn the error names, and the error settles nothing. The rule is not version-gated; it simply only finds a send to settle on older Codex.
    • Which turns Codex opened is recorded from turn/started (codex-structured-dispatch-echo.ts, opened). An error for a turn that did open is left to that turn's own turn/completed.
    • It is a process fact naming that turn, not elapsed time, so a slow but healthy turn start is never shown as unconfirmed.
    • Not used: releasing at Codex's "thread not running" report. Codex publishes the thread idle ahead of turn/completed, and between an aborted turn and the next picked turn, so that report does not prove a picked turn will never open.
  • Claude needs nothing new: its adapter already settles an unechoed send that the CLI started as unknown when the CLI goes idle.

Known limits (no timer, by design):

  • A Codex child that answers turn/start and then sends nothing more (no turn/started, no error, no turn/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.
  • Codex 0.147 can drop a refused steer with no error, which would leave its send pending and 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…"):
    • Change: the resumed child now echoes "Carry on.", which opens its turn, before "And this." is expected to go out.
    • Why: the old fake never echoed, which a live Claude CLI always does. Without an echo, "And this." would be a fold handed over before the turn exists, which is this bug.
  • 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…"), and structured-agent-session-queued-stop-row.test.ts (2 tests: "a card the Stop withdrew comes back once…" and "survives a host crash…"):
    • Change: these send a card "into the turn", so they now open that turn first (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.
    • Why: the rig's "working" send was a pending send with no turn record. A real provider opens a turn for it, and a Send-now into a turn that has not opened is exactly what now waits.
  • 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"):
    • Change: it asserted that the adapter waited for the opening turn. It now asserts the follow-up is held, with no wait, and then steered once the turn opens. The test's own claim, both withdrawn by the Stop, is unchanged and still passes.
    • Why: the follow-up no longer reaches the adapter before the turn opens.
  • structured-agent-session-send-restarts-failed-start.test.ts ("restarts the child and admits the message against it before it has proven its start"):
    • Change: the restarted child now echoes the first message before the second is sent.
    • Why: its child admitted the first message and never answered it, which no live provider does, so the second was held behind a turn still opening. The test still checks that the second send restarts nothing.
  • send-agent-turn-host.test.ts ("has a now send join the running turn, never the queue", from main's orchestration work):
    • Change: the setup now opens the working send's turn (openRigTurnFor) before the now send. The assertions are unchanged.
    • Why: the rig never opened the working send's turn, so the "running turn" the test names did not exist; a provider opens it.
  • codex-turn-lifecycle-fake.ts: a turn's end now publishes the thread idle ahead of turn/completed, as Codex does (captured in __fixtures__/codex-app-server-turn-endings.jsonl), so every Codex test runs the real order.
  • Seven Stop tests whose rig left the stopped send pending with no turn forever, which no provider does. Each now settles that send the way the provider would (withdrawnByStop or openRigTurnFor in the new fixture module):
    • structured-agent-session-steer-while-stopping.test.ts:
      • "hands over a send made after a Stop that stopped nothing…": it asserted the bug's own order (the later send handed over before the first send's turn opened). It now asserts the later send waits for that turn, then joins it.
      • "hands a held send over when the Stop settles with no row after it": the working send's turn is open, so only the Stop's settle holds the later send, which is what the test is about.
    • structured-agent-session-stop-event-binding.test.ts:
      • "reopens no earlier Stop: a late Stop naming a turn already over…" and "…a press whose event row failed…": after the turnless Stop, the stopped send, whose turn never opened, is withdrawn as the provider's Stop settles it.
      • "writes the host's event when a send after the Stop is unanswered beside the stopped one": the stopped send's turn opens after the Stop and ends interrupted, still unanswered.
    • 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.
    • None of these needed a Stop to release the hold once the send ahead was modelled as a provider settles it. A Stop does not release the hold, as in the common pattern.

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:

Difference Label
A message queued while the turn ahead opens joins that turn as a steer once it has opened; it is not held until that turn ends. Intended. Orca already sends a message typed during a running turn into that turn. This only closes the window where that turn is still opening. Making queued messages wait for the turn to end would be a separate product change.
A message the host holds queued is drawn at the end of the chat, after the live turn, in the queued look. In the common pattern a pending or not-yet-recorded send is drawn after the conversation's rows. Intended. Orca already draws a message held behind /compact or a Stop this way, and every client draws the queued message from the same journal.
The wait is re-derived from the journal on every delivery step, not stored as a waiting record. Intended. Orca's delivery loop already decides everything from the journal on each step. A stored wait would be a second copy of a fact the journal already holds, with its own way to go stale.

Alternatives considered:

  • Fix the drawing in the client (this PR's earlier approach, fix(native-chat): draw a waiting send after the turn ahead of it #25203). Rejected: the client cannot tell a message that opens its own turn from one the agent steered or folded into an earlier turn. Moving it below the turn misplaces every steer, on Codex and on Claude.
  • Release the wait after a fixed time. Rejected: an elapsed-time unknown would show "Message delivery is unconfirmed." on a slow but healthy start. Orca's rule is that unknown comes only from a process fact.

Mixed versions

  • No wire change: no new field, RPC or stored record. What the host publishes changes: a message stays queued a little longer, and its handover row now names the opened turn.
  • An older client on this host gets the turn fix: the held message joins the turn and is drawn inside it. During the wait it still draws the held message above the live status, as it does today. This is Temporary: it ends as clients update.
  • A newer client on an older host: while its message is not yet recorded (the older host's lane is busy with the first send), it is drawn after the live status, as on a new host. Once the older host hands it over, back to back, before the first send's turn opens, it jumps above the live status, the old placement. This is Temporary: it ends as hosts update, and no client code needs removing.
  • SSH and remote: the hold runs on the execution host that owns delivery. Clients only read the journal.

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 carries main'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 to a6885ae1a1b changed none of this PR's files except one type file (a new field from main) and one test.

  1. A waiting message the Stop takes back. The stand-in delays the first turn's start by 3 s. A second message sent meanwhile waits below the live "Working…" line. The Stop then takes it back: it never reaches Codex, stays on screen with one "Stopped before the agent started" row, and as a settled row now sits just above "Stopping…", never above the first turn's "Working for…" header.
Waiting below the live line Taken back: above "Stopping…"
second message waiting below Working taken back, one stop row, above Stopping
  1. A Stop Codex accepts while the turn never opens (synthetic: the stand-in answers the Stop and then says nothing, which real Codex does not do). The next message goes out as its own turn and is answered, where before this round's fix it waited forever. Not fixed here, and the same on 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.
After the accepted Stop The next message, sent and answered as its own turn
Cancellation requested, still Working second message as its own turn
  1. A Stop Codex refuses because the turn has not started. The next message is held: it waits below "Stopping…" and does not reach Codex before the turn opens. Orca then sends the Stop again once the turn has opened, Codex takes it, the first turn ends "Interrupted", and the held message runs as its own turn after it.
Held while the refused Stop's turn opens After: interrupted turn, then the held message's own turn
held below Stopping interrupted turn then second message

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.

Before: two headers, message between them After: one turn, message inside it
before after

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.

Before: waiting message above "Working…" After: waiting message at the end
before, waiting after, waiting

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.

During the compaction Compaction done, first message's turn starting Just after the turn opens End
compacting compact done turn open end

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.

While Stopping Stopped turn ended Just after the new turn opens End
stopping ended turn open end

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 (base main): 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:
    • the second message is held until turn/started, then steered in, its row scoped to that turn and drawn in it as the turn streams on;
    • three messages: both followers held, then both steered in, in order;
    • a Stop while one is held: it is withdrawn with the queue and never sent;
    • a lost turn/start answer releases the next message at once;
    • a message into a running turn, or behind an unanswered steer, is never held;
    • a Codex turn failed before it opened (only an error) releases the hold, the send ahead refused in Codex's words;
    • with timers advanced three times past Codex's own turn-open wait, the send ahead stays pending (never "unconfirmed") and the next stays held until the turn opens;
    • with Codex reporting the thread idle ahead of 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:
    • a second message the host has not recorded yet is drawn after the live "Working for Ns" status and the "Working…" line;
    • so is one the host holds queued, whose accepting row sits above the first send's handover;
    • a Stop during the wait: B stays at the tail while Stopping, and is gone once withdrawn, never drawn above the live status.
    • the Q2 frame, where the Stop is pressed while B is not recorded yet and a message typed while Stopping joins it;
    • a send waiting on Retry (unconfirmed, or outlived by a Stop) is not moved.
    • the moment the turn opens, one frame per commit, in two orders. In the first, the second message is recorded after the turn record: not recorded yet, recorded, handed over as a steer, the steer echoed before the first message, then the first message echoed. In the second, it was accepted above the first send's handover (queued behind /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.ts also 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:
    • the follow-up is not written to the CLI until the first echo opens the turn, then is folded in, scoped to that turn and drawn inside it above the reply, with one turn in all;
    • the CLI going idle on a started, unechoed send doubts it, which releases the follow-up.

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):

  • the hold off: 9;
  • a lost answer, or a send the CLI's idle doubted, treated as still opening: 3;
  • a steer counted as opening: 2;
  • no release on the turn record: 14;
  • an error naming an unopened turn not read as its end: 1;
  • that error read 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").
  • The two "thread idle ahead of turn/completed" tests go red (2) against this PR's previous idle-based release, which this round replaced.
  • Drawing, measured on this round's files (desktop 8 tests, phone 5, plus the shared rule, the real-host Codex file and the restore grouping file):
    • the live turn not kept on the opening send: 4 desktop and 2 phone;
    • the held message not waiting behind the opening turn: 4 desktop and 2 phone;
    • the opening case reading queued messages only, not ones the host has not recorded: 3 desktop and 1 phone (the phone's own echo);
    • a send waiting on Retry not excluded: 2 desktop (the phone's echo is never a send waiting on Retry);
    • the old early return when a Stop already holds a row: 1 desktop and 1 phone (the phone's echo beside a queued B while Stopping);
    • a queued message allowed to be the turn's fallback opener: 3 (the queued-above order on desktop and phone, and its shared-rule test);
    • a steer allowed to be its turn's opener again: 6 (both turn-open orders on desktop and phone, the real host, and the shared rule);
    • the steer rule widened to let any unechoed message ahead of the record beat the echoed opener: 1 (the shared-rule test for a host that hands over two messages before the turn opens).
    • No other test turned red in any of these.

Run locally:

  • The turn-open rounds: every test importing 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.
  • The earlier round, unchanged since:
  • 7,085 test files: every test importing a touched module, resolved transitively from imports rather than file names (this round touches 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 the pg package locally, and two hosted-review integration tests that time out under load and pass on a re-run.
  • The full mobile suite: all pass except three that fail identically on feat(native-chat): the chat reads "Stopping…" from your Stop until the turn actually ends #24369's head; they check locally generated bundle files and are unrelated.
  • tc:node, tc:web, tc:cli, mobile tsc and the mobile tests typecheck ratchet pass.
  • Cross-version wire suite, run serially: 15 files, 91 tests, all pass.
  • oxlint, anti-slop and the changed-code quality gate pass.

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Mobile: the phone draws through the same shared rules (use-mobile-native-chat-turn-disclosure.ts passes the submissions). Its own test covers the frames the phone can show: recorded rows, and its own echo of an accepted send.
  • Folder workspaces: unaffected; nothing here depends on git.
  • Cross-platform: no platform-dependent code.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)
Files Added Deleted Net
Test 19 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1831 $\color{#cf222e}{\Huge{\mathbf{−}}}$​23 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1808
Prod 21 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​460 $\color{#cf222e}{\Huge{\mathbf{−}}}$​89 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​371

…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.
…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.
…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.
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.
…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.
… 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.
… 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.
…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.
@brennanb2025
brennanb2025 changed the base branch from brennanb2025/stopping-state-on-b to main October 6, 2026 19:18
@brennanb2025

brennanb2025 commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Review status: ready, base main, head d26397a

The problem. If you sent two messages close together, or both waited behind /compact, the second could show up inside the agent's reply to the first, above text the agent was still writing, and stay there even after a Stop. The host passed the second message to the agent before the first message's turn had started, so it was recorded as belonging to no turn, though the agent actually added it to that turn.

What changes for you.

  • A message sent while the turn ahead of it is still opening waits at the bottom of the chat, after that turn's live status. It joins that turn once the turn has opened, so it is drawn in the right place.
  • If you Stop that turn before it opens, your next message is not held. It goes out as its own turn after the stop. If the Stop was refused or couldn't be confirmed, the turn may still open, so the next message keeps waiting for it.

New in this round. main's new tests (#25754) caught a real bug in this PR's hold. An accepted Stop on a message whose turn never opened left that message pending forever, so every later message was held behind it and the chat stopped answering.

  • Fixed: the hold now also ends at the note of a Stop that took. That note says "Cancellation requested." with no failure.
  • The fix is derived from the journal, with no new state or timer.
  • Removing it turns the test red again.
  • A review asked whether that note could be written before a turn start the agent had already sent. It can't: while a chat can take a Stop, each agent event goes into the chat's history as soon as it is read, in order. A new test pins it (the note lands after the turn it stopped).

Why the rule is worth having, stated plainly. No agent Orca ships is known to reach "Stop accepted, turn never opened" today. As far as we have seen, Codex either opens the turn and ends it as interrupted, or refuses the Stop. The rule is a defense for an agent that accepts a Stop and then goes silent. Without it, that one state holds every later message forever and the chat stops answering; with it, the next message goes out. main's own "stalled catalog" test (#25754) reaches that state, so the rule is what keeps that test passing on this branch. It is not optional.

Merging main (#25051, #25888 and the typecheck fixes). #25051 now keeps a message a Stop takes back on screen, with one "Stopped before the agent started" row. This PR's two tests that said such a message disappears (desktop and phone) now pin that it stays after the live turn, never above it, with its row after it. The merged turn-membership file went over its line limit, so the rule for which messages wait behind the live turn moved to its own file (native-chat-messages-waiting-behind-live-turn.ts), unchanged. #25051's own tests pass at this head.

Merging main again (#25152, #26006, #25986, #26050), head d26397a.

  • fix(claude): start a Claude chat with its saved options and send the first message at once #25152 now hands a message to an agent that is still starting, instead of waiting for the start to finish. With this PR, a still-starting agent gets the first message at once, as fix(claude): start a Claude chat with its saved options and send the first message at once #25152 intends; a second message waits until the first message's turn opens, which is the rule that keeps it out of the wrong turn.
  • If that start fails, the outcome is the same as on main: one start-failure row, no second start attempt, and both messages rejected with the start's own words. The held one is rejected one step later.
  • Two of fix(claude): start a Claude chat with its saved options and send the first message at once #25152's tests expected both messages written to the starting agent at once ("a start that fails after it was handed messages" and "a published child that dies while it proves its start"). They now expect one write and wait for the held message's rejection; every original assertion about the row and both rejections is kept.
  • One test helper main removed (adapter.awaitStarted) is replaced with main's claudeStartupSettled, and this PR's two hold tests that open a real journal database are added to the SQLite test list main's new check requires.
  • CI at d26397a: every check passes, test shards included. One Windows job first failed on profile-state-writer-stall.electron.test.ts ("Profile state writer command timed out"), a file this PR does not touch; the re-run passed.
  • The live QA above ran at 38279c36782; these merges did not change this PR's own rules.

The stack: #24864, #24369 and #25051 are on main. This PR is based on main.

Verified.

  • CI at a6885ae: 16 pass, 16 skipped, 0 fail, mergeable, with the test shards running (main's typecheck fix fix(test): restore main typecheck — pass resolveLaunchArgs in the Codex stopped-send-order test #25977 is merged in, so the typecheck gate passes).
  • Tests at a6885ae: all 15 desktop test files this PR changes (190 tests) and its 2 phone files (14 tests) pass. tc:node, tc:web, phone tsc and the phone tests-typecheck ratchet pass, and oxlint is clean on every changed file.
  • Live desktop QA of the new Stop rule (round 18b, at 38279c36782; screenshots in the PR body, under Visual Proof). Separate Mac, stand-in Codex, driven by an opencode agent (opencode-go/deepseek-v4.1-flash). Codex was not used as the driver: its login lives in the real ~/.codex and a run writes there, and an isolated home would need copied credentials. Since then only main merges; of this PR's files they changed one type file (a new field from main) and one test.
    • A Stop Codex accepts while the turn never opens (synthetic, see below): the next message went out as its own turn and was answered within 4 s.
    • A Stop Codex refuses before the turn opens: the next message was held and did not reach Codex before the turn opened. Orca then re-sent the Stop, Codex took it, and the held message ran as its own turn after the interrupted one.
    • A waiting message the Stop takes back: it never reached Codex, and stayed on screen with one stop row, never above the live turn.
    • In earlier rounds: two messages sent close together, and messages queued behind /compact or sent while Stopping.

Not verified.

  • The phone, live. The phone draws the hold from the same shared rule, covered by tests.
  • A real Claude agent. Covered by tests.

Found live, not fixed here (by the code, the same on main; not run live on main): after a Stop Codex accepts on a turn that never opens, the stopped message is never settled, so the chat keeps reading "Working…" with Stop shown, and the next turn's clock counts from that message. The next message does go out and is answered (this PR's rule). The cause is the "is the agent working" rule, which still counts that send as in flight; making it read the same Stop note this PR's hold reads would fix it. Proposed as a follow-up, since no shipped agent reaches this state.

Needs a reviewer's eye:

  • When a Stop takes back a message that was waiting for the turn ahead to open, the message moves up one line: from below the "Stopping…" line, where waiting messages sit, to just above it, where settled rows sit (screenshots under Visual Proof, case 1).
  • To see the turn open, main's "stalled catalog" test now hands its standalone Codex adapter the host's event sink, as the app does. That is a change to Fix Codex chat creation after its own model listing fails #25754's test file.

@brennanb2025
brennanb2025 marked this pull request as ready for review October 7, 2026 00:31
@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d43c13d6-0380-46c0-af31-93d87ea7792d
📥 Commits

Reviewing files that changed from the base of the PR and between 50e5d90 and d26397a.

📒 Files selected for processing (2)
  • src/main/native-chat/agent-session-wire/structured-agent-session-accept-then-deliver.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-provider-child-record.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.


📝 Walkthrough

Walkthrough

The 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 d2639

A Codex child that returns turn/start but emits no later event can leave the next message queued until Stop or child exit. This is a bounded edge case with a recovery path, so the change appears mergeable with owner awareness.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 53.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 75 functions across 40 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the native-chat fix: queued messages wait until the preceding turn opens. The follow-up and issue reference add detail, but the title remains specific and relevant.
Description check ✅ Passed The description covers the required ELI5, change, rationale, linked issue, visual proof, testing, compatibility notes, and checklist. It gives detailed behavior and validation results. Some checklist …
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…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
@brennanb2025
brennanb2025 merged commit d0b0f13 into main Oct 7, 2026
53 of 55 checks passed
brennanb2025 added a commit that referenced this pull request Oct 7, 2026
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.
brennanb2025 added a commit that referenced this pull request Oct 7, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant