Background sub-agents spawned by a subagent stay "Running" forever after the parent completes; TaskStop can't reach them
Summary
When a background agent (spawned from the main session via the Agent tool with run_in_background: true) itself spawns children with run_in_background: true and then ends its turn, the children finish their work but remain listed as "Running" in the Background tasks panel indefinitely. The main session cannot stop them — TaskStop with their agent IDs returns No task found (they are registered to the completed parent's context). The only way to remove them is the panel's per-row stop button or "Clear".
Environment
- Claude Code 2.1.170, macOS (Darwin 25.5.0), desktop app UI
- Model: claude-fable-5
Steps to reproduce
- From the main conversation, spawn an agent with
run_in_background: true. - That agent spawns two of its own children with
run_in_background: true, then ends its turn ("I'll wait for the two background subagents to finish") — i.e. it stops while its children are still alive. - The parent's task-notification fires in the main session; resume the parent via SendMessage; it verifies the children's output and completes normally.
- Watch the Background tasks panel.
Expected
Children of a completed subagent are reaped or re-parented once they finish; the panel reflects a terminal state; the main session can address them by ID.
Actual
- The children's transcripts (
subagents/agent-<id>.jsonl) stop growing — mtimes frozen at 18:35:46 and 18:37:14 — confirming their work finished. - The panel still showed both as "Running" 15+ minutes later, elapsed timers ticking (12m+), token counters frozen.
TaskStopfrom the main session with either child's agent ID →No task found with ID: <id>.- No programmatic way to clear them; they persist until manual panel stop/Clear.
Possibly related: #68992 (stale background-task bookkeeping for shell commands / stuck "running" badge). This report is specifically about nested Agent children orphaned by parent completion, which additionally breaks TaskStop addressing from the main session.
Showing cached comments. Read the full discussion on GitHub ↗
3 Comments
The orphaned-children problem points at a deeper lifecycle gap: once a subagent's own turn ends, its spawned children have no parent context to report back to, so the system has nowhere to route their completion signals. "TaskStop returns No task found" is the symptom - the underlying issue is that child-of-child agent IDs were registered under the intermediate parent's context, which is now closed.
The per-row stop button and Clear working as expected makes sense - those are UI-level operations that don't go through the same ID resolution path as TaskStop.
One pattern that sidesteps this for now: instead of letting the intermediate agent spawn its own background children, have the orchestrator (main session) spawn all background agents directly, and use SendMessage to coordinate handoffs between them. It's more verbose in the orchestration prompt but keeps all agent IDs under the main context where TaskStop can reach them.
Something like:
The tradeoff is you lose the convenience of having an intermediate agent manage its own sub-team. Would be good to see a supported re-parenting mechanism here - or at minimum a flag to register child agents under the top-level context regardless of which intermediate spawned them.
Confirming this on a second, independent trigger — not an explicit
run_in_background: trueorchestration prompt, but a general-purpose subagent (dispatched via a Skill-driven task: auditing ~60 files) that autonomously decided to parallelize by spawning 2 of its own children. Same symptom:<task-notification>.a1ea60339c3a2122d,a464c6b4cd9abee5a) kept showing "Running" in the panel for 1h15min+ after the parent had already returned, counters still ticking.TaskStop(task_id=<child>)→No task foundfor both, as reported here.TaskOutput(task_id=<child>, block=false)(the non-blocking, non-destructive status probe) returns the sameNo task found— so it's not thatTaskStopspecifically can't reach them, the entire ID is gone from whatever registry both tools query. Matches @kcarriedo's "registered under the intermediate parent's context, which is now closed" theory.+1 on a supported re-parenting mechanism, or at minimum registering child agent IDs under the top-level session context regardless of which intermediate spawned them.
Tried this on the released 2.1.233 (Linux CLI in tmux, nesting depth 3) following your recipe with three timings: children finishing before the parent completed, children outliving the parent's completion, and children left to finish on their own after the parent was done.
On 2.1.233 the reported behavior no longer occurs:
TaskStopfrom the main conversation with the grandchildren's IDs succeeded while they were still running ("Successfully stopped task: …"). Once they finish they leave the list, so a laterTaskStopcorrectly reports no such task.This was fixed in 2.1.203: "Fixed TaskStop and TaskOutput failing to find background agents spawned by another agent" (changelog). Heads-up: nested spawning was briefly off by default in 2.1.217 and is back on (depth 3) since 2.1.219.
Closing as fixed — if you still see stuck "Running" entries on 2.1.203 or later, reply here and we'll reopen.
🤖 Generated with Claude Code