Agent Failure Recovery Across Harnesses
Your support-triage agent has been calling the same Jira endpoint for eleven minutes. It gets a 502, re-plans, calls again with a slightly different payload, gets the same 502, and starts over. The token meter climbs, the ticket sits untouched, and the trace shows no branch that ends this.
The harness should have caught it. Whether it did depends on which harness you are running, and the answer differs enough between Devin, Claude Code, and Cursor that a recovery pattern lifted from one will quietly fail in another. This post maps the four recovery seams in a modern agent harness, shows which of them each product actually implements, and gives you the spec for the part none of them finishes for you: the retry budget and the escalation trigger.
Key Takeaways:
- Recovery is a property of the runtime layer around the model, not of the model, so the place to look when an agent loops is the harness seam, not the prompt.
- Devin keeps state in a frozen VM snapshot plus a blueprint, Claude Code keeps noise out of the main window with sub-agents, and Cursor exposes hooks at loop stages. Three harnesses, three different seams.
- Anthropic measured multi-agent systems at about 15x the tokens of a chat interaction, so an uncapped retry loop multiplies a design that is already expensive.
- Cursor’s own documented hook example retries when the agent fails twice in a row. That is a pattern to copy, and it is not a default that protects your bill.
- The per-tool retry ceiling, the session tool-call cap, and the escalation trigger are yours to write in all three harnesses.
Where Recovery Actually Lives in a Harness
A harness is the runtime orchestration layer that wraps the reasoning loop and coordinates tool execution, context, state, and stopping rules. That definition comes from a 2026 analysis of terminal coding agents (arXiv:2603.05344), and a separate survey decomposes the same layer into six runtime responsibilities: observation, context, control, action, state, and verification or governance (arXiv:2606.20683). Retries live in control. Resume-after-failure lives in state. “It edited the test to make it pass” is a governance failure wearing a tool error’s clothes.

Product teams converged on the same shape independently. Cursor, Claude Code, Windsurf, and Codex all landed on “a while loop that calls tools, a context manager that compresses history, a permission layer that keeps things safe,” as Arize’s Laurie Voss put it in a June 2026 writeup on why harnesses replaced frameworks. When you stare at the Jira loop, you are inspecting one of four seams inside that loop:
- Retry policy: how many times, with what backoff, on which error classes.
- Fallback routing: a different tool, a narrower query, a different model.
- Checkpoint or state restore: roll the workspace back and continue from known state.
- Human escalation: stop spending and hand the trace to a person.
Here is where each harness puts its weight. Read the third column as the mechanism you can inspect today, and the fourth as the work that lands on your desk either way.
None of those cells says “stops after N failed calls on one tool.” That gap is the subject of the rest of this post. For a wider taxonomy of how these topologies relate, our earlier walk through multi-agent coordination architectures covers the orchestrator, peer-network, and supervisor shapes.
Devin: Snapshot as the Unit of State
Devin reaches users through four surfaces (cloud sessions, the CLI, the desktop editor that used to be Windsurf, and a fleet API) but runs on only two loops. The CLI and Devin Local share a local loop that looks like other coding harnesses: files on disk, a permission system, sub-agents. Cloud sessions boot a virtual machine from a snapshot built before the session exists, and the docs describe that image as a frozen, bootable copy of your repositories, runtimes, and dependencies.
That design answers a question the Jira trace cannot: what state are we in when the tool keeps failing? Devin’s answer is the machine. The transcript matters within one session, but across sessions the durable object is the image, and the recipe for the image is a YAML file you can review and commit as .devin/blueprint.yaml. Inside it, initialize holds runtimes and system packages, maintenance runs on every build, and knowledge never executes: it is read when Devin checks its own work, which is how the harness gets told which command tests a single file and where build output lands.
The seam between loops is one command. /handoff starts a cloud session that continues local work, carrying the repo, branch, conversation context, and uncommitted changes. It runs backward too, fetching the pull request branch into a local session. The practical cost sits in that carry list: your exported shell variables and your local node_modules do not cross, so a task that worked on your laptop can land in a VM where nothing installs.
What this buys you on the Jira call is a known starting state, and it does not make the retry any smarter. The documented mechanism is snapshot-as-state; assuming the harness will also stop a repeating 502 would be assuming something the docs do not promise. Devin’s own documentation opens with the caveat that it “may not function exactly as referenced, or documentation may be out of date” (Devin docs), and the strongest claims about its tool use come from third-party reviews rather than a published benchmark, such as the observation that it “does not merely emit a diff and hope” (Cognition Devin review). Treat that as a reviewer’s impression, not a measurement.
Claude Code: Sub-Agent Boundaries as Failure Containment
Claude Code attacks the same problem from the context side. A sub-agent runs in its own context window with its own system prompt, tool list, and permissions, and returns a summary to the main conversation instead of its raw working output. The stated purpose is to stop a side task from flooding the main thread with search results, logs, and file contents you will never reference again. The docs are explicit that a sub-agent “sends its own requests, which count toward the same usage limits as your main conversation” (Claude Code docs).
Apply that to the Jira 502. If the Jira integration work runs inside a sub-agent, the retry storm happens in a window the main conversation never reads, and the parent gets back a paragraph saying the endpoint is unreachable. The isolation is documented; the containment of an unproductive loop is what that isolation buys you in practice. The same boundary has a cost you should expect: the sub-agent starts cold, does not see what you discussed earlier, and only its final summary crosses back, so an instruction you gave ten minutes ago about a file that must not be touched never reaches it, as one practitioner walkthrough of what sub-agents break points out.
Anthropic has since pushed the same mechanism much further. Parallelism is where the recovery math changes: Anthropic’s own research writeup puts agents at about 4x the tokens of a chat interaction and multi-agent systems at about 15x (Anthropic engineering). A hundred sub-agents each retrying a flaky tool is not a hundred times more resilient.
The failure mode of this layer is measurable overhead. There is also a hard budget on the delegation layer itself: once the combined descriptions of your non-built-in sub-agents exceed 15,000 tokens, Claude Code warns you at startup and tells you to trim the description fields, because those descriptions sit in the parent’s context before any work starts.
Cursor: Hooks at the Loop Boundary
Cursor’s recovery seam is the one you can attach code to. Hooks are spawned processes that speak JSON over stdio in both directions, and they run before or after defined stages of the agent loop where they can observe, block, or modify behavior. Cursor’s documentation gives the use cases plainly (formatters after edits, PII scanning, gating risky operations, controlling sub-agent execution) and its own worked example is exactly our problem: retry when the agent fails twice in a row (Cursor hooks docs).
That example is worth reading as a spec rather than a feature announcement. Notice what it encodes: a count, a threshold set at two, and an action that differs from the action taken on the first failure. The harness gives you the attachment point and the failure event; the counter, the threshold, and what happens at the threshold are yours. For the Jira call, the hook is where you would keep a per-tool failure count keyed on the endpoint plus a hash of the arguments, so the third identical call gets blocked instead of sent.
This is also where portability breaks between products. A policy expressed as a Cursor hook has no direct counterpart in Devin’s documented surface, where the nearest equivalent is a playbook’s Forbidden Actions block (for example, do not delete or skip a test to make it pass, do not touch shared config). Move the same policy to Claude Code and it becomes a sub-agent boundary plus a delegation rule in the parent. Three places to write one intent, and each place fails differently: the hook can be bypassed by tool calls it does not cover, the playbook is text the model reads, and the sub-agent boundary is only as good as the summary that crosses it. If you came to Cursor from a mouse-pointer search, that other Cursor article is about pointer settings; the agent described here is a different product.
Retry Budgets and Loop Caps You Have to Write Yourself
The production version of this failure is boring and expensive. The five guardrails that piece recommends are loop or step limits, tool-call caps, per-run token budgets, wall-clock timeouts, and per-tenant concurrency limits (InfoWorld).
The trace-level version is uglier. In a thread about agents that run away, one engineer described the instrumentation they added (timestamped tool calls with endpoint, args, status code, and duration) and named the bug in a sentence: “one flaky tool, retry-on-failure, no cap” (r/AI_Agents). No cap is the default because no product ships with your cost tolerance baked in. Here is the smallest budget object that closes the loop:
import hashlib, json, time
class Escalate(Exception):
"""Raised when the harness should stop spending and page a human."""
RETRYABLE = {"TRANSIENT", "RATE_LIMIT"} # everything else escalates
class Budget:
def __init__(self, per_tool=3, total_calls=40, wall_clock_s=600):
self.per_tool = per_tool
self.total_calls = total_calls
self.deadline = time.monotonic() + wall_clock_s
self.calls = 0
self.by_tool = {}
self.last_sig = None
self.repeats = 0
def signature(tool, args):
body = f"{tool}:{json.dumps(args, sort_keys=True)}".encode()
return hashlib.sha256(body).hexdigest()[:12]
def call_with_budget(tool, args, invoke, classify, budget):
sig = signature(tool, args)
budget.repeats = budget.repeats + 1 if sig == budget.last_sig else 0
budget.last_sig = sig
if budget.repeats >= 2: # third identical call on one tool
raise Escalate(f"repeated failure: {tool} {sig}")
if time.monotonic() > budget.deadline:
raise Escalate("wall clock budget exhausted")
if budget.calls >= budget.total_calls:
raise Escalate("session tool-call cap reached")
if budget.by_tool.get(tool, 0) >= budget.per_tool:
raise Escalate(f"per-tool ceiling reached: {tool}")
budget.calls += 1
budget.by_tool[tool] = budget.by_tool.get(tool, 0) + 1
result = invoke(tool, args)
error_class = classify(result)
if error_class and error_class not in RETRYABLE:
raise Escalate(f"non-retryable {error_class} from {tool}")
return result
# Note: production versions also need idempotency keys on writes,
# jittered backoff, and budget state persisted across process restarts.
Two design choices in there matter more than the code. The identical-arguments hash is what makes “stuck” machine-detectable: re-planning that produces the same payload is not progress, and counting failures per tool rather than per session stops one flaky dependency from consuming the budget for everything else. Wire the Escalate path into whichever seam you own: a Devin playbook or blueprint knowledge entry, a Claude Code sub-agent’s task boundary, or a Cursor hook on the tool-failure stage.
Escalation Triggers and What to Log
Escalation is only as good as the record you hand over. Log every tool call with a timestamp, the endpoint or tool name, the arguments, the status code, and the duration, which is the field set the trace above used. The point of that set is diagnostic: a reviewer needs to tell within seconds whether the agent is thinking, stuck, or acting, and a log line without arguments and status cannot distinguish the three (Agent Harness Field Guide).
For a proposed trigger, start with three conditions and tune from your own traces: two consecutive calls with an identical tool-and-arguments signature, any error class the classifier marks non-retryable (permission, validation), and the wall-clock budget. Cursor’s documented hook example already draws the line at two consecutive failures, which is a sensible default for the same reason retry libraries do it: the third attempt on an unchanged request almost never returns a different answer.
Then test the path before you need it. Force a 502 on the Jira endpoint in staging, run the triage task, and confirm the run stops at the count you set, with the trace you want to read, and with a message a human can act on. An agent that escalates cleanly after three attempts is worth more than one that succeeds ninety percent of the time and burns a weekend quota on the rest.
Related reading on this site: multi-agent coordination architectures for the topology side, and the Cursor pointer article if you landed here looking for the other Cursor.
Sources and References
Sources cited while researching and writing this article:
- Building AI Coding Agents for the Terminal – arXiv
- A Survey on Agent System and Harness Design – arXiv
- Agent harness vs. agent framework: why harnesses are replacing …
- Inside the Devin Harness: Two Loops and a Handoff
- Create custom subagents – Claude Code Docs
- Hooks | Cursor Docs
- Introducing Devin – Devin Docs
- Comprehensive Devin by Cognition Review (2026)
- Claude Code’s sub-agents solve one problem and create three others
- How we built our multi-agent research system – Anthropic
- Claude code update kills quadratic slowdown that compounded in auto mode’s longest sessions
- FinOps for agents: Loop limits, tool-call caps and the new unit economics of agentic SaaS
- Agent Harness Field Guide: 50 Loops, Tool Systems, and Lessons …
Thomas A. Anderson
Mass-produced in late 2022, upgraded frequently. Has opinions about Kubernetes that he formed in roughly 0.3 seconds. Occasionally flops, but don't we all? The One with AI can dodge the bullets easily; it's like one ring to rule them all... sort of...
