Uh oh!
There was an error while loading. Please reload this page.
fix(server): keep Claude CLI alive across Stop - #8997
Conversation
Closing the query on Esc forced the next prompt through --resume, which rewrites prompt cache. Interrupt the turn and live tasks instead, and only close when background work cannot be stopped. Co-authored-by: Cursor <cursoragent@cursor.com>
| Effect.as(true), | ||
| Effect.catch(() => Effect.succeed(false)), | ||
| ); | ||
| if (!stopAcknowledged || !context.liveTaskIds.delete(taskId)) { |
There was a problem hiding this comment.
🟠 HighLayers/ClaudeAdapter.ts:4636
A delayed concurrent interruptTurn can interrupt a newer turn after the original turn has already been stopped. The second call reaches context.query.interrupt() after its stopTask result is discarded, and _turnId is ignored; capture and re-check the requested turn identity before interrupting.
🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/server/src/provider/Layers/ClaudeAdapter.ts around line 4636:
A delayed concurrent `interruptTurn` can interrupt a newer turn after the original turn has already been stopped. The second call reaches `context.query.interrupt()` after its `stopTask` result is discarded, and `_turnId` is ignored; capture and re-check the requested turn identity before interrupting.
| yield* Effect.tryPromise({ | ||
| try: () => context.query.interrupt(), | ||
| catch: (cause) => toRequestError(threadId, "turn/interrupt", cause), | ||
| }); |
There was a problem hiding this comment.
🟠 HighLayers/ClaudeAdapter.ts:4673
A subagent that starts during query.interrupt() is left running, and the Claude CLI stays alive instead of taking the stopSessionInternal() fallback. The liveTaskIds check occurs only before the interrupt, so recheck it after query.interrupt() and close the session if a task was added.
🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/server/src/provider/Layers/ClaudeAdapter.ts around line 4673:
A subagent that starts during `query.interrupt()` is left running, and the Claude CLI stays alive instead of taking the `stopSessionInternal()` fallback. The `liveTaskIds` check occurs only before the interrupt, so recheck it after `query.interrupt()` and close the session if a task was added.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 4b1c76f. Configure here.
| if (context.turnState) { | ||
| yield* completeTurn(context, "interrupted"); | ||
| } |
There was a problem hiding this comment.
Leftover interrupt result closes next turn
Medium Severity
interruptTurn locally completeTurns after Query.interrupt() acknowledges, but the SDK still emits the interrupted result (and sometimes a truncated assistant message) on the live stream. handleResultMessage completes whatever turnState exists, so a follow-up sendTurn can be closed as interrupted. If those leftovers arrive before the next send, handleAssistantMessage also auto-starts a synthetic working turn.
Additional Locations (2)
Reviewed by Cursor Bugbot for commit 4b1c76f. Configure here.
| if (context.turnState) { | ||
| yield* completeTurn(context, "interrupted"); | ||
| } |
There was a problem hiding this comment.
Interrupt leaves pending requests open
Medium Severity
Cooperative Stop no longer runs the pendingApprovals and pendingUserInputs teardown that lived in stopSessionInternal. After Esc, completeTurn marks the turn interrupted while request.opened and user-input.requested can stay unresolved, so approval or AskUserQuestion dialogs remain on a finished turn.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 4b1c76f. Configure here.
ApprovabilityVerdict: Not approved Macroscope's review found this PR not approvable — This changes the production Claude Stop path from closing the CLI to coordinating subagent termination, interrupting the turn, and retaining the process, with new concurrency and lifecycle behavior. Unresolved concerns involve delayed interrupts, late SDK events, runaway tasks, and pending interactive requests, so the effects require human review. Not approved because:
Adjust the Minimum Blocking Severity for this repo — including turning it Off — in Settings. You can add or adjust custom eligibility rules. Learn more. |


What Changed
Claude Stop (
interruptTurn) no longer closes the provider query. It now:Query.stopTaskQuery.interrupt()and completes the local turnclose()only when live tasks remain (the fix(server): stop kills lingering Claude work #5891 runaway-fleet case)thread.session.stopand the 30-minute idle reaper still tear the process down.Why
#7338 reports ~2× Claude usage in T3 vs native Claude Code. After #5891, Esc killed the CLI. The next message
--resumes a new process.A cheap local check (Haiku,
--max-turns 1, promptreply with just the word ok, 5h usage 0% → 1%):--resume, git unchanged--resumeafter one untracked fileEach resume rewrote ~27k cache tokens even when git status did not change. On a 300k thread that is the cache-write spike reported in #7338. Native Claude Code keeps one process alive across Esc.
This does not claim to erase the whole gap. Claude effort/fast-mode changes still restart the session, idle reaping still stops it after 30 minutes, and app restart still
--resumes. Those are separate.Test plan
vp test run apps/server/src/provider/Layers/ClaudeAdapter.test.ts(81 passed)Made with Cursor
Note
Keep Claude CLI alive across Stop by interrupting turn and stopping live tasks
interruptTurninClaudeAdapterto cooperatively stop live subagent tasks viaquery.stopTaskand cancel the in-flight turn viaquery.interrupt, instead of unconditionally closing the CLI session.task.completedevents with status'stopped'for acknowledged task stops, and completes the open turn as'interrupted'.stopSessionInternal(closing the CLI) only when live tasks remain andstopTaskis unavailable or ineffective.ClaudeQueryRuntimeinterface to requireinterrupt()and optionally supportstopTask(taskId).ClaudeQueryRuntimemust now provideinterrupt(); without it, type checking and runtime calls will fail.📊 Macroscope summarized 4b1c76f. 2 files reviewed, 2 issues evaluated, 0 issues filtered, 2 comments posted
🗂️ Filtered Issues