Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): stop kills lingering Claude work #5891

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 4 commits intomain fromrefs/pull/5891/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

Claude's interrupt request could succeed while resumed background tasks kept the CLI process alive. Repeated Stop clicks left the thread working until the process was killed manually.

Claude Stop now closes the provider query before cleanup. The SDK escalates to SIGKILL if the CLI ignores graceful exit. Cleanup also keeps a replacement session safe when the next message resumes the thread.

Tests: vp test run apps/server/src/provider/Layers/ClaudeAdapter.test.ts

Made with GPT-5.6 in T3 Code through the Codex harness.


Note

Medium Risk Changes core Claude session lifecycle and Stop semantics; close failures now fail operations instead of being logged and ignored, which can surface new errors during interrupt or session replacement.

Overview Claude Stop now tears down the provider session instead of calling SDK interrupt() and per-task stopTask. interruptTurn routes through stopSessionInternal, which closes the query first (SDK can escalate to SIGKILL) and emits task.completed with status stopped for every live task.

Session teardown only removes the map entry and emits session.exited when the context is still the active one, so a replacement session started while slow cleanup runs is not wiped. getContextUsage is capped at 1 second so stop does not hang on a stuck provider call.

stopAll still tries every session and surfaces the first close() failure as ProviderAdapterProcessError while leaving failed sessions registered. Replacement startSession no longer swallows stop errors from the prior session. Tests cover close failures, multi-session stop, and resume-during-interrupt races.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit e6f78bed1ee4e9f2ba6dae2dd612d52682d11ee3. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Fix lingering Claude work by closing provider sessions on stop and interrupt

  • interruptTurn and session replacement now close the Claude provider process via close() rather than issuing interrupt()/stopTask() SDK calls, which were leaving work running after a stop.
  • stopSessionInternal immediately closes the process, emits task.completed (stopped) for all live tasks, resolves pending approvals with cancel, and shuts down the prompt queue and stream fiber.
  • stopAll and the finalizer now attempt every session stop and surface aggregated failures instead of swallowing errors.
  • getContextUsage is wrapped in a 1-second timeout to prevent indefinite blocking during cleanup.
  • Risk: interruptTurn and startSession (replacement path) now fail with ProviderAdapterProcessError if the provider process close throws, instead of continuing silently.
Macroscope summarized e6f78be.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: 88771e71-63e6-41e5-9a56-bb38a15f1e44

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      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.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    3. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire11.3 KiB11.3 KiB+33 B (+0.3%)15.1 KiB✅
      CodexThread snapshot wire5.5 KiB5.5 KiB−2 B (−0.0%)7.3 KiB✅
      CodexLive turn WebSocket wire5.9 KiB5.9 KiB+35 B (+0.6%)7.8 KiB✅
      CodexLive turn WebSocket decoded49.7 KiB49.7 KiB0 B (0.0%)66.4 KiB✅
      CodexLive turn messages16160 (0.0%)21✅
      ClaudeTotal thread wire11.3 KiB11.3 KiB−21 B (−0.2%)15.1 KiB✅
      ClaudeThread snapshot wire5.5 KiB5.5 KiB−1 B (−0.0%)7.3 KiB✅
      ClaudeLive turn WebSocket wire5.9 KiB5.8 KiB−20 B (−0.3%)7.8 KiB✅
      ClaudeLive turn WebSocket decoded50.6 KiB50.6 KiB0 B (0.0%)66.4 KiB✅
      ClaudeLive turn messages16160 (0.0%)21✅

      Baseline: 83d769f · PR result: e6f78be · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 94.6 KiB
      • Claude decoded thread snapshot: 95.4 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    4. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Needs human review

      This PR changes the fundamental approach to stopping Claude sessions - replacing SDK-level interrupt/stopTask calls with process termination via close(). It also changes error propagation behavior in stopAll and session replacement. These are significant runtime behavior changes to session lifecycle management that warrant human review.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    5. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot). Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 50906db339d601c1dbc7c357e8be60d5f3145ab1. Configure [here](https://www.cursor.com/dashboard/bugbot).

Sign in to join this conversation.