#8893: fix: enhance subagent error reporting with diagnostic context
gateway
commands
agents
stale
Cluster:
Subagent Enhancements and Features
## Problem
When a sub-agent fails, the parent agent only receives `{ status: 'error', error: 'message' }`. This minimal information makes it hard for the orchestrating agent to:
- Understand what went wrong
- Decide whether to retry
- Report meaningful status to the user
## Solution
Expand `SubagentRunOutcome` to include:
- `lastTool`: Which tool was executing when the failure occurred
- `completedSteps`: How many steps succeeded before the failure
- `partialProgress`: Any partial results before the error
Update the status label formatting to include this context in announcements.
## Example
Before:
```
failed: connection timeout
```
After:
```
failed: connection timeout (last tool: exec) (completed 3 steps before failure)
```
## Impact
- Better debugging for batch operations
- Orchestrating agent can make smarter retry decisions
- More informative error messages for users
Note: This is a forward-compatible change. The new fields are optional and existing code will continue to work.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR expands `SubagentRunOutcome` to optionally include richer diagnostics (`lastTool`, `completedSteps`, `partialProgress`) and updates the announce/status label formatting to surface that context in user-facing announcements.
The main integration point is the subagent registry’s lifecycle listener (`onAgentEvent`), which now reads these fields from error events and persists them into the run record so `runSubagentAnnounceFlow` can incorporate them into its status text.
<h3>Confidence Score: 3/5</h3>
- Mostly safe, but the new diagnostics won’t consistently propagate on the primary completion path.
- The change is small and localized, but `agent.wait`-based completion currently drops the new fields, meaning the intended behavior is only present for lifecycle-event errors. That inconsistency is likely to be noticed in production debugging and reduces confidence.
- src/agents/subagent-registry.ts and src/agents/subagent-announce.ts (agent.wait outcome construction)
<!-- greptile_other_comments_section -->
<sub>(5/5) You can turn off certain types of comments like style [here](https://app.greptile.com/review/github)!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#13990: feat: add subagent_progress tool for sub-agent progress reporting
by caprihan · 2026-02-11
82.4%
#8471: fix(subagent): add defensive checks for undefined string fields
by adam-smeth · 2026-02-04
80.7%
#13105: fix: debounce subagent lifecycle events to prevent premature announ...
by mcaxtr · 2026-02-10
79.5%
#23166: fix(agents): restore subagent announce chain from #22223
by tyler6204 · 2026-02-22
78.1%
#18205: fix (agents): add periodic retry timer for failed subagent announces
by MegaPhoenix92 · 2026-02-16
77.4%
#7584: Tests: align subagent announce wait expectations
by justinhuangcode · 2026-02-03
77.3%
#22719: fix(agents): make subagent announce timeout configurable (restore 6...
by Valadon · 2026-02-21
77.0%
#22407: fix: allow agent turn after subagent completion message delivery
by noodleprincss-ai · 2026-02-21
76.4%
#20328: fix(agents): Add retry with exponential backoff for subagent announ...
by tiny-ship-it · 2026-02-18
76.3%
#9049: fix: prevent subagent stuck loops and ensure user feedback
by maxtongwang · 2026-02-04
76.1%