Skip to content

fix(claude): withdraw a follow-up queued behind a stopped turn instead of dropping it silently - #23553

Merged
brennanb2025 merged 5 commits into
mainfrom
brennanb2025/claude-queued-cancel-settles
Sep 28, 2026
Merged

brennanb2025 merged 5 commits into
mainfrom
brennanb2025/claude-queued-cancel-settles

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​559 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​555
Prod 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​42 $\color{#cf222e}{\Huge{\mathbf{−}}}$​19 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​23

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/init frame 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's system/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:

  • Treat a pending Claude message as not working once the turn ends. Rejected: after a turn ends, Claude immediately starts the next queued message, so a pending message at that point is often real work. This would hide it.
  • Use the CLI's per-message "cancelled" lifecycle events as the settlement signal. This is the provider's own final word on each message, and it could also rescue a send whose settlement was lost some other way. But it adds a new kind of frame to consume, with its own capability check, and I have not verified whether older CLIs send it. Left for a follow-up.
  • Read capabilities only from turns and drop the startup read. Rejected: the startup read also consults the CLI's initialize answer, and a CLI that advertises there would lose its capabilities until its first turn opened.

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 main for comparison.

main This PR
B in the journal after Stop pending, with nothing after it rejected provider_cancelled_before_start (3/3)
Chat, tab and sidebar still Working minutes later (the longest was checked at 3 min 16 s) Interrupted and idle within 300 ms of A's interrupted
B's bubble stays removed, with no notice (see above)

Settled 45 s after Stop, runs 1 to 3:

run 1
run 2
run 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 on main:

    • A start proven by a SessionStart hook and a start proven by system/init give the same answer: Stop asks Claude to cancel the queue, and B is recorded as withdrawn.
    • A later frame that names no capabilities does not clear them.
    • Capabilities a turn reported survive startup finishing after that turn opened.
    • On a CLI without one-step queue cancel, a message withdrawn one at a time is recorded as withdrawn.
  • structured-agent-session-claude-queued-stop.test.ts (host, fails on main): the exact sequence of A running, B handed over and queued, then Stop. The journal records B as rejected 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 on main and passes here.

  • pnpm tc:node, tc:web and tc:cli, oxlint, check:code-quality:changed (0 findings) and check:react-doctor:changed pass. src/main/claude, src/main/native-chat, src/shared and 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 main too: its Claude settings have no SessionStart hook, and Claude 2.1.280 sends system/init only 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

  • 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

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

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

Author: @BrennanKB5

…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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Capabilities survive a SessionStart-proved start — readClaudeCapabilities now folds observed plus every report, keeping the first non-empty capability list and never clearing. Startup and each turn's system/init both apply it, so interrupt_cancel_queued_v1 is learned regardless of which frame proved the start.
  • One-at-a-time withdrawal now settles — cancelAsyncMessage returns Promise<boolean> (cancelled === true, false when the SDK method is absent), and cancelClaudeTurn'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.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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 configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: e602596e-d11b-46e3-85ec-91c73ccd378c

📥 Commits

Reviewing files that changed from the base of the PR and between 36c78d9 and 4097097.

📒 Files selected for processing (1)
  • src/main/native-chat/agent-session-wire/structured-agent-session-claude-queued-stop.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/native-chat/agent-session-wire/structured-agent-session-claude-queued-stop.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

Claude 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 40970

Queued messages are recorded as withdrawn only when cancellation is confirmed, with no identified issue requiring a fix before merge.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 36c78

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
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed settlement path acts on the interrupted Claude session's dispatch waiters using provider UUIDs; the identified entrypoint signal does not show a new externally reachable route. Exposure through the outer transport was not independently assessed.

Trust Boundaries and Controls

  • observed — The host admits a cancellation against caller and session state before reaching the provider. At the provider boundary, only confirmed cancellation results cause the corresponding queued dispatch to be marked rejected.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 21.74% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 23 functions across 14 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 summarizes the primary change: withdrawing a queued Claude follow-up when its active turn is stopped.
Description check ✅ Passed The description is detailed and covers the user impact, implementation, rationale, testing, visual proof, compatibility considerations, and checklist. It does not provide a linked issue and leaves the…
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 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: baf14865-cee1-4619-a750-dc3ce0f9f522

📥 Commits

Reviewing files that changed from the base of the PR and between 9179b93 and 279c4e6.

📒 Files selected for processing (13)
  • src/main/claude/claude-agent-sdk-control-requests.ts
  • src/main/claude/claude-structured-control-actions.test.ts
  • src/main/claude/claude-structured-control-actions.ts
  • src/main/claude/claude-structured-init-proof.ts
  • src/main/claude/claude-structured-queued-stop.test.ts
  • src/main/claude/claude-structured-real-cli.test.ts
  • src/main/claude/claude-structured-session-acquisition-processless.test.ts
  • src/main/claude/claude-structured-session-acquisition.ts
  • src/main/claude/claude-structured-session-startup.ts
  • src/main/claude/claude-structured-session-test-support.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-claude-queued-stop.test.ts
  • src/main/runtime/claude-structured-fake-connection-test-fixture.ts
  • src/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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Pinned the cancel-confirmation contract — a new createClaudeControlSurface cancelAsyncMessage case in claude-agent-sdk-control-requests.test.ts mocks the query method returning true, false, and undefined, asserting the surface resolves true only for the first and false for the rest, plus false when the SDK method is absent. It exercises the same cancelled === true path the higher-level sweep relies on, and fails if the surface regresses to the old fire-and-forget void result.

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.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Await the async journal snapshot in the queued-stop host test — dispatch and status in structured-agent-session-claude-queued-stop.test.ts are now async and await host.journalSnapshot(SESSION) before reading .submissions/.items, plus the direct journalSnapshot call feeding activeStructuredAgentSessionTurnId. This brings the new test in line with journalSnapshot'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 as rejected provider_cancelled_before_start and the session as idle.

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.

Pullfrog  | View workflow run | Using 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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Queued-stop test waits for state instead of sleeping — structured-agent-session-claude-queued-stop.test.ts replaces the fixed 20 ms settled() sleeps with a vi.waitFor-backed eventually() helper that asserts the exact state each step needs: both sends reaching the fake connection, A accepted, B pending, then B rejected provider_cancelled_before_start and the session idle. 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.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@brennanb2025

brennanb2025 commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Status

Ready for review. Head 4097097a7b, based on current main.

What the review covered

  • The failure: Stop withdraws a message Claude has queued only if Orca knows the CLI can cancel its queue. Orca took that capability list from whichever frame proved the session had started. Under the SessionStart hook Orca installs, that frame carries no capabilities. So Stop never asked Claude to cancel the queue, and the queued message stayed pending forever. This PR removes that cause: capabilities come from every report the CLI makes, and a report with none never clears them. It doesn't add a guard around the symptom. The one-at-a-time fallback now keeps the CLI's own "withdrawn" answer instead of discarding it.
  • The step that records a withdrawn message was already correct and is unchanged. This PR only fixes its two inputs.

Validation

  • Live desktop QA on a second Mac with the real Claude CLI: 3/3 runs fixed, compared with 2/2 stuck on main. The screenshots and the table are in the description. Stop with nothing queued and a normal first send are unchanged.
  • The host test now waits on each state it checks instead of sleeping 20 ms (the review thread). It fails with the production change reverted (the queued message stays pending) and passes with it.
  • CI green. tc:node, tc:web and tc:cli, oxlint, the changed-lines gate and React Doctor are clean.

Known, not in this PR

  • On this PR alone, the withdrawn message's bubble disappears with no notice. Returning its text to the composer is fix(native-chat): Stop is there from the moment a message is sent #23026.
  • With a message queued, Stop takes about 3 s to act, the same as on main. Before interrupting, Stop waits up to 3 s for the queued message to be accepted, and a queued message never is until it runs. It is a separate fix and will be planned on its own.

Review session at 4097097a7b

  • Readiness checklist: PASS at the start and at the end, with no findings.
  • Review loop: CLEAN, with no changes, covering the whole diff, including the main merge and the test-wait change. Removing either half of the fix makes its tests fail.
  • Live QA re-run at this head on the second Mac, with the real Claude CLI and a fresh profile: 4 of 4 runs PASS, one with an image on the queued message. The queued message was withdrawn about 3 s after Stop, and the chat left Working. A Stop with nothing queued and a cold send are unchanged. The ~3 s delay is the same on main.
  • Difference from the common pattern: a common approach ends the agent's process on Stop, so a queued message simply dies with it. Orca keeps the Claude process alive across Stop, and tracks delivery per message, so this PR settles each withdrawn message from the CLI's own answer. That follows from Orca's existing design; this PR does not add it.
  • Residual, predates this PR, older-CLI path only: cancelling the first message of a batch the CLI has already pulled for its next turn drops the whole batch but answers "not cancelled", so those messages stay waiting. The same happens for a cancel that times out. A separate follow-up covers giving every waiting message a way to end.

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