Skip to main content

When a Subagent Fails

Why This Matters

In a team of four, something will go wrong: a timeout, an invalid result, a subagent that keeps calling tools without ever finishing. The question is not whether, but whether the run degrades gracefully or collapses.

Kinds of failure

FailureExampleHandling
No answerTimeout, API error after retriesMark as not triaged, with the reason
Invalid answerResult does not match the schemaOne retry with feedback, then not triaged
Never finishesStep limit reachedStop, mark as not triaged, keep the tool log
Tool downLog service unavailableSpecialist continues with what it has and says so in openQuestions

Retry once, with feedback

The same pattern as lessons 10 and 38: one retry that tells the subagent what was wrong. Then stop. Infinite retries cost money and hide problems.

Partial results are still results

run-1099: 40 failures
  37 triaged
   3 not triaged
     t-031 root-cause investigator timed out twice
     t-032 invalid result twice (missing evidence)
     t-040 step limit reached (8 tool calls)

That report is useful at 08:45 on a Monday. A crashed job is not.

Never turn a failure into “unknown”

It is tempting to mark failed investigations as unknown. Do not. “Unknown” means we looked and the evidence is unclear. “Not triaged” means we could not look. A tester treats them very differently, so the report must too. Keep a separate status for it, outside the category list.

Test it with scripted subagents

Like lesson 29, script the subagents’ responses:

  • one specialist returns invalid results twice → not triaged, others unaffected
  • one specialist never finishes → step limit hit, run continues
  • the log tool is down → findings mention it in openQuestions

These tests prove the team degrades the way you designed, without a single real API call.

What the first real run found

The first run of npm run team on run-1099 with solution/lesson-40-triage-team:

npm run team on run-1099: 40 failures in 7 groups and 8 investigations in 30 seconds; two environment groups, one product bug found down to the line, a test bug, an unknown, one disputed group, and two bug proposals for the same root cause

Most of it is exactly what a tester wants at 08:45:

  • 40 failures, 7 groups, 8 investigations, 30 seconds. Grouping in code did most of the work before any model ran.
  • 27 failures explained by two infrastructure problems, each with its evidence: a search latency spike and the payment sandbox running out of memory.
  • The product bug found down to the line: the controller calls pricing.recalculate(cart) and throws away the result.
  • t-040 honestly unknown (0.20): no log, no history, nothing in the commit.

And it found two flaws in the team’s design, both of which are now fixed on the branch, with tests:

  1. Two bug proposals for one bug. Groups g3 and g4 have different error messages, so code split them, but they share one root cause. Grouping by symptom is right for planning investigations; it is not enough for deciding tickets. Fix: the bug writer now runs one group at a time and sees the proposals already drafted in this run, so the second group points to the first proposal instead of drafting a duplicate.
  2. A dispute that was not one. On t-039 the flaky analyst said flaky and the investigator test_bug, while its own summary says “looks like a flaky test”. Both labels mean the same action: fix the test’s waiting. The rule from this lesson’s own “When to ask a human” section says to escalate when the verdicts lead to different actions. The code escalated on any difference. Fix: disputes now require different actions; agreeing actions keep both labels in the summary.

The second run, after both fixes:

npm run team on run-1099 after the fixes: 40 of 40 triaged, one bug proposal with group g4 marked as the same root cause, and t-039 reported as flaky with both specialists’ labels and the shared action

One proposal instead of two (g4: same root cause as proposal-t-029), and t-039 triaged as flaky with both labels kept: both mean: fix the test. Nothing was hidden; the report just stopped asking a human to decide something that needed no decision.

Both flaws only showed up with a real model on a realistic run. The scripted tests prove the team does what you designed; a real run shows whether the design was right.

Exercise

Implement the “not triaged” status in the report and the three scripted tests above.

Compare with solution/lesson-40-triage-team, which covers lessons 34–40 (see docs/exercises.md, module 5).