Skip to content

fix(native-chat): draw a waiting send after the turn ahead of it - #25203

Closed
brennanb2025 wants to merge 1 commit into
mainfrom
brennanb2025/waiting-send-after-turn
Closed

brennanb2025 wants to merge 1 commit into
mainfrom
brennanb2025/waiting-send-after-turn

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​500 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​500
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​122 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​120

ELI5

If you send two messages while the agent is busy, both wait in line. When the agent picks them up, the second one could show up in the middle of the agent's reply to the first, above text the agent was still writing. Now a message that is waiting always shows after the reply it is waiting behind, and moves down as that reply grows.

What Changed

The problem.

  • A message you send while a turn runs (for example during /compact) is queued. When the turn ends, Orca hands the queued messages to Codex one after another.
  • Codex can take the second message before it has opened the turn for the first. The first turn's rows (its reply, its tool calls) are then written after the second message in the conversation's history.
  • The chat drew each message where it was handed over, so the second message sat between the first message and the reply to it. As the reply streamed, the waiting message stayed wedged in the middle of it.
  • If a Stop then left that second message unconfirmed, it stayed in the wrong place for good, between the first message and its reply, above the Stop's "Cancellation requested." row.

Before / after (two messages queued behind /compact):

Situation Before After
While the reply to the first message streams (a live, in-flight change) first message → second message → reply to the first, still growing first message → reply to the first, still growing → second message, which moves down as the reply grows
A Stop leaves the second message unconfirmed first message → second message → reply to the first → "Cancellation requested." first message → reply to the first → second message → "Cancellation requested."
A third message, sent while the first one's turn runs, joins that turn (a steer) first message → second message → reply → third message first message → reply → third message (where it joined the turn) → second message
The second message's own turn opens after the first one ends unchanged unchanged

User-facing change, called out: this moves live, in-flight messages, not only ones a Stop left behind. A message waiting for the turn ahead of it now draws below that turn's latest row and moves down while that turn streams, instead of staying above the reply.

Mechanism.

  • The shared message projection (src/shared/structured-agent-session-message-projection.ts, used by desktop and phone) now draws a handed-over message that belongs to no turn past the end of every turn whose opener the journal wrote before that message's own row.

  • The rule is in src/shared/native-chat-waiting-send-placement.ts. It compares journal positions only, never clocks: the message's own row is already its handover row, so the host publishes nothing new.

  • A message steered into a running turn belongs to that turn, so it stays where it joined. A turn the message itself opened is not one it waits on.

  • A queued message the host has not handed over yet is unchanged. nativeChatMessagesWaitingBehindLiveTurn still draws it after a running command, and this rule never touches it.

  • The cost is one pass over the loaded rows, only when the chat holds a handed-over message outside any turn. Each such message is then placed with a binary search. Measured on the shared projection (milliseconds per update, median of 9 interleaved rounds):

    Rows loaded Handed-over messages Before After
    1,200 0 0.08 0.10
    1,200 20 0.11 0.22
    6,000 20 0.40 1.24
    12,000 100 0.92 2.66

    A chat with no handed-over message pays nothing extra, and the cost grows with the rows loaded, not with rows times messages. The before and after drew identically in every benchmark case. Those cases have no message waiting behind a turn.

Why

Linked Issue

Closes STA-9348 (https://linear.app/stably/issue/STA-9348).

Visual Proof

To be added from a live QA run: before and after of two messages queued behind /compact, while the first reply streams.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

New tests:

  • src/shared/structured-agent-session-message-projection-waiting-send.test.ts, built from the journals the shipped host wrote in the review runs:
    • the second message draws after the first one's streaming reply;
    • it stays after the reply when a Stop leaves it unconfirmed, with "Cancellation requested." after it;
    • a later message steered into the running turn stays where it joined, with the turn's later output below it, and the waiting message after both;
    • a message whose own turn opened after the turn before it ended stays at its own row.
  • src/main/runtime/structured-agent-session-codex-waiting-send-placement.test.ts, end to end through the real host, journal and Codex adapter with the Codex stand-in, drawn by the client's own projection:
    • two messages queued behind /compact, both handed over before the first turn opens: the second draws after "working on the first";
    • a third message steered into that turn: the waiting message draws after it.

Each rule was checked by breaking it and watching its tests fail:

  • the rule off: 3 of the 4 unit tests and both end-to-end tests;
  • a message steered into a turn moved like any other: 1;
  • a message counting a turn it opened itself as one it waits on: all 6.

Run locally:

  • 406 test files that draw or project the conversation (every native-chat renderer test, every shared transcript, turn and projection test, every structured-session runtime test): all pass (4,547 tests).
  • The full mobile suite: all pass (9,934 tests).
  • Cross-version wire tests, run serially: 17 files, 105 tests, all pass.
  • tc:node, tc:web, mobile tsc and the mobile tests typecheck ratchet 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

  • Mixed versions: client-only. No RPC, stream frame or stored record changes. An older client keeps drawing the message at its handover row. A message whose row states no turn scope, or that has no handover time, is left where it was.
  • SSH/remote: the client draws from the journal the execution host already sends. Nothing about where work runs changes.
  • Mobile: the phone uses the same shared projection, so it gets the same order.
  • Claude: by the rule, a Claude follow-up handed into a running turn is scoped to that turn and stays where it joined, and one handed over once Claude is idle has no turn ahead of it still writing, so it does not move. The end-to-end tests drive Codex only; Claude is covered by the existing renderer and runtime suites above, which all pass.
  • 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)

Codex can be handed a second send before the first one's turn opens. That turn's rows are then written after the second send's handover row, so the second send was drawn between the first message and its reply, and stayed there if a Stop left it in doubt. A handed-over send outside any turn is now drawn past the end of every turn whose opener the journal wrote before it, in journal order. A send steered into a running turn stays where it joined.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Closing in favour of #25217.

This PR fixed the symptom when drawing: it moved a waiting message below the previous reply. Review showed the real cause is earlier. The host recorded where a message belongs at the moment it handed it over, before the agent decided whether it started a new turn or joined the running one. So a message that actually joined the turn was drawn as if it hadn't. The drawing rule couldn't tell those cases apart, and it misplaced a Claude follow-up that had been folded into the running turn.

#25217 fixes it at delivery instead. The next queued message waits until the turn ahead has opened or settled, so it's recorded, and drawn, in the right place.

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