Repository navigation
fix(claude): withdraw a follow-up queued behind a stopped turn instead of dropping it silently - #23553
Conversation
…d of dropping it silently Orca's SessionStart hook proves most Claude starts before the turn's system/init, the only frame that advertises interrupt_cancel_queued_v1. Capabilities were read once from the start proof, so they stayed empty: Stop never asked Claude to cancel its queue, and the one-at-a-time fallback withdrew the follow-up without settling it. The send stayed pending and the chat read Working until the child exited. Capabilities are now one derived value, taken from whichever report names any and never cleared by one that names none. The fallback settles each send the CLI confirms it withdrew.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Capabilities survive a SessionStart-proved start —
readClaudeCapabilitiesnow foldsobservedplus every report, keeping the first non-empty capability list and never clearing. Startup and each turn'ssystem/initboth apply it, sointerrupt_cancel_queued_v1is learned regardless of which frame proved the start. - One-at-a-time withdrawal now settles —
cancelAsyncMessagereturnsPromise<boolean>(cancelled === true,falsewhen the SDK method is absent), andcancelClaudeTurn's receipt-sweep path settles exactly the uuids the CLI confirms it withdrew. - Tests — new adapter and host end-to-end tests for the A-running/B-queued/Stop sequence, plus a control-actions case proving unconfirmed withdrawals are left untouched and a real-CLI SessionStart-hook case.
Verified the load-bearing external contract in the bundled SDK: Query.cancelAsyncMessage returns (...).response.cancelled and interrupt returns { still_queued, cancelled? }, so the === true check and still_queued sweep work against 2.1.280. Both callers, the readonly string[] type, and every test double are updated consistently; pnpm vitest on the new adapter, control-actions, and host wire tests passes locally.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review. 📝 WalkthroughWalkthroughClaude capability handling now scans reports and updates live session capabilities from accepted init frames. Cancellation calls return a boolean confirmation, and the fallback cancellation sweep settles dispatch waiters only for confirmed cancellations. Tests cover capability timing and queued-stop behavior in structured sessions, the native session wire, and an authenticated real CLI session. Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to Queued messages are recorded as withdrawn only when cancellation is confirmed, with no identified issue requiring a fix before merge. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to Stopping a turn now records a queued follow-up as withdrawn only when cancellation is confirmed. The stop request still follows the existing session controls. No introduced security issue was established, though provider behavior and security coverage remain incompletely verified. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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: baf14865-cee1-4619-a750-dc3ce0f9f522
📒 Files selected for processing (13)
src/main/claude/claude-agent-sdk-control-requests.tssrc/main/claude/claude-structured-control-actions.test.tssrc/main/claude/claude-structured-control-actions.tssrc/main/claude/claude-structured-init-proof.tssrc/main/claude/claude-structured-queued-stop.test.tssrc/main/claude/claude-structured-real-cli.test.tssrc/main/claude/claude-structured-session-acquisition-processless.test.tssrc/main/claude/claude-structured-session-acquisition.tssrc/main/claude/claude-structured-session-startup.tssrc/main/claude/claude-structured-session-test-support.tssrc/main/native-chat/agent-session-wire/structured-agent-session-claude-queued-stop.test.tssrc/main/runtime/claude-structured-fake-connection-test-fixture.tssrc/main/runtime/structured-claude-scripted-runtime-test-support.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.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Pinned the cancel-confirmation contract — a new
createClaudeControlSurface cancelAsyncMessagecase inclaude-agent-sdk-control-requests.test.tsmocks the query method returningtrue,false, andundefined, asserting the surface resolvestrueonly for the first andfalsefor the rest, plusfalsewhen the SDK method is absent. It exercises the samecancelled === truepath the higher-level sweep relies on, and fails if the surface regresses to the old fire-and-forgetvoidresult.
Verified the case runs green (pnpm vitest run src/main/claude/claude-agent-sdk-control-requests.test.ts, 2 passed). No production lines changed since the prior review.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Await the async journal snapshot in the queued-stop host test —
dispatchandstatusinstructured-agent-session-claude-queued-stop.test.tsare nowasyncandawait host.journalSnapshot(SESSION)before reading.submissions/.items, plus the directjournalSnapshotcall feedingactiveStructuredAgentSessionTurnId. This brings the new test in line withjournalSnapshot's async signature after main landed its own equivalent fix (1b458795), which the merge commit pulled in. No production lines changed; the assertions still pin B asrejected provider_cancelled_before_startand the session asidle.
Verified the file runs green (pnpm vitest run src/main/native-chat/agent-session-wire/structured-agent-session-claude-queued-stop.test.ts, 1 passed). The prior review's approval at f99732e covers the unchanged production logic.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
A fixed 20 ms sleep does not cover the host's asynchronous journal writes on a loaded runner.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Queued-stop test waits for state instead of sleeping —
structured-agent-session-claude-queued-stop.test.tsreplaces the fixed 20 mssettled()sleeps with avi.waitFor-backedeventually()helper that asserts the exact state each step needs: both sends reaching the fake connection, Aaccepted, Bpending, then Brejected provider_cancelled_before_startand the sessionidle. This removes the dependency on the host's asynchronous journal writes that the earlier review flagged. No production lines changed.
Verified the file runs green (pnpm vitest run src/main/native-chat/agent-session-wire/structured-agent-session-claude-queued-stop.test.ts, 1 passed). The assertions still fail on the pre-fix production behavior — B never settles, so the final waitFor times out — so the test retains its ability to catch the regression. The prior approval at 36c78d9 covers the unchanged production logic.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
StatusReady for review. Head What the review covered
Validation
Known, not in this PR
Review session at
|

ELI5
If you sent a second message to a Claude chat while Claude was still answering the first one, then pressed Stop, the second message vanished without a word and the chat kept saying "Working" until Claude was restarted. Now Stop withdraws that second message and the chat goes idle.
What Changed
Before: Claude replies to message A, you send message B, Claude holds B in its queue, and you press Stop. Claude drops B, but Orca never records that. B stays "sent, waiting for an answer" forever, so the tab, the sidebar and the chat all keep showing Working and the Stop button, and B is gone without any notice.
After: the same Stop records B as withdrawn before it started (
provider_cancelled_before_start). The chat goes idle once the stopped reply ends. On this PR alone, B's bubble is simply removed: there is no notice, and its text is not returned. Returning a withdrawn message's text to the composer is #23026's job; this PR makes sure the withdrawal is recorded at all.Mechanism, part 1: Orca learns what the installed Claude CLI can do from a list of capabilities the CLI advertises. That list is only on the
system/initframe that opens each turn. Orca read it once, from whichever frame proved the session had started. On every Orca install, that is the frame from the SessionStart hook Orca itself installs, and it carries no capabilities. So Orca believed the CLI could not cancel its queue, and Stop never asked it to. The capability list is now one value derived from every report the CLI makes: the first report that names any capabilities sets it, and a report that names none never clears it. The same rule runs at startup and on each turn'ssystem/init, so it does not matter which frame proved the start, or whether startup finished before the first turn opened.Mechanism, part 2: on a CLI that really cannot cancel its queue in one step, Stop withdraws each queued message one at a time. The CLI answers whether it withdrew each one, and Orca used to throw that answer away. Orca now keeps it and records each confirmed message as withdrawn, the same way the one-step path does. A message the CLI did not confirm (it already ran, or the answer never came) is left alone.
Why
The step that records a withdrawn message was already correct. It just never received the message, because of the two gaps above. Fixing those two inputs uses the existing mechanism instead of adding a new one.
Alternatives considered:
Linked Issue
Found in live QA of the Stop-while-queued work. No separate issue.
Visual Proof
Live desktop QA on a second Mac with the real Claude CLI: send A (a long story), queue B while A is answering, then press Stop. Three runs on this PR, each in a fresh chat, and two on
mainfor comparison.mainpending, with nothing after itrejected provider_cancelled_before_start(3/3)interruptedSettled 45 s after Stop, runs 1 to 3:
Controls: Stop with nothing queued acts in about 20 ms, and a cold send replies normally. With B queued, Stop takes about 3 s to act, the same on
main; this PR does not change that.Testing
Reproduced first with the real Claude CLI (2.1.280): with a SessionStart hook in the project settings, capabilities came back empty and the interrupt receipt listed B as still queued. Claude cancelled B, and Orca's record of B never settled. Without the hook, the same run settled B correctly.
claude-structured-queued-stop.test.ts(adapter), all failing onmain:system/initgive the same answer: Stop asks Claude to cancel the queue, and B is recorded as withdrawn.structured-agent-session-claude-queued-stop.test.ts(host, fails onmain): the exact sequence of A running, B handed over and queued, then Stop. The journal records B asrejected provider_cancelled_before_start, and the session status is idle once the interrupted turn ends.claude-structured-control-actions.test.ts: only messages the CLI confirms it withdrew are recorded; an unconfirmed or failed withdrawal leaves the message untouched.claude-structured-real-cli.test.ts: a new real-CLI case with a project SessionStart hook. It uses the machine's own Claude login in place and sends A, queues B, then Stops. It fails onmainand passes here.pnpm tc:node,tc:webandtc:cli,oxlint,check:code-quality:changed(0 findings) andcheck:react-doctor:changedpass.src/main/claude,src/main/native-chat,src/sharedand the cross-version agent-session wire test pass, both plainly and with the Orca session variables unset. The rest of the cross-version folder and one refusal test timed out only in the combined run, while archives were being extracted in parallel, and passed when run on their own.The four older real-CLI cases wait for startup before the first message, and they time out on this laptop on
maintoo: its Claude settings have no SessionStart hook, and Claude 2.1.280 sendssystem/initonly once a message arrives. Unchanged by this PR.I manually tested these changes locally
Automated tests added/updated, or explained why not below
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
Nothing is sent over the wire and nothing new is saved: the capability list lives only in the host's memory for one Claude process. Mixed versions are unaffected. Behaviour is the same on macOS, Linux, Windows and SSH hosts, because it is the host talking to its own Claude child.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)Author: @BrennanKB5