Skip to content

Remove finished and killed claude subagents from the sidebar roster - #8522

Merged
brennanb2025 merged 3 commits into
mainfrom
brennanb2025/claude-code-subagent-lifecycle
Jul 13, 2026
Merged

brennanb2025 merged 3 commits into
mainfrom
brennanb2025/claude-code-subagent-lifecycle

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Fixes the two reported Claude subagent sidebar symptoms: finished workflow/ultracode subagents piling up as permanent Idle - general-purpose child rows, and killed subagents that never disappear (and pin the pane working forever).

Root cause

Roster entries had no exit path while a session stayed busy. SubagentStop only marked an entry idle, and the only cleanup was a lead Stop with a fully empty background_tasks — exactly what ultracode (live workflow tasks) and teams sessions (teammates always listed) never send. A child killed without its SubagentStop (interrupt race, lost hook, SIGKILL'd tree) additionally stayed working forever, which both pinned the pane working via the done-gate and blocked the server's interrupt inference.

Fix (grounded in live hook captures from claude CLI)

Empirical ground truth captured with logging hooks: one-shot Task agent ids are a+16-hex (no hyphen) while teammate ids embed their name (a<name>-<hex> with agent_type = name); SubagentStop also fires for interrupt-aborted children; a lead Stop's background_tasks lists running subagents id-exact and drops finished tasks entirely.

  • SubagentStop now removes one-shot entries. Teammates (identified by the name-embedding id) only go idle — they're alive and resumable, and SubagentStop fires per finished task for them.
  • The fold treats a present background_tasks list as authoritative for non-teammates: id-matched not-running entries and unlisted entries are removed (this reaps killed children whose SubagentStop was lost). Teammates are exempt (their task ids never match lifecycle ids); snapshot-seeded teammate phantoms still demote to idle so they can't gate the pane.
  • Hydration seeding re-derives the teammate flag from the persisted id/agentType, so restart keeps teammate idle rows while stale one-shot seeds get reaped at the next Stop.

Verification

Reproduced live in a dev instance (real claude session in an Orca terminal + a deterministic replay of the exact ultracode/teams hook traffic against the dev hook server), then re-ran the identical traffic on the fixed build.

Before: real claude — finished batches squat as Idle rows while batch 3 runs Before: killed agent (Working, no SubagentStop) + 6 squatters + teammate
before-pile before-phantom
Before: 3 min later, terminal is an empty shell — rows still there, pane pinned working After: identical traffic mid-replay — all rows genuinely working, no squatters
before-persist after-mid
After: same traffic settled — only the genuinely-running agent + the idle (resumable) teammate remain; the killed agent was reaped at the lead Stop
after-final

An organic re-run (real claude spawning 6 subagents in batches) showed idle-row count staying 0 for the whole session (pre-fix it climbed with every finished batch), resolving to done cleanly.

Tests: roster + listener suites updated to the new semantics plus a regression spec (claude-subagent-row-lifecycle.test.ts); src/shared (2363), src/main/agent-hooks + src/relay (1131) all green; typecheck + oxlint clean. The 10 sidebar/dashboard renderer test failures are pre-existing on main (fail with this diff stashed; Linear-toast/board-hint files, unrelated).

Known residual gaps (follow-ups, out of scope)

  • A pane whose PTY teardown skips clearPaneState (stillOwnsPaneKey === false — remount/SSH-reattach races) or a dead pane rehydrated with its tab restored can still render frozen child rows until eviction (src/main/ipc/pty.ts:1168, server.ts:1603).
  • An agent that dies inside a surviving shell is never retired by design (pty-connection.ts:2981); with this fix its last snapshot at least no longer contains finished-agent squatters.
  • Older Claude builds without background_tasks keep the previous conservative behavior (no reaping by omission).

Finished one-shot subagents stayed in the pane roster as permanent idle
rows (dozens per ultracode/workflow session), and a subagent killed
without its SubagentStop hook stayed 'working' forever, pinning the pane
working. SubagentStop now removes one-shot entries (teammates only idle:
they are alive and resumable), and a lead Stop's present background_tasks
list is treated as authoritative for non-teammates - unlisted entries are
removed. Teammates are identified by their name-embedding agent ids
(a<name>-<hex>, verified against live hook captures).
@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 0c2814c5-7e62-4420-92d3-868a42e19dac

📥 Commits

Reviewing files that changed from the base of the PR and between 025eba6 and 2b0484b.

📒 Files selected for processing (4)
  • src/shared/agent-hook-listener.ts
  • src/shared/claude-subagent-roster.test.ts
  • src/shared/claude-subagent-roster.ts
  • src/shared/claude-subagent-row-lifecycle.test.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/shared/claude-subagent-row-lifecycle.test.ts
  • src/shared/agent-hook-listener.ts
  • src/shared/claude-subagent-roster.ts
  • src/shared/claude-subagent-roster.test.ts

📝 Walkthrough

Walkthrough

Claude subagent roster handling now distinguishes teammates from one-shot subagents. Finished one-shots are removed, while teammates transition to idle and can persist through background-task omissions. Snapshot hydration re-derives teammate status, truncated inventories preserve live children, and lifecycle handling uses the new finalization helper. Tests cover roster reconciliation, teammate identity mapping, killed or interrupted subagents, and resulting sidebar payloads.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: removing finished and killed Claude subagents from the sidebar roster.
Description check ✅ Passed The description is directly related to the change set and explains the bug, fix, and verification in the PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Warning

Tools execution failed with the following error:

Failed to run tools: 13 INTERNAL: Received RST_STREAM with code 2 (Internal server error)


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Workflow/named one-shot agents report name-embedding lifecycle ids
(afinder-C-<hex>, agent_type = the label), indistinguishable by shape
from resumable teammates - so the roster retained them as idle rows
(observed live: a 32-row 12h-old pile). Unlike teammates they ARE
listed id-exact as subagent-typed background tasks, including inside
their own SubagentStop payload. Use that corroboration to remove them
on stop, reclassify task-listed teammate-shaped entries as one-shots,
and reap teammate-shaped leftovers when a complete inventory lists no
teammate-typed task at all (a teams session always lists its teammates,
even idle ones).
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Addendum: named workflow lanes (second commit)

A second real-world variant surfaced after the initial fix: a 12h-old pile of 32 idle rows (Idle - finder-C, Idle - v1-streaming, Idle - fix-parsers, …) in a native-chat workspace. The persisted snapshot shows these are named workflow lanes whose ids embed their label:

afinder-C-5d713c0781b7f8d2      agent_type: finder-C
acr-triage-1-c5a0588e7a2e4151   agent_type: cr-triage-1

That's the same id shape as resumable teams teammates (a<name>-<hex>), so the roster's teammate exemption retained them as idle rows forever.

Live hook captures show the reliable discriminator: one-shots (named or not) are listed id-exact as type:"subagent" background tasks — including inside their own SubagentStop payload — while real teammate lifecycle ids never appear as task ids. The amendment uses that:

  • SubagentStop removes a teammate-shaped entry when its own payload lists the id as a subagent task.
  • The fold reclassifies task-listed teammate-shaped entries as one-shots, and reaps teammate-shaped leftovers (killed lanes) when a complete inventory lists no teammate-typed task at all — a teams session always lists its teammates, even idle ones.

Regression tests encode the exact observed shape. Existing stale piles clear at the first turn-end Stop after updating. Remaining edge: a killed named lane inside a session that also runs live teammates is retained until the teammates go away — acceptable and rare.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Live verification of the named-lane amendment (pre/post, identical hook traffic)

Replayed the exact fleet shape from the reported workspace (afinder-C-<hex>-style ids, one lane killed with its SubagentStop never delivered, one lane still running) against a dev instance — first at 025eba666 (pre-amendment), then at HEAD, same script, same pane.

025eba666 — 6 finished lanes squat as Idle, killed v2-sanitize stuck Working (pane pinned) HEAD — identical traffic: only the genuinely-running fix-main remains
before after

Also verified the migration story for existing piles: booting the fixed build on the pre-fix profile hydrated all 8 stale rows from last-status.json (pane pinned working), and the first lead Stop with a present inventory reaped every one of them. Draining the last lane resolved the pane to done with zero rows.

@brennanb2025
brennanb2025 merged commit fc458f2 into main Jul 13, 2026
1 check passed
brennanb2025 added a commit that referenced this pull request Jul 15, 2026
…he sidebar roster (#8825)

* fix(agent-status): reap finished Claude named agents/teammates from the sidebar roster

#8522 stopped one-shot subagents from squatting as idle rows, but named
background agents (Workflow/orchestration/ultracode lanes and agent-teams
teammates) still piled up permanent "Idle - <type>" child rows for the rest
of the session — the reported regression (11 idle rows under an
"Orchestration Messages" pane, all idle 3-6h after finishing).

Root cause, confirmed against live hook captures (claude 2.1.210): named
agents get teammate-shaped ids (a<name>-<hex>) AND now appear in Stop's
`background_tasks` as `type: "teammate"` entries whose status stays "running"
forever — even after the agent finished. The old code read that shape as a
"resumable teammate", so SubagentStop only marked it idle and the fold never
reaped it (a present teammate task kept hasTeammateTypedTask true). The rows
never left.

Fix: the roster now tracks only WORKING children.
- SubagentStop removes the child outright (teammate-shaped or not) — it is
  the reliable finish signal; the teammate task's "running" status is not.
- TeammateIdle removes by name as the fallback when a SubagentStop is lost.
- A lead Stop's background_tasks still reaps unlisted children: hyphen-free
  one-shots always, and teammate-shaped rows once a complete inventory shows
  no teammate-typed task at all. A live named agent whose id never appears is
  kept only while a teammate-typed task is still present (the done-gate).
- Hydration drops persisted idle snapshots so a restart can't re-pile them.

Verified live in a dev Electron instance driving a real Claude TUI that spawns
four named background agents: pre-fix the pane resolves to done with four
persistent "Idle - <probe>" rows; post-fix each row disappears the instant its
agent finishes and the roster drains to empty (done, zero child rows).

Tests: roster + row-lifecycle + hook-listener suites rewritten to the
working-only semantics, grounded in the captured 2.1.210 hook stream
(126 passing). Typecheck + oxlint clean.

* fix(agent-status): prune persisted idle Claude children

* fix(agent-status): persist Claude idle-row hydration cleanup

* fix(agent-status): avoid ambiguous teammate idle cleanup

* fix(agent-status): reconcile replacement children at roster cap
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…tablyai#8522)

* Remove finished and killed claude subagents from the sidebar roster

Finished one-shot subagents stayed in the pane roster as permanent idle
rows (dozens per ultracode/workflow session), and a subagent killed
without its SubagentStop hook stayed 'working' forever, pinning the pane
working. SubagentStop now removes one-shot entries (teammates only idle:
they are alive and resumable), and a lead Stop's present background_tasks
list is treated as authoritative for non-teammates - unlisted entries are
removed. Teammates are identified by their name-embedding agent ids
(a<name>-<hex>, verified against live hook captures).

* Fix Claude subagent roster reconciliation

* Drop named workflow lanes that share the teammate id shape

Workflow/named one-shot agents report name-embedding lifecycle ids
(afinder-C-<hex>, agent_type = the label), indistinguishable by shape
from resumable teammates - so the roster retained them as idle rows
(observed live: a 32-row 12h-old pile). Unlike teammates they ARE
listed id-exact as subagent-typed background tasks, including inside
their own SubagentStop payload. Use that corroboration to remove them
on stop, reclassify task-listed teammate-shaped entries as one-shots,
and reap teammate-shaped leftovers when a complete inventory lists no
teammate-typed task at all (a teams session always lists its teammates,
even idle ones).
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…he sidebar roster (stablyai#8825)

* fix(agent-status): reap finished Claude named agents/teammates from the sidebar roster

stablyai#8522 stopped one-shot subagents from squatting as idle rows, but named
background agents (Workflow/orchestration/ultracode lanes and agent-teams
teammates) still piled up permanent "Idle - <type>" child rows for the rest
of the session — the reported regression (11 idle rows under an
"Orchestration Messages" pane, all idle 3-6h after finishing).

Root cause, confirmed against live hook captures (claude 2.1.210): named
agents get teammate-shaped ids (a<name>-<hex>) AND now appear in Stop's
`background_tasks` as `type: "teammate"` entries whose status stays "running"
forever — even after the agent finished. The old code read that shape as a
"resumable teammate", so SubagentStop only marked it idle and the fold never
reaped it (a present teammate task kept hasTeammateTypedTask true). The rows
never left.

Fix: the roster now tracks only WORKING children.
- SubagentStop removes the child outright (teammate-shaped or not) — it is
  the reliable finish signal; the teammate task's "running" status is not.
- TeammateIdle removes by name as the fallback when a SubagentStop is lost.
- A lead Stop's background_tasks still reaps unlisted children: hyphen-free
  one-shots always, and teammate-shaped rows once a complete inventory shows
  no teammate-typed task at all. A live named agent whose id never appears is
  kept only while a teammate-typed task is still present (the done-gate).
- Hydration drops persisted idle snapshots so a restart can't re-pile them.

Verified live in a dev Electron instance driving a real Claude TUI that spawns
four named background agents: pre-fix the pane resolves to done with four
persistent "Idle - <probe>" rows; post-fix each row disappears the instant its
agent finishes and the roster drains to empty (done, zero child rows).

Tests: roster + row-lifecycle + hook-listener suites rewritten to the
working-only semantics, grounded in the captured 2.1.210 hook stream
(126 passing). Typecheck + oxlint clean.

* fix(agent-status): prune persisted idle Claude children

* fix(agent-status): persist Claude idle-row hydration cleanup

* fix(agent-status): avoid ambiguous teammate idle cleanup

* fix(agent-status): reconcile replacement children at roster cap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant