[Bug]: Stop on a Claude thread kills its background agents, commands and delegated children, with no notice to the thread #46329
Before submitting#
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area#
apps/server
Steps to reproduce#
- Start a Claude thread.
- Ask it to start a background Bash command (
run_in_background) that runs for 4 minutes and then writes a file. - In the same turn, ask it to start a background agent with the Agent tool and
run_in_background. The agent works for 4 minutes and then writes a file. Adelegate_taskchild that does the same shows the cascade. - Let the turn end. The thread shows the work as pending.
- Press Stop, or send
thread.stop. - Wait 5 minutes.
I ran these steps with Stop sent while the thread was idle and waiting on the work. In real use I hit the same loss when I pressed Stop on a running turn. An earlier turn had started the background work.
Expected behavior#
Stop on a running turn ends that turn. Background work that earlier turns started keeps running, as it does when I press Esc in Claude Code's terminal.
If Stop has to end background work, any one of these would fix the loss:
- Interrupt a Claude turn without closing the query.
- Offer two Stop actions. "Stop this turn" keeps background work, and "Stop everything" ends it.
- At the least, post a message to the thread that names each task Stop ended.
Actual behavior#
Stop closes the whole Claude Code process. Every piece of background work the thread's session started ends in the same second:
- background Bash commands,
- background agents,
- commands those agents started,
delegate_taskchildren, whose results are thrown away.
The thread gets no message. It learns of the loss only on its next turn, from Claude Code's "didn't finish before the previous session ended" notice. In my case the Stop ended an agent before it committed its code changes, and it ended a long test run.
In the repro, none of the files appeared, and none of the processes survived 20 seconds past the Stop.
What I found in the bundled server code:
ClaudeAdapterV2.interruptTurncallsquery.interruptand then always callsquery.close.- The Claude runtime sets
backgroundTasksEndWithProcess: true, so every background task ends with the process. Orchestrator.dispatchThreadStopadds adelegated-tasks.stopeffect unless the command setsstopDelegatedTasks: false. The web Stop control never sets it.ThreadManagementService.stopDelegatedTasksthen sendsthread.stopto each active child.disposeDelegatedCompletionCohortdisposes the child's pending result, so nothing reaches the parent.
The idle release is not involved. ProviderSessionManager.releaseIfStillIdle put the release off for as long as the background work was live, with nothing registered through t3_background_wait.
Impact#
Major degradation or frequent failure
Version or commit#
0.1.12-nightly.20261124.5209
Environment#
macOS, T3 Code (Nightly) desktop app, Claude provider, Claude Opus 5.5 and Claude Haiku 4.5
Logs or stack traces#
# Real use: Stop pressed 5 seconds into a running turn. Times are seconds after the Stop.
+0.00 ws.rpc.orchestration.dispatchCommand command_type=thread.stop
+0.66 task_updated background agent status=killed
+0.66 task_updated background command status=killed
+0.66 outgoing query.interrupt
+0.71 outgoing query.close
+0.77 task_updated background command status=killed
+18.5 query.open resume: "didn't finish before the previous session ended"
# Repro with a delegate_task child: Stop sent to the idle parent.
+0.000 thread.stop thread=<parent>
+0.014 ThreadManagementService.stopDelegatedTasks
+0.018 thread.stop thread=<delegated child>
Workaround#
Send the next message without pressing Stop. The composer steers the running turn, and the background work survives.
tanstack-source added labelsbug
Sign in to join this conversation.