Fix the Supervisor That Dies With One Subagent
supervise(subtasks, run) hands each subtask to a subagent and collects the results. In production one subagent hit a bad input, and the report came back with the wrong number of results, the failure in the wrong place, and three attempts billed for a task that could never succeed. Fix it.
run(subtask) is the subagent. It returns a result, or raises TransientError (a flaky tool, worth one more try) or something else (a BadTask, a bug: not worth retrying).
- Results come back in subtask order, one slot per subtask,
Nonewhere it failed. - A
TransientErroris retried once, so at most two attempts. Any other exception is not retried at all. - Every failure is recorded in
failedas{"subtask": ..., "error": "ClassName: message"}, in order, with the last error seen. attemptscounts every call torun.supervisenever raises because a subagent did. The rest of the swarm's work still comes back.
Return {"results": [...], "failed": [...], "attempts": n}.
Three things are wrong with the current version. Run the tests and read the shape of what comes back before you change anything: the length of results is the first clue.