You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: orphan sub-sessions not cleaned up when parent aborts #37314
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
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
#45482 addresses this. Cleanup currently works from one stale snapshot and skips an intermediate task that already finished, so work beneath it survives. The PR stops the session in view plus its provable running descendants.
Partly done: interrupting a parent now stops its foreground subagent too (since #34320, packages/core/src/tool/plugin/subagent.ts). Background subagents are detached and keep running after the parent is interrupted, and there's no orphan cleanup; #45482 was closed unmerged. Closing this tracker.
Activity
github-actions commentedon Jul 16, 2026
Thanks for updating the issue! It now includes a clear description, reproduction steps, and supporting evidence. Everything looks good.
goleary commentedon Jul 22, 2026
running into this too
NamedIdentity commentedon Aug 27, 2026
#45482 addresses this. Cleanup currently works from one stale snapshot and skips an intermediate task that already finished, so work beneath it survives. The PR stops the session in view plus its provable running descendants.
neriousy commentedon Oct 22, 2026
Partly done: interrupting a parent now stops its foreground subagent too (since #34320, packages/core/src/tool/plugin/subagent.ts). Background subagents are detached and keep running after the parent is interrupted, and there's no orphan cleanup; #45482 was closed unmerged. Closing this tracker.