---
title: "Counting the retry loop"
description: "Count an agent retry loop as one stuck attempt across docs and API. Repeated calls are not extra tasks. MCP tool-error recovery stays a separate count."
canonical: "https://www.agentrail.co/blog/agent-retry-loop?h=31ZH7W41MWY0Q005"
author: "Vivek Mittal"
published: "2026-11-12T12:14:00Z"
last_updated: "2026-11-22T15:28:41.499Z"
---

# Counting the retry loop

Count an agent retry loop as one stuck attempt across docs and API. Repeated calls are not extra tasks. MCP tool-error recovery stays a separate count.

An agent retry loop is one stuck attempt. The agent fetches the same doc, or calls the same API route, again and again, and the outcome does not change. Count that run once. Repeated calls on that task are not extra tasks. A gateway chart that treats every HTTP call as its own incident will invent a pile of failures from a single stuck task.

The loop can cross surfaces. A docs refetch and a failing call are one attempt when they share a task and neither one moves the outcome. Which requests share a task is [agent journey analytics](https://www.agentrail.co/blog/agent-journey-analytics?h=31ZH7W41MWY0Q013). Whether the task finished stays in [agent task completion rate](https://www.agentrail.co/blog/agent-task-completion-rate?h=31ZH7W41MWY0Q021).

> **Key Takeaways**
>
> Collapse repeated docs and API requests on one task into one stuck attempt, and keep the call count on that attempt.
>
> A cursor, filter, or linked page that advances is progress. An unchanged request, while the outcome stays put, is a loop.
>
> Mark whether the loop exited into a later success or ended the task.
>
> Send MCP tool-error recovery to the MCP page, and send a repeated write to the idempotency page.

## Group the requests that leave the outcome unchanged

Start from the requests you already stored, in order, inside one task. Group a run when three things hold.

The target stays the same. For docs, that is the same URL. For an API, that is the same method and path template. A new path the task required opens a new group.

The request stays materially the same. The body, the query, and the headers that change behavior do not move. Ignore a clock header or a request id. If the cursor, the filter, or the payload changes in a way the task needed, you are looking at progress. A new idempotency token or timestamp can ride on an otherwise identical write. Treat that as the same request for the group.

The outcome stays put. The row is still absent, the key is still missing, or the pull request is still unopened. A 200 that returns the same empty body is still a loop. Status is a column on the group. A 429 is a response, and it joins the loop when the same request is sent again and the outcome still does not change.

Publish the group as one attempt, with the call count on it. A client library that repeats a 503 stays inside that attempt.

## Join the doc and the API call

The usual loop is untidy. The agent reads a guide, calls an endpoint, gets a thin error, refetches the guide, and calls the endpoint again. Split by service and you'll report two problems. The guide looks popular. The endpoint looks unstable. The task had one stuck attempt.

Join them when they share the task and the outcome does not change from the first request of the run to the last. Store both targets. The headline target is the one that repeats most often. The other stays on the attempt as context. A docs-only burst can be the whole loop. So can an API-only burst. A per-host chart miscounts that alternation.

Keep the join inside the task. Two tasks that hit the same URL in the same minute are two attempts. Group paths by template, with ids replaced by a placeholder, so one route does not shatter into singletons.

## A moving cursor is the task

Some repeats are the work. The next page is progress when the cursor changes and the task asked for the full list.

[Anthropic's tool essay](https://www.anthropic.com/engineering/writing-tools-for-agents) of 11 September 2025 is the suspect list once the request stops changing. Repeated calls usually mean pagination, filtering, or defaults are wrong. Invalid-parameter errors usually mean the description or the examples are thin. A validation error should name a correction. An opaque code gives the next attempt nothing new to send.

Compare the two requests anyway. If the cursor, page token, or filter advanced, class the run as progress. If the response never named a next cursor and the agent sent the same query again, class it as a loop. On docs, a second fetch of a URL the agent already holds, with no new fragment and no new query, is a refetch. A different anchor can be progress. Store the full URL, query string included.

## Mark the exit, then name the target

An exited loop is followed, in the same task, by a different request that reaches the outcome. Keep it in the count and mark it exited. A stuck loop is how the task ends: after the last repeat, nothing reaches the outcome. The call count says how hard the agent tried. If you cannot see a later request, mark the exit unknown. A dropped log line is not an exit.

The first-attempt reading and the later rescue are [first-try success and eventual success](https://www.agentrail.co/blog/agent-first-try-success-rate?h=31ZH7W41MWY0Q03Z).

A POST that fires twice can create two rows when the route treats each call as new work. The count shows the double send. Making that write safe is [write endpoints an agent will call twice](https://www.agentrail.co/blog/idempotent-api-for-ai-agents?h=31ZH7W41MWY0Q04X). A safe write can still be a stuck loop if the outcome never appears.

Recovery after an MCP tool error, and a tool that stays in error, are counted in [MCP analytics](https://www.agentrail.co/blog/mcp-analytics?h=31ZH7W41MWY0Q05V). If the only repeats are MCP tool calls, use that page. When a tool error sits beside an HTTP run, count the HTTP run here.

| Repeat shape | Class | Where it is counted |
| --- | --- | --- |
| Same doc URL or same method and path, outcome unchanged | One stuck attempt | This page |
| Cursor, filter, or linked page advances | Progress | Not a loop |
| Identical run, then a later call reaches the outcome | Exited loop | This page, marked exited |
| Same write sent twice | Loop, plus a safety question | Count here. Safety is the idempotency page |
| MCP tool errors only | Tool recovery or a stuck tool | MCP analytics |

For a window you can rerun, publish how many tasks contain a stuck loop, the doc URL or method and path each one sat on, and whether it exited. Sort those targets by tasks. If task membership is missing, skip the count. The edit to that doc or error body is [agent experience optimization](https://www.agentrail.co/blog/agent-experience-optimization?h=31ZH7W41MWY0Q06S). Change it, then count the loop again on the same task.
