Description
When a parent session is aborted (e.g., due to timeout, user cancellation, or runtime error), its sub-agent sessions are not automatically cleaned up. The orphaned sub-sessions remain in tool-calls state, consuming resources indefinitely.
Steps to reproduce
- Start an agent session that dispatches sub-agents via
task(subagent_type="...")
- Allow one or more sub-agents to get stuck (e.g., infinite explore loop)
- Abort the parent session
- Observe that child sub-agent sessions remain in
tool-calls state indefinitely
Evidence
From a production opencode deployment:
-
4 orphan sub-sessions currently stuck in tool-calls state with terminated parents:
ses_09e82cb4 (explore sub-agent) — parent task-executor completed days ago
ses_0c77d7ac (explore sub-agent) — parent fusion-deep-research completed
ses_0ddbf20a (critical-thinking sub-agent) — parent fusion-deep-research completed
ses_117c5c57 (critical-thinking sub-agent) — parent session completed
-
5 mass-abort events where 3+ sub-agents were aborted together because their parent was aborted — but the cleanup was a batch abort, not a graceful shutdown:
ses_10049ce8: 4 children aborted together (3 pm-coordinator + 1 explore)
ses_0c781f98: 3 children aborted together (pm-coordinator + dify-kb-manager + communication-drafter)
ses_0d4228cd: 3 children aborted together
ses_0dab015c2: 3 explore children aborted together
ses_11846e3e: 3 children aborted together
Expected behavior
- Cascading abort: When a parent session is terminated, automatically abort all active child sub-sessions.
- Orphan detection: Periodic cleanup of sub-sessions whose parent session no longer exists or has been terminated.
- Graceful shutdown signal: When aborting, send a cancellation signal to sub-agents first, wait briefly for them to save state, then force-terminate.
Impact
- Prevents resource leaks from orphaned sub-sessions
- Avoids confusion when checking session status and finding "running" sessions with dead parents
Description
When a parent session is aborted (e.g., due to timeout, user cancellation, or runtime error), its sub-agent sessions are not automatically cleaned up. The orphaned sub-sessions remain in
tool-callsstate, consuming resources indefinitely.Steps to reproduce
task(subagent_type="...")tool-callsstate indefinitelyEvidence
From a production opencode deployment:
4 orphan sub-sessions currently stuck in
tool-callsstate with terminated parents:ses_09e82cb4(explore sub-agent) — parenttask-executorcompleted days agoses_0c77d7ac(explore sub-agent) — parentfusion-deep-researchcompletedses_0ddbf20a(critical-thinking sub-agent) — parentfusion-deep-researchcompletedses_117c5c57(critical-thinking sub-agent) — parent session completed5 mass-abort events where 3+ sub-agents were aborted together because their parent was aborted — but the cleanup was a batch abort, not a graceful shutdown:
ses_10049ce8: 4 children aborted together (3 pm-coordinator + 1 explore)ses_0c781f98: 3 children aborted together (pm-coordinator + dify-kb-manager + communication-drafter)ses_0d4228cd: 3 children aborted togetherses_0dab015c2: 3 explore children aborted togetherses_11846e3e: 3 children aborted togetherExpected behavior
Impact