[Bug] Sub-agent backgrounded processes orphaned/SIGHUP'd on turn-end; no auto-resume on background exit
Sub-agent backgrounded processes are orphaned/killed on turn-end; combined with the 10-min foreground Bash cap this makes >10-min jobs unrunnable from sub-agents
Summary
When a sub-agent (spawned via the Agent/Task tool) starts a long-running command with Bash(run_in_background: true) and then has no further foreground work, its turn ends and fires a "completed" notification while the backgrounded process is still running. The sub-agent is not automatically re-invoked when its own backgrounded child later exits — unlike the top-level session, which reliably gets re-invoked on background-process completion. As a result the process runs orphaned (its exit status/output is never observed by the agent that launched it), and in some cases the detached child is SIGHUP'd when the sub-agent's context is torn down, killing it outright.
Environment
- Claude Code CLI (background/headless session), model claude-opus-4-8
- macOS (darwin 25.5.0), zsh
- Orchestration pattern: a top-level "conductor" session delegating work to multiple sub-agents, each operating in its own git worktree
Why it bites (the compounding constraint)
The Bash tool hard-caps any foreground command at 10 minutes (600000 ms max timeout). Our pre-push git gate (Docker Playwright e2e + coverage) routinely runs longer than 10 minutes, so a foreground git push from a sub-agent is killed mid-gate. The natural workaround — run_in_background: true — hits the orphan/kill behavior above. Net effect: there is no reliable way for a sub-agent to run a single >10-minute job to completion and observe its result. The only reliable path is to run the long job from the top-level session, which defeats a delegation-based architecture.
Repro
- Top-level session spawns a sub-agent.
- Sub-agent runs
Bash(command: "<job that takes >10 min>", run_in_background: true). - Sub-agent has no more foreground work; its turn ends → "completed" notification fires with the job still running.
- Observe: the sub-agent is never re-invoked when the background job exits; its result is unobserved. On context teardown, the detached process may receive SIGHUP and die.
Expected
A sub-agent that launches a background process should be auto-resumed when that process exits (the same guarantee the top-level session has), and its backgrounded children should not be SIGHUP'd on turn-end / context compaction.
Actual
Sub-agent turn ends and is not re-woken on its background child's exit; the child is orphaned and its result unobserved; child may be terminated on teardown.
Impact
- Long-running gated pushes (>10 min) cannot be delegated to sub-agents — forces the orchestrator to run them itself, undermining a conductor/sub-agent split.
- Silent: the "completed" notification implies the delegated work is done when it is still running (or has since failed/been killed), which is easy to over-trust.
- In a parallel setup this also drives race conditions: agents unknowingly run heavy jobs concurrently because none can cleanly hold/observe a serialized long job.
Suggested fixes (any one helps)
- Give sub-agents the same auto-resume-on-background-exit behavior the top-level session has.
- Guarantee backgrounded children survive their launching sub-agent's turn-end and context teardown (don't SIGHUP them; reparent/detach cleanly).
- Raise or make configurable the 10-minute foreground Bash cap for long CI/gate commands, so backgrounding isn't required in the first place.
- At minimum: make the sub-agent "completed" notification distinguish "agent idle but has live background children" from "agent fully done," so the orchestrator doesn't over-trust a premature completion.
Environment Info
- Platform: darwin
- Terminal: xterm-256color
- Version: 2.1.206
- Feedback ID: abef374e-8cd3-4e23-aaae-407aa139d0eb
Errors
[]