Skip to content

fix(server): treat signal-killed Claude subprocess as interrupted - #5142

Closed
marcoamt wants to merge 4 commits into
pingdotgg:mainfrom
marcoamt:fix/claude-shutdown-runtime-error
Closed

marcoamt wants to merge 4 commits into
pingdotgg:mainfrom
marcoamt:fix/claude-shutdown-runtime-error

Conversation

@marcoamt

@marcoamt marcoamt commented Jul 31, 2026 •

Copy link
Copy Markdown

What 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

Screenshot 2026-07-31 alle 22 56 46

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

Open in Devin Review

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.

Reviewed by Cursor Bugbot for commit 8021acf. Bugbot is set up for automated code reviews on this repo. Configure here.

Summary by CodeRabbit

  • Bug Fixes

    • Claude sessions interrupted by SIGTERM or SIGINT are now handled as interrupted turns rather than runtime errors.
    • Prevents an unnecessary runtime.error from being emitted when Claude is stopped externally.
  • Tests

    • Added regression coverage for interrupted Claude subprocesses.

@coderabbitai

coderabbitai Bot commented Jul 31, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

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 dd9528a and f806188.

📒 Files selected for processing (2)
  • apps/server/src/provider/Layers/ClaudeAdapter.test.ts
  • apps/server/src/provider/Layers/ClaudeAdapter.ts

Included 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 SIGTERM or SIGINT as an interrupted turn. A regression test verifies that the stream emits an interrupted turn.completed event without emitting runtime.error.

Changes

Claude interruption handling

Layer / File(s) Summary
Signal interruption classification and regression coverage
apps/server/src/provider/Layers/ClaudeAdapter.ts, apps/server/src/provider/Layers/ClaudeAdapter.test.ts
isClaudeInterruptedMessage recognizes SIGTERM and SIGINT termination messages. The regression test verifies the interrupted completion event and the absence of runtime.error.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: juliusmarminge

Merge Risk: ⚪ Minimal · up to f8061

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

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 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 main change: treating signal-terminated Claude subprocesses as interrupted.
Description check ✅ Passed The description includes What Changed, Why, UI Changes, and Checklist sections. It explains the cause, implementation, regression test, and user-visible effect. The focused scope and required UI evide…
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
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Jul 31, 2026
@macroscopeapp

macroscopeapp Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

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.

- ClaudeAdapter now recognizes "terminated by signal SIGTERM/SIGINT" from the Claude Agent SDK's ProcessTransport as a graceful interruption instead of surfacing a runtime.error
- Covers the case where the OS delivers the signal directly to the subprocess (e.g. desktop app quit) ahead of our own stopSession()-driven close
- Add regression test asserting no runtime.error is emitted and the turn completes with state "interrupted"
@marcoamt
marcoamt force-pushed the fix/claude-shutdown-runtime-error branch from 8f898ff to e6c7331 Compare July 31, 2026 20:43
@marcoamt marcoamt changed the title {"title": "fix(server): treat signal-killed Claude subprocess as interrupted", "body": "placeholder"} fix(server): treat signal-killed Claude subprocess as interrupted Jul 31, 2026
@marcoamt

marcoamt commented Aug 4, 2026

Copy link
Copy Markdown
Author

This PR should fix #5323

@juliusmarminge

Copy link
Copy Markdown
Member

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.

@marcoamt
marcoamt deleted the fix/claude-shutdown-runtime-error branch September 23, 2026 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants