Skip to content
Source
Sign inSign up
pingdotgg/t3code

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

Closedmarcoamt(GitHub profile, opens in a new tab)wants to merge 4 commits intomain fromrefs/pull/5142/headopened View on GitHub

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](https://cursor.com/bugbot) for commit 8021acff78f83fb0a1f75cabcdba8f4540a688b9. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

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.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      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 dd9528a974ba534faa8d1588f3f137fa2a281860 and f8061887f83ccc351cfecb661332272aebe84c3c.

      📒 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 nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring 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 nameStatusExplanation
      Title check✅ PassedThe title clearly summarizes the main change: treating signal-terminated Claude subprocesses as interrupted.
      Description check✅ PassedThe 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✅ PassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes check✅ PassedCheck 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.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. 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).
    4. marcoamt(GitHub profile, opens in a new tab) changed the title

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

    6. juliusmarminge closed this

Sign in to join this conversation.