The Idempotency Gap in Agentic AI: Why Retried Tool Calls Silently Corrupt Enterprise State
Every production agent framework retries failed tool calls -- on timeout, on transient error, on a dropped connection. Almost none of them ask whether the tool was safe to retry. When an agent re-issues a call that already succeeded but whose response was lost, it charges the card twice, sends the email twice, books the order twice. The idempotency gap is the most under-instrumented correctness bug in agentic systems.

The Order That Got Placed Twice
The agent called the order-placement tool. The call succeeded on the vendor's side -- the order was created, the warehouse was notified, the customer's card was authorized. But the network hiccupped on the way back, the response never reached the agent runtime, and the framework did what frameworks do: it retried. The second call placed a second identical order. Two charges, two shipments, one very confused customer, and an incident review that took three days to trace back to a single dropped TCP packet.
Nothing in this story is exotic. It is the single most common way agentic systems corrupt real-world state, and it is almost entirely invisible in testing because it only manifests under exactly the transient conditions your test suite does not reproduce. The bug is not in the model. It is in the seam between the model's decision to call a tool and the tool's effect on the world -- the place where retries live and idempotency is assumed but never enforced.
Every serious agent framework retries. Retrying is correct for transient failures. What is missing is the question that has to come before every retry: was this operation safe to run twice? For most enterprise side effects, the answer is no, and nobody checked.
Why Agents Make the Idempotency Problem Worse
Retry-induced duplication is an old distributed-systems problem. What is new is that agentic systems make it dramatically more likely and dramatically harder to reason about, for three structural reasons.
First, agents introduce retries at multiple layers that do not know about each other. The LLM provider retries on its side. The agent framework retries the tool call. The HTTP client inside the tool retries the request. The queue that delivered the task redelivers on timeout. Each layer is individually reasonable; stacked, they turn one logical operation into an unknown number of physical executions. This is the same uncontrolled-fan-out geometry that makes robust observability for AI systems non-negotiable, because the model layer will never tell you it fired twice.
Second, the model is nondeterministic, so the same operation is a slippery notion. A retried tool call in a classic system replays identical bytes. A re-planned agent step might call the same tool with subtly different arguments, defeating any naive deduplication keyed on exact payload. The agent does not know it already did the thing, because its memory of having done it lives in a tool result it never received.
Third, and most dangerously, the failure is silent. A duplicated order does not throw. The system reports success -- twice. Without instrumentation specifically watching for duplication, the only signal is a downstream anomaly days later.
The Seam Where State Gets Corrupted
The idempotency gap lives in one specific place: between the tool's side effect and the acknowledgment of that side effect reaching the caller. Four failure shapes live in that seam.
The lost acknowledgment
The operation succeeds; the response is lost in transit. The caller assumes failure and retries. This is the canonical duplicate, and it is undetectable from the caller's side without an idempotency key, because a successful-but-unacknowledged call and a genuinely-failed call look identical to the retrying party.
The partial write
The tool performs a multi-step operation -- create record, charge card, send confirmation -- and fails midway. A retry re-runs the whole sequence, re-doing the steps that already committed. This is the agentic version of a transaction without a transaction boundary, and it demands the same discipline that data contracts enforce at the boundaries of AI pipelines: every side-effecting operation needs a defined, enforceable notion of what already done means.
The re-planned duplicate
The agent, having lost the result, does not blindly retry -- it re-plans, and its new plan re-issues a semantically identical action with non-identical arguments. Payload-hash deduplication misses this entirely. You need a business-level idempotency key derived from intent, not bytes.
The cross-run replay
A task is redelivered from a queue after a worker crash, and the entire agent run replays from the start, re-executing every side effect it already committed before the crash. Without a durable record of which effects already fired, the replay is indistinguishable from a fresh run.
Closing the Gap: Idempotency as a First-Class Contract
The fix is not to stop retrying. Retrying is correct. The fix is to make every side-effecting tool safe to retry, and to make that safety an enforced contract rather than a hopeful convention.
Assign idempotency keys at the intent layer
Every side-effecting operation should carry an idempotency key generated at the moment the agent forms the intent -- not at the HTTP layer, where re-planning defeats it. The key should encode the business intent so that a re-planned duplicate with different phrasing still collides with the original. The tool, or the service behind it, deduplicates on that key and returns the original result on a repeat. This turns was it safe to retry from a guess into a guarantee.
Separate reads from writes and mark tools explicitly
Agent tool definitions should declare whether a tool is safe to retry. Read-only tools retry freely. Write tools retry only through the idempotency-key path. Making this a required field in the tool schema is the same discipline as structured output engineering, where you constrain the system's surface so unsafe states become unrepresentable. If a write tool ships without an idempotency contract, the deploy should fail.
Make duplication observable
You cannot fix what you cannot see. Instrument the deduplication layer to emit a metric every time it suppresses a duplicate, and alert when the rate spikes -- a duplication surge is an early warning of a retry misconfiguration upstream. This is a specific, high-value case of the general principle that production AI needs audit trails that trace every effect back to the decision that caused it. When a duplicate does slip through, the audit trail is what turns a three-day investigation into a three-minute one.
Govern it as policy, not folklore
Idempotency cannot be a convention that senior engineers remember and juniors do not. It has to be a governed requirement -- part of the review gate for every new tool, enforced in the framework, verified in CI. This is exactly the kind of control that belongs inside an AI governance framework, even for smaller organizations that assume governance is a big-company problem. The cost of skipping it is not theoretical; it is a double-charged customer and a compliance incident.
The Uncomfortable Truth
Most teams shipping agentic systems today have an idempotency gap and do not know it, because it only fires under transient failure and their happy-path testing never triggers it. The gap is dormant, not absent. It will surface the first time production sees a real network partition, a real worker crash, a real provider timeout under load -- and it will surface as corrupted state, not as an error page.
The agents that survive contact with production are not the ones with the cleverest prompts. They are the ones whose every real-world side effect is safe to retry by construction. Idempotency is not an optimization you add later. It is the correctness boundary that separates an agent that assists your business from one that quietly duplicates its liabilities.
Building agentic systems that touch real enterprise state -- payments, orders, records, communications? Book a working session and we will pressure-test where your idempotency gap is hiding before production finds it for you.
Founder & Principal Architect
Ready to explore AI for your organization?
Schedule a free consultation to discuss your AI goals and challenges.
Book Free Consultation