cmux NEXT subagents: a completed turn ends its foreground subagents, so Running counts only live ones

Merged
TE
14d ago
+30-7

Leo's Inspector read "5 running · 3 failed · 89 done" while about 3 subagents were live (his screenshot from the "THIS BECAME A SIDEBAR FOR NO REASON" report; the panel itself is fixed in #24020).

Cause. The counts, the avatars and the rows all come from one source and agree. What was wrong is a foreground subagent whose end the harness never sent: it read running for good. subagentsLeft (subagents/subagentFold.ts) ended a turn's subagents only when the turn was cancelled or lost (outcome_unknown), never when it completed normally.

Fix. A turn_result with status: "completed" ends that turn's still-running foreground subagents as completed, so they count as done. A completed turn waited on them: Claude's foreground Agent call returns before the turn can end. Two cases are unchanged:

  • Background subagents run on. acpmux flags them background: true for run_in_background, workflows, and ones moved to the background (claude_stdio/inbound.rs).
  • A subagent that reports again reads running again.

Tests (red first). test/subagent-stopped-after-cancel.test.ts:

  • New: a foreground subagent whose turn completed reads completed, and a background one from the same turn still reads running. Red at d17b3aec.
  • Four existing cases used a foreground spawn to stand in for background work. They now spawn with the background flag, which is what acpmux sends.
  • The subagent, summary, inspector and background-task suites: 106 pass. The 1 failure, in summary-background-work.test.tsx ("the card lists running commands…"), fails the same way with base sources.

No capture: the Subagents count changes only for a subagent left running after its turn completed, and the tests above pin that.

🤖 Generated with Claude Code

Agent session: huge-blue


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.


Summary by cubic

Fixes the subagent Running count so a completed turn ends its foreground subagents, which the harness never reported as done.

  • A turn_result with status: "completed" now ends that turn's still-running foreground subagents as completed, so they no longer read running forever.
  • Background subagents still read running after a completed turn; their behavior is unchanged.
  • Updates tests that used foreground spawns as stand-ins for background work to use the background flag.