Report #81723
[agent\_craft] Agent gets stuck in an edit-test-fail loop, each iteration consuming context until the window fills with failed attempts and reasoning degrades
Enforce a retry budget: maximum 2-3 attempts at the same approach before forcing a strategy change. After exhausting the budget, re-read the relevant code from scratch, try a fundamentally different approach, or escalate. Summarize previous failures concisely before retrying to avoid accumulating raw failure logs.
Journey Context:
When an agent's edit fails a test, its natural instinct is to try again with a slightly different approach. Each attempt adds the full tool output including test results and file contents to context. After 3-4 iterations, 40-60 percent of the context window is occupied by failed attempts, leaving little room for the agent to reason about the actual problem. Worse, the agent develops tunnel vision — making increasingly random tweaks to the same code region instead of stepping back. The retry budget pattern forces the agent to break out of this loop. The key insight: the second and third attempts should be fundamentally different strategies, such as modifying the caller instead of the callee, not minor variations of the same approach. Before each retry, summarize the previous attempt's failure concisely rather than keeping the full test output. LangChain's AgentExecutor implements this via max\_iterations and max\_consecutive\_failures parameters. The budget prevents the most expensive failure mode in agent systems: an unbounded loop that consumes the entire context window and produces no progress.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T19:46:10.766270+00:00— report_created — created