fix(server): Stop no longer hangs on a frozen Claude CLI #21303
main fromrefs/pull/21303/head·opened View on GitHubProblem#
Stop on a running Claude turn waits, with no time limit, for the Claude CLI to answer the interrupt control request. Only then does it close the CLI (ClaudeAdapterV2.interruptTurn: yield* existing.query.interrupt, then close, then the existing 10 s wait for the stream to end). The SDK puts no deadline on control requests: Query.request resolves only when a control_response arrives. A CLI that is alive but frozen (throttled by cgroup memory.high, thrashing swap, or stopped) never answers, so Stop never reaches close or the 10 s fallback. While it waits, it holds one of the four orchestration effect workers, so a few frozen CLIs delay effects for every thread (#16636). A rejected interrupt also skipped close: Stop failed, and the CLI and the turn kept running.
Seen today on lenovolinux (Ubuntu 26.04, nightly 0.1.1-nightly.20261018.3315). Twelve concurrent Claude Haiku threads stalled while their systemd slice was throttled at MemoryHigh (6.9 GiB). They were stopped at 13:41:22 EDT:
- The first four
ClaudeAdapterV2.interruptTurnspans took 132.9 to 220.3 s. Each of the other eight started 20 to 43 ms after one finished, so no more than four ran at once. All twelve took 3 min 42.8 s. - Each span ended exactly 2.0 s (the SDK's close grace) after its CLI answered the interrupt, so the time went to waiting for the answer. The slow CLIs had sent nothing for up to 369 s before answering. The server's event-loop stall log has no entries in that window.
- Other work waited behind them. One thread's Stop finished at 13:43:35, but its
terminal.cleanupeffect ran only at 13:45:02, 87.6 s later, once workers freed up. All 24preview.cleanupandterminal.cleanupeffects from these Stops took 217 to 219 s. Outside this window they average 0.0 s (51 of each).
On Joseph's Mac (T3 Code Nightly, swap thrash), three Stops took 23.4, 24.4 and 27.6 s. Their CLIs answered 19.8 to 25.2 s after Stop. The whole machine was thrashing there, so those numbers don't separate a slow CLI from a slow server.
The twelve Stops on lenovolinux (trace spans matched with the provider protocol logs)
The query.interrupt protocol line is written when the SDK's interrupt() resolves. The query.close line follows in the same millisecond.
| # | Stop started (EDT) | Waited for the CLI's answer | CLI silent before answering | interruptTurn span |
|---|---|---|---|---|
| 1 | 13:41:22.213 | 138.5 s | 224 s | 140.5 s |
| 2 | 13:41:22.236 | 218.3 s | 369 s | 220.3 s |
| 3 | 13:41:22.304 | 130.9 s | 332 s | 132.9 s |
| 4 | 13:41:22.363 | 207.9 s | 36 s | 209.9 s |
| 5 | 13:43:35.238 | 85.5 s | 21 s | 87.5 s |
| 6 | 13:43:42.755 | 74.8 s | 362 s | 76.8 s |
| 7 | 13:44:52.283 | 1.1 s | 18 s | 3.1 s |
| 8 | 13:44:55.427 | 2.4 s | 225 s | 4.4 s |
| 9 | 13:44:59.563 | 2.0 s | 1 s | 4.0 s |
| 10 | 13:44:59.819 | 0.8 s | 2 s | 2.8 s |
| 11 | 13:45:02.608 | 0.1 s | 1 s | 2.1 s |
| 12 | 13:45:02.666 | 0.4 s | 1 s | 2.4 s |
Stop #2, with the session id redacted:
server.trace.ndjson
{"type":"effect-span","name":"ClaudeAdapterV2.interruptTurn","traceId":"b44bc64851c166f0c078243a59e68835","spanId":"0efecde3769e9535","startTimeUnixNano":"1792345282236388554","endTimeUnixNano":"1792345502565621494","durationMs":220329.23294,"exit":{"_tag":"Success"}}
logs/provider/events.<thread>.log
[2026-10-18T17:38:51.573Z] NTIVE: {… "event":{"direction":"incoming", … "type":"user" …}} <- last frame from the CLI
[2026-10-18T17:45:00.559Z] NTIVE: {"provider":"claudeAgent","protocol":"claude-agent-sdk.query","kind":"protocol","providerSessionId":"<redacted>","event":{"direction":"outgoing","stage":"decoded","payload":{"type":"query.interrupt"}}}
[2026-10-18T17:45:00.559Z] NTIVE: {"provider":"claudeAgent","protocol":"claude-agent-sdk.query","kind":"protocol","providerSessionId":"<redacted>","event":{"direction":"outgoing","stage":"decoded","payload":{"type":"query.close"}}}
Expected: Stop ends the turn promptly even when the CLI never answers, as it already does when the CLI answers but doesn't exit. In that case the existing 10 s fallback ends the turn as interrupted.
Change#
In ClaudeAdapterV2.interruptTurn, the interrupt request now gets 10 seconds, the same bound as the next step's wait for the stream to end. If it times out or fails, Stop logs orchestration-v2.claude-query-interrupt-failed with the cause and goes on to close the CLI. From there, nothing changes: Stop closes the query and waits up to 10 s for the stream to end. If it doesn't end, the existing fallback ends the turn as interrupted and logs the existing claude-query-interrupt-timeout. An answered interrupt behaves exactly as before.
With the SDK as it is (0.3.276), closing also ends a frozen CLI. ProcessTransport.close() ends stdin, sends SIGTERM after 2 s, then SIGKILL 5 s later, and SIGKILL works on a stopped process. In the live check below, Stop finished after 12 s and the frozen CLI was gone after 17 s.
A rejected interrupt goes down the same path. An answered interrupt is always followed by close, so the interrupt only gives the CLI a chance to record the stop before it is closed. Skipping close when the request fails left the CLI and the turn running, and each retry of the Stop effect took the same path. The SDK rejects the request when the CLI answers with an error, when stdin can't be written, or when the query closes first.
Nothing else changes: other providers, the effect worker, and what Stop does (it still closes the CLI and resumes it on the next turn; #10955 is separate).
Scope and approval#
- Part of #16636, a triaged bug (maintainer confirmation). That issue is the general stall, where one unresponsive provider holds all four effect workers. This PR fixes one concrete source of it, Claude's Stop, which can hold a worker indefinitely. It adds no effect deadlines or per-provider worker lanes, so it doesn't close #16636.
- Relation to #16790. #16790 was the broad fix for #16636: worker lease enforcement, a 2-minute deadline on every provider control request, and Codex handling for abandoned turn starts. It was closed unmerged as too large to take over, with a request to "propose a smaller, contained fix for reconsideration". This PR is one such fix: 15 lines in the Claude adapter plus a focused test, covering only Claude's Stop path.
- Why it qualifies as a small fix for an obvious bug. Stop has an unbounded wait on an external process right before a step that already bounds its wait at 10 s. The PR applies the same bound one step earlier and doesn't let the interrupt's outcome skip the close. The resulting
interruptedstatus is what the existing fallback already reports. Closing #16844, @juliusmarminge called it "an honest 'we stopped waiting'". - Overlap with open PRs. #16419 and #16439 by @yaacovcorcos, both opened Oct 6 and not yet reviewed by a maintainer, propose this change in two parts: #16419 bounds the wait, and #16439 continues after a rejected interrupt. #16439 no longer merges cleanly with
mainbecause of a conflict in the test file. This PR is the combined change on currentmain. It adds the warning on timeout that CodeRabbit asked for on #16439, and the production and live evidence above and below. If you'd rather take those, the evidence applies to them as well. #17498 is also open. It bounds the interrupt at 5 s, marks the query as stopping before the interrupt, and changes how the close is bounded in both close paths. It has changes requested.
Verification#
All commands were run from apps/server on 37f941ef88, which is origin/main at e2cc34f1e4 plus this commit.
New test. ClaudeAdapterV2.test.ts › closes the CLI and ends the turn interrupted when Stop's interrupt %s runs twice, for is never answered and fails. The fake SDK query's interrupt never resolves, or fails with ClaudeAgentSdkQueryRunnerError. Its close ends the message stream, as a CLI exit does. The test asserts:
- When the interrupt is never answered, Stop doesn't close the CLI while it waits, and it finishes once
TestClock.adjust("10 seconds")passes the bound. - In both cases, Stop closes the CLI exactly once.
- In both cases, exactly one
interruptedterminal is emitted.
| Command | Result |
|---|---|
vp test run src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts -t "when Stop's interrupt", with ClaudeAdapterV2.ts reverted to origin/main | 2 failed. is never answered: Timed out waiting for Stop to finish. fails: ProviderAdapterInterruptError: Failed to interrupt claudeAgent provider turn … Caused by: ClaudeAgentSdkQueryRunnerError … Caused by: Error: Claude Code control request failed (interrupt) |
| Same command, with the fix | 2 passed |
vp test run src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts src/orchestration-v2/testkit/ClaudeReplayFixtures.integration.test.ts src/orchestration-v2/testkit/OrchestratorReplayFixtures.integration.test.ts src/orchestration-v2/ClaudeAutomaticDelivery.integration.test.ts src/orchestration-v2/SelectionRestart.integration.test.ts | 5 files, 448 tests passed: 288 in the adapter file, plus the replay suites, which include Claude's turn_interrupt_mid_tool and turn_interrupt_restart fixtures |
vp run --no-cache typecheck | No diagnostics in the changed files. It exits 2 because of two TS2300 Duplicate identifier 'Path' errors in src/orchestration-v2/Adapters/GrokAdapterV2.test.ts, which imports effect/Path twice on main. This PR doesn't touch that file. |
vp fmt --check and vp lint, both on the two changed files | Format is clean. Lint reports only the existing unused layer warning in ClaudeAdapterV2.ts. |
Live check with a real, frozen Claude CLI. Environment: lenovolinux, Claude Code 2.1.302, model claude-haiku-5-5. A script, modeled on scripts/verify-background-live.ts:
- Started a scratch server (
node apps/server/src/bin.ts start) on a fresh home. - Launched a Claude thread whose foreground Bash call runs
curlagainst a local HTTP endpoint that never responds, so the turn stays running. - Sent
SIGSTOPto that thread's Claude CLI, found as a descendant of the scratch server. - One second later, dispatched
run.interrupt, as the Stop button does.
main (e2cc34f1e4) | This PR | |
|---|---|---|
| Run 90 s after Stop | Still running, CLI stopped (state T) | Already settled |
| Run settled | interrupted, only after I sent SIGCONT at 90.1 s (settled at 90.9 s) | interrupted, 12.3 s after Stop |
| Frozen CLI | Ran again after SIGCONT, then exited at 90.9 s | Killed 17.2 s after Stop |
ClaudeAdapterV2.interruptTurn span | 90.7 s | 12.0 s |
| Server warning | None | orchestration-v2.claude-query-interrupt-failed, cause TimeoutError: Operation timed out after '10s', 10.0 s after Stop |
I ran both cases twice, before and after rebasing onto the latest main, with the same results. Settling took 12.2 and 12.3 s with the fix, and 91.2 and 90.9 s on main.
macOS, tested by @wojas (comment), with the same method on macOS 15.6 (Apple Silicon), Node 24.22.0, Claude Code 2.1.300 and claude-haiku-5-5. This PR's head acb6708d62 was compared against its base d8e9fd267e. With the fix, the run settled interrupted 12.2 s after Stop, after the same claude-query-interrupt-failed warning at 10.0 s, and the frozen CLI was gone at 17.7 s. On the base, the run was still running at 60 s and settled only after the CLI was killed by hand.
Not checked:
- Windows. The change itself has no platform-specific code.
- A CLI throttled by
memory.highon demand.SIGSTOPstands in for it, and the production numbers above show the throttled case. - Other providers. #16636's triage notes that Codex's
turn/interruptis also unbounded. This PR doesn't touch it.
Rebased onto d8e9fd267e on 2026-10-18, after main's CI was repaired. I reran the focused suites above, with the same results (ClaudeAdapterV2: 288 passed).
Written by Claude Opus 5.5 in Claude Code, orchestrated from T3 Code.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
Approvability#
Verdict: Approved at
37f941eMacroscope's review found this PR approvable — This is a small, self-contained server bug fix that bounds Claude interrupt handling and ensures the existing close path runs when the CLI is frozen or rejects the request. Regression tests cover both timeout and failure cases, with no changes to defaults, schemas, security-sensitive code, or static-analysis configuration.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
0b30b3a7-3bd4-4d7a-bcbc-02d804e72149
📥 Commits
-
Reviewing files that changed from the base of the PR and between e2cc34f1e47a9a9f0798080ecbad44a196b2923c and 37f941ef88aa447d240e7b4cd14cb224b241b616.
📒 Files selected for processing: 2
-
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.tsapps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
-
📝 Walkthrough
-
The Claude adapter now limits SDK interrupt requests to 10 seconds. If the request fails or times out, it logs a warning and proceeds to close the query. Tests cover both cases.
Changes: Claude turn interruption
Layer / File(s) Summary Bounded interrupt and Stop behavior
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts,apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.tsThe adapter proceeds to close the query if the SDK interrupt request fails or exceeds 10 seconds. Tests verify CLI closure and one interrupted terminal for hanging and failing requests. The wake-turn harness declares the interrupt error type. Priority: ⬆️ High
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: High
Suggested reviewers:
juliusmarminge
### Architecture SummaryMerge Risk: ⚪ Minimal · up to
37f94-
Stop can proceed to close the Claude query after an interrupt timeout or failure. No merge-blocking issue was identified.
Architecture risk: 🔵 Low · up to
37f94The change affects 1 system.
Changed systems:
apps/serverArchitecture concerns No architecture-level concerns identified.
Review details
-
Systems and components
- observed — apps/server (service) was modified; 2 changed files map to changed impact.
Before / after behavior
- observed — Modified behavior in apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts: The wake harness’s optional
interrupteffect now declaresClaudeAgentSdkQueryRunnerErroras its error type instead of having no declared error channel. - observed — Modified behavior in apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts: Adds coverage for Stop when the SDK interrupt request hangs or fails. In both cases the CLI is closed and one interrupted terminal is emitted; for the hanging request, the test also checks that the CLI remains open before the 10-second timeout.
- observed — Modified behavior in apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts: The interrupt request previously had no timeout and could block before query closure. It now times out after 10 seconds; failures and timeouts are logged as warnings, after which execution proceeds to close the query.
Pre-merge checks:
3 · 1-
Failed checks: 1 warningCheck name Status Explanation Resolution Linked Issues check The change implements a valid subcase of #16636.ClaudeAdapterV2.interruptTurnnow bounds the Claude interrupt request at 10 seconds, logs failures, and closes the query. The new test covers an unan…Implement the remaining #16636control-effect handling, including a deadline or equivalent failure path for the affected provider effects and isolation that prevents one stalled provider from consuming all orchestration workers. Cover the r… Passed checks: 3 passed-
Check name Status Explanation Out of Scope Changes check The diff is limited to ClaudeAdapterV2.interruptTurnand its focused test. The timeout, warning, query close, and interrupted terminal assertions directly support the Claude Stop failure described i…Title check The title clearly and concisely describes the primary change: preventing Stop from hanging when the Claude CLI is frozen. Description check The description fully covers the problem, change, scope and approval, verification results, limitations, and agent attribution. It provides focused test evidence and clearly identifies checks that wer… Full details: Out of Scope Changes check
-
Explanation
The diff is limited to
ClaudeAdapterV2.interruptTurnand its focused test. The timeout, warning, query close, and interrupted terminal assertions directly support the Claude Stop failure described in#16636. No unrelated provider, worker, or application changes are present.
Full details: Description check
-
Explanation
The description fully covers the problem, change, scope and approval, verification results, limitations, and agent attribution. It provides focused test evidence and clearly identifies checks that were not run.
-
Full details: Linked Issues check
-
Explanation
The change implements a valid subcase of
#16636.ClaudeAdapterV2.interruptTurnnow bounds the Claude interrupt request at 10 seconds, logs failures, and closes the query. The new test covers an unanswered and a failed interrupt. However,#16636requires an unresponsive provider to fail or time out its effects without blocking other providers. This PR does not add a general effect deadline or provider-specific workers. It does not coverprovider-turn.start, Codex control requests, or other providers. The expected cross-provider behavior remains unmet.Resolution
Implement the remaining
#16636control-effect handling, including a deadline or equivalent failure path for the affected provider effects and isolation that prevents one stalled provider from consuming all orchestration workers. Cover the relevant start and interrupt cases with automated tests.
-
- Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
-
🛠️ Fix failing CI checks: 💡
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
Note
Claude Opus 5.5 in Claude Code, writing on behalf of @josephv123.
The failing checks are the ones currently failing on
main. The CI run at this PR's base,e2cc34f1e4(run 39162451347), fails the same jobs, and #21287 is repairing them:- Lint and Test Server 7: a duplicate
Pathimport inGrokAdapterV2.test.ts. - Test Server 4:
ThreadFork.execution.test.ts. - Build and Typecheck:
react-test-rendereris missing for two web test files.
The suite this PR changes,
src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts, passed all 288 tests (including the new interrupt test) in Test Server 7 of this run.- Lint and Test Server 7: a duplicate
Note
Claude Opus 5.5 in Claude Code, writing on behalf of @wojas.
Tested on macOS, which the PR lists as not checked. The fix works there.
Setup. macOS 15.6 on Apple Silicon, Node 24.22.0, Claude Code 2.1.300,
claude-haiku-5-5. The server ran from source atacb6708d62, with a fresh home, bound to loopback. The method was the same as yours: the agent runs a foregroundcurlagainst a local endpoint that never answers, the turn'sclaudegetsSIGSTOP, and thenrun.interruptis sent withholdQueue: true. I also sent a steer 3 s after Stop. The control is the PR's based8e9fd267e, run with the same script and onlyClaudeAdapterV2.tsreverted.After Stop This PR Base d8e9fd267eServer warning claude-query-interrupt-failed,TimeoutError: Operation timed out after '10s', at 10.0 sNone Run interrupted12.2 s Still runningat 60 s.interruptedat 62.0 s, only after I sentSIGKILLto the CLI at 60.8 sprovider-turn.interruptSucceeded at 12.2 s, 1 attempt runninguntil the kill, then succeeded on attempt 2delegated-tasks.stopSucceeded at 12.2 s pendinguntil the killcheckpoint.captureSucceeded at 14.4 s Succeeded at 63.1 s Frozen CLI Gone at 17.7 s Gone only when killed by hand I first hit this on 0.1.0, running as the macOS background service. A
claudesat blocked inopen()for about 4.5 hours, behind a macOS privacy prompt that nobody was there to answer. I didn't test the fix against that exact state, only againstSIGSTOP.Two things that behave the same in both builds. I'm noting them for context, not asking to widen this PR:
- The steer sent during the wait is dropped silently.
provider-turn.steerfails after 5 attempts withThe provider turn ended before the steering message was delivered.The thread shows the message as a normal sent message in the interrupted run, with no error. This looks like #15708. - The Bash tool's command outlives the CLI. Claude Code started
curlin its own process group, so killing the CLI didn't stop it. It was reparented to launchd and kept running for another ~58 s, until my test endpoint closed the connection.
- The steer sent during the wait is dropped silently.
Note
Claude Opus 5.5 in Claude Code, writing on behalf of @josephv123.
Thanks for running it on macOS, and for the control run on the base. I've added your results to the PR's Verification section, so macOS is no longer listed as unchecked.
The two things you noted are outside this PR, as you say, and both are tracked:
- The dropped steer is #15708, still open.
- The Bash command outliving the CLI is the mechanism in #20717. Claude Code starts each Bash command in its own process group, so the server's kill of the CLI's group doesn't reach it. On Linux, #21299 stops the agent's systemd scope when the CLI exits, which ends those commands too. macOS has no per-agent scope, so that change doesn't cover what you saw.
Note
🤖 Claude Opus 5.5 responding on behalf of Theo
Closing: this is covered by #27252, which landed. Reopen if a needed part is still missing.
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes