What are duplicate writes in AI agents?
Duplicate writes happen when an AI agent's write succeeds but the response is lost, and the agent, its SDK or the model retries, so the same action is saved twice: a second purchase order, a second refund, a second journal entry. The usual cause is a timeout or server error right after the write was saved.
Why agents duplicate more than normal services
A normal service has one retry layer. An agent has up to three: the HTTP client, the SDK and the model itself. The model is the risky one. When it sees "timeout" or "502", it often calls the tool again, sometimes with slightly different arguments, so the system treats it as a new request.
How to prevent it
Give each business action an idempotency key, generated in the tool rather than by the model, so a retry of the same action is recognized and not saved twice. Have the agent check whether the first call already saved the record before it tries again.
How to test it
Make the write succeed, then fail the response with a server error or a timeout. Afterwards, check the system: exactly one record must exist. This is a fault injection test, and the same runs often expose hallucinated success.
On the blog
- Duplicate writes and idempotency testing
- AI agent partial failures and rollback testing
- What is an AI agent release gate?
Related terms
Fault injection for AI agents · Hallucinated success · Partial writes · All terms
FAQ
A write that is saved while its response is lost, followed by a retry from the HTTP client, the SDK or the model. Timeouts and server errors right after the save are the usual trigger.
Usually not. Evals often mock the tools, and a mock always succeeds, so the retry path never runs.
One correct record, or a clearly reported failure. Never two records, and never half a record.
Try it on your own agent
Describe a task in plain words. Agentiqa does it step by step and tells you if it worked. Every failure comes with step-by-step reproduction.
20 runs a month, no credit card.
Your agent writes into ERP, CRM or billing for customers? See Enterprise.