Summary
The current 3-attempt self-correction cap for failing tests is arbitrary and doesn't distinguish between fixable bugs and architectural issues requiring plan revision.
Problem Analysis
Current behavior: When tests fail, agents retry up to 3 times before... (what? failing the task? escalating?).
This is problematic because:
-
Not all failures are equal: A typo causing a test failure needs 1 retry. An architectural mismatch needs 0 retries and plan revision instead.
-
Retrying the same approach rarely works: If the approach is fundamentally wrong, 3 attempts of the same strategy waste tokens and time.
-
No escalation path: After 3 failures, what happens? If the task just fails, we've learned nothing. If it continues anyway, we ship broken code.
-
Missing: "stop and think" mode: The Deep Agents pattern emphasizes that agents should recognize when they're stuck and revise their plan, not just retry.
State of the Art Comparison
From Philipp Schmid's Agents 2.0:
"No Recovery mechanism: If it goes down a rabbit hole, it rarely has the foresight to stop, backtrack, and try a new approach."
The fix isn't more retries—it's plan revision when retries aren't working.
12-Factor Agents:
"Embrace Errors: Keep error messages in the context."
Errors should inform strategy changes, not just trigger identical retries.
Proposed Improvement
Replace fixed retry count with adaptive failure handling:
Failure Type Detection → Strategy Selection → Escalation Path
Failure Classification
| Failure Type |
Signal |
Action |
| Trivial |
Single assertion, clear error message |
Retry (max 2) |
| Moderate |
Multiple failures, related to recent change |
Analyze, then retry with adjustment |
| Architectural |
Systemic failures, interface mismatch |
Create blocker, request plan revision |
| External |
Network, API, dependency issues |
Wait and retry with backoff |
| Unknown |
Unclear failure mode |
Create blocker for human review |
Implementation Approach
-
Failure analyzer: Before retrying, classify the failure type
- Parse test output for patterns
- Compare to previous attempt (same error = not fixable by retry)
- Check if failure is in code agent just modified vs. elsewhere
-
Strategy selector:
if failure_type == "trivial" and attempt < 2:
return RetryStrategy(same_approach=True)
elif failure_type == "moderate":
return RetryStrategy(analyze_first=True, max_attempts=2)
elif failure_type == "architectural":
return EscalateStrategy(create_blocker=True, reason="architectural_mismatch")
elif consecutive_same_errors >= 2:
return EscalateStrategy(create_blocker=True, reason="stuck_in_loop")
-
Escalation to plan revision:
- Create async blocker: "Test failures suggest approach X won't work. Options: A, B, C. Human guidance requested."
- Or: Escalate to Lead Agent for task re-decomposition
-
Learning from failures:
- When human resolves blocker, record the pattern
- Build procedural memory: "When you see error type X in this codebase, approach Y works"
Success Criteria
Metrics to Track
- Retry efficiency: % of retries that succeed vs. fail again with same error
- Escalation rate: % of failures that become blockers
- Blocker resolution time: How long until human input resolves architectural issues
- Token waste: Tokens spent on retries that didn't help
References
Summary
The current 3-attempt self-correction cap for failing tests is arbitrary and doesn't distinguish between fixable bugs and architectural issues requiring plan revision.
Problem Analysis
Current behavior: When tests fail, agents retry up to 3 times before... (what? failing the task? escalating?).
This is problematic because:
Not all failures are equal: A typo causing a test failure needs 1 retry. An architectural mismatch needs 0 retries and plan revision instead.
Retrying the same approach rarely works: If the approach is fundamentally wrong, 3 attempts of the same strategy waste tokens and time.
No escalation path: After 3 failures, what happens? If the task just fails, we've learned nothing. If it continues anyway, we ship broken code.
Missing: "stop and think" mode: The Deep Agents pattern emphasizes that agents should recognize when they're stuck and revise their plan, not just retry.
State of the Art Comparison
From Philipp Schmid's Agents 2.0:
The fix isn't more retries—it's plan revision when retries aren't working.
12-Factor Agents:
Errors should inform strategy changes, not just trigger identical retries.
Proposed Improvement
Replace fixed retry count with adaptive failure handling:
Failure Classification
Implementation Approach
Failure analyzer: Before retrying, classify the failure type
Strategy selector:
Escalation to plan revision:
Learning from failures:
Success Criteria
Metrics to Track
References