fix(server): treat signal-killed Claude subprocess as interrupted #5142
main fromrefs/pull/5142/head·opened View on GitHubWhat Changed#
ClaudeAdapter now recognizes "terminated by signal SIGTERM/SIGINT" messages from the Claude Agent SDK's ProcessTransport as a graceful interruption instead of surfacing a runtime.error. Added a regression test asserting no runtime.error is emitted and the turn completes with state interrupted.
Why#
When the OS delivers SIGTERM/SIGINT directly to the Claude subprocess (e.g. on desktop app quit) ahead of our own stopSession()-driven close, the SDK's error message for the signal-killed process was being treated as a runtime error instead of a normal interruption.
UI Changes#
When Cmd+Q app and reopen a Claude Code thread it looks like screenshot
Checklist#
- This PR is small and focused
- I explained what changed and why
- I included before/after screenshots for any UI changes
- I included a video for animation/interaction changes
Note
[!NOTE]
Fix isClaudeInterruptedMessage to treat SIGTERM/SIGINT-killed subprocesses as interrupted#
When the Claude CLI subprocess is killed by SIGTERM or SIGINT before stopSession() completes, the Claude Agent SDK surfaces an error message containing 'terminated by signal sigterm' or 'terminated by signal sigint'. Previously these were treated as runtime errors; now isClaudeInterruptedMessage matches these substrings and returns interrupted state instead.
Macroscope summarized 8021acf. >
Note
Low Risk Small change to interruption heuristics in the Claude adapter with a focused regression test; no auth, data, or API surface changes.
Overview
When the desktop app quits, the OS can SIGTERM/SIGINT the Claude CLI child before stopSession() finishes. The Agent SDK then reports "terminated by signal SIGTERM/SIGINT" — which used to surface as runtime.error and a broken thread on reopen.
isClaudeInterruptedMessage in ClaudeAdapter now treats those SDK ProcessTransport messages like other graceful interruptions, so the turn ends with state interrupted and no runtime error.
A regression test simulates external subprocess kill and asserts no runtime.error and turn.completed with interrupted.
Summary by CodeRabbit#
Bug Fixes
- Claude sessions interrupted by
SIGTERMorSIGINTare now handled as interrupted turns rather than runtime errors. - Prevents an unnecessary
runtime.errorfrom being emitted when Claude is stopped externally.
- Claude sessions interrupted by
Tests
- Added regression coverage for interrupted Claude subprocesses.
- 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
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
Approvability#
Verdict: Approved 8f898ff
Straightforward bug fix that adds two string patterns to an existing pattern-matching function. The change correctly classifies SIGTERM/SIGINT subprocess terminations as 'interrupted' rather than runtime errors, following the same pattern already used for similar cases. Includes comprehensive test coverage.
You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).marcoamt(GitHub profile, opens in a new tab) changed the title
This PR should fix https://github.com/pingdotgg/t3code/issues/5323
Thanks for the PR. We're not taking changes to the orchestration and provider layers right now: that part of the server is being rewritten for V2, and merging into the current code would either conflict with or be thrown away by that work.
Closing for now. If this is still an issue once V2 lands, please reopen (or open a fresh PR against the new code) and we'll take a proper look.
juliusmarminge closed this
Sign in to join this conversation.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
0c178234-d792-41d4-9bc6-7494ebe6be77📥 Commits
Reviewing files that changed from the base of the PR and between dd9528a974ba534faa8d1588f3f137fa2a281860 and f8061887f83ccc351cfecb661332272aebe84c3c.
📒 Files selected for processing (2)
apps/server/src/provider/Layers/ClaudeAdapter.test.tsapps/server/src/provider/Layers/ClaudeAdapter.tsIncluded review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
📝 Walkthrough
Walkthrough#
The Claude adapter now treats subprocess termination by
SIGTERMorSIGINTas an interrupted turn. A regression test verifies that the stream emits an interruptedturn.completedevent without emittingruntime.error.Changes#
Claude interruption handling
apps/server/src/provider/Layers/ClaudeAdapter.ts,apps/server/src/provider/Layers/ClaudeAdapter.test.tsisClaudeInterruptedMessagerecognizesSIGTERMandSIGINTtermination messages. The regression test verifies the interrupted completion event and the absence ofruntime.error.Priority: ➖ Normal
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Suggested reviewers:
juliusmarmingeMerge Risk: ⚪ Minimal · up to
f8061The interruption path correctly completes signal-terminated Claude turns without reporting a runtime stream failure. No actionable merge risk remains.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands.