Skip to content

fix(spool): classify detached lanes waiting on their own background subagent as failed - #1149

Merged
agents-squads[bot] merged 1 commit into
developfrom
fix/1130-subagent-wait-classing
Jul 17, 2026
Merged

fix(spool): classify detached lanes waiting on their own background subagent as failed#1149
agents-squads[bot] merged 1 commit into
developfrom
fix/1130-subagent-wait-classing

Conversation

@agents-squads

@agents-squads agents-squads Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Closes #1130.

A detached lane's terminal result event can report a clean, non-error
success while the lane's own last turn was still waiting on a background
Task/Agent subagent it spawned and never got a result back from ("I'll pause
here until it completes"). In a detached lane there is no next turn to
resume that wait — the run gets recorded as a zero-deliverable "completed"
forever (repro'd twice on 2026-07-14/15, see issue).

This is a distinct terminal-state class from #1123's deliver-and-stop CI
gate (which verifies CI on a PR the lane already believes it produced) —
here the lane never produced anything to gate.

Fix, built on the same seam #1131 added for "claude's own terminal
state can lie":

  • stream-json.ts now correlates Agent/Task tool_use ids against later
    tool_result blocks (the same shape exec-events.ts already uses for the
    obs events file) and exposes the count left unresolved by the time the
    stream ends as openBackgroundSubagents.
  • spool.ts's reconcile (toRecord) adds a third branch to the existing
    #1131 reclassification chain: a sawResult && !isError run is
    reclassified to failed when openBackgroundSubagents > 0 and the
    run produced zero commits/PRs/issues. A subagent that resolved before the
    stream ended, or a run that still delivered a commit/PR/issue despite a
    dangling background task, are both left completed.

Structural, not text-matching — the issue's own follow-up comment notes a
second occurrence phrased the "waiting" differently ("waiting for the
automatic notification" vs. "I'll pause here"), so regexing the model's
free-form text would just chase rewordings. Whether a synchronous subagent
call resolved before the parent turn ended is a hard fact of the stream.

Test plan

  • npm run typecheck — pass
  • npm run build — pass
  • npm test — 2365/2365 pass (145 files), including new cases:
    • test/stream-json-parser.test.ts: open/resolved/ignored subagent tool_use tracking
    • test/spool.test.ts: the exact repro (clean result + hanging subagent + zero deliverable → failed), resolved-subagent stays completed, delivered-PR-with-dangling-subagent stays completed, legacy plain-text logs untouched
  • npm run lint — 0 errors (pre-existing warnings only, unrelated to this change)

…kground subagent as failed (#1130)

A detached run's terminal `result` event can report a clean, non-error
success while the lane's last turn was still waiting on a background
Task/Agent subagent it spawned and never got a result back from — in a
detached lane there is no next turn to resume that wait, so the run is
recorded as a zero-deliverable "completed" forever.

`stream-json.ts` now correlates Agent/Task tool_use ids against later
tool_result blocks (same shape exec-events.ts already uses for the obs
events file) and exposes the count left unresolved by stream end.
`spool.ts`'s reconcile — extended for the sibling "claude's own terminal
state can lie" case in #1131 — now also reclassifies to failed when that
count is nonzero AND the run produced no commit/PR/issue, without relying
on matching the model's free-form "I'll pause here" phrasing.

Closes #1130
@agents-squads
agents-squads Bot requested a review from kokevidaurre as a code owner July 17, 2026 01:44
@agents-squads
agents-squads Bot enabled auto-merge (squash) July 17, 2026 01:44
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 96.29630% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/lib/stream-json.ts 95.45% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant