Skip to content
Agent Model Fit

GuidesImplementation guide

Why AI Agent Retries Create Duplicate Records

By Agent Model Fit

Published

Sources (2)

On this page

A timed-out write may already have succeeded. Before an AI agent retries a create request, the tool needs either a way to verify what happened or an API contract that prevents the same request from creating a second record. Give the intended write a stable identifier, and reuse it for every attempt. An identifier alone does nothing unless the system receiving the request enforces it.

How a successful write becomes a duplicate

In this hypothetical content management system (CMS) migration, an agent reads article 417 from the old site, converts it to the new format, and requests a draft in the destination CMS.

  1. The destination saves draft A92.
  2. The response is lost, so the agent sees a timeout.
  3. The agent sends another create request. The destination treats it as a new request and creates draft B18.

Both drafts can have correct content. The migration still produced two records for one article. A tool-call limit might stop the loop too late. A permission check answers whether the agent is allowed to create a draft, not whether it already created one.

Give the record and the write separate identities

  • Source identity: The old site’s ID plus article 417 identifies the content item. Store a mapping to destination draft A92 so a later migration can find the existing entry. Storing the original ID as a field does not enforce uniqueness or perform the lookup.
  • Operation identity: A request ID identifies one intended write, such as importing revision 6 of article 417 as a draft. Persist that ID and the intended payload before the first attempt. A retry after a timeout or restart reuses the same ID and payload. A later, intentional revision uses a new operation ID but targets the same draft.

Title or slug can change. The source identity is the better anchor for finding the same content across migration runs. The operation identity answers a different question: did this particular change already happen?

Check what the write API actually guarantees

A request is idempotent when repeating it has the same intended effect as performing it once; the responses or logs need not be identical. RFC 9110 defines PUT, DELETE and safe methods as idempotent. A POST that creates a record has no general retry guarantee. The HTTP standard advises against automatically retrying a non-idempotent request unless the client knows the operation is safe to repeat or can establish the first request was never applied.

The Amazon Builders’ Library describes an API design that accepts a caller-supplied request ID, detects reuse with changed parameters, and records the ID and the mutation as one atomic operation. Two identical payloads can represent two legitimate actions, so matching on content alone is not a substitute for the caller’s intent.

Before enabling retries, check the API’s documented ID scope, retention period, concurrent-request behavior, and response to a reused ID with a different payload. A gateway that logs a request in one database and writes to a remote CMS cannot assume both commit together. It needs destination support, such as a documented idempotent write or enforced unique identity, or a way to reconcile a write whose outcome is unknown. An unprotected lookup followed by create can race with another worker doing the same thing.

Reconcile a timeout before starting a new write

Check the operation status if the API exposes it. Otherwise, look up the destination by the recorded mapping or stable source identity. For the example above, verify that the matching draft has the intended revision, author and image references. If the evidence confirms the intended write happened, record its destination ID and move on.

No match is not necessarily proof of failure: the first write may still be running, or a search index may not reflect it yet. If the service documents safe repetition with the same request ID and that guarantee is still in effect, retry within a set limit. If the result remains unknown and neither verification nor safe retry is available, stop that item and flag it for review. Do not create a second draft just to get a successful response.

Test the failure with one disposable draft

Use a test destination. Do not publish the draft. Verify the stored records and references, not only the status codes.

  1. Lose the response after the write commits. Recover the same entry ID and verify there is exactly one draft.
  2. Restart the worker before retrying. Confirm it reuses the persisted operation ID.
  3. Send two attempts at the same time. Confirm at most one creates the draft and that the final state is correct.
  4. Reuse an ID with a different payload. Confirm the service reports a conflict rather than silently accepting changed intent.
  5. Import an intentional new revision. Confirm the importer updates the same destination entry and keeps its references intact.
  6. Check the retention boundary. Verify what the service does after the request ID expires and what the importer does when the previous outcome is still uncertain.

These are proposed checks, not measured results. Passing them supports the retry behavior tested for this write path. It does not prove that every downstream event, attachment, or notification occurs exactly once.

Provenance and limits

Prepared for Agent Model Fit with Codex assistance in source verification, drafting, and editing. The CMS example is hypothetical. No specific CMS behavior, runtime experiment, or human editorial review is claimed.

Sources

  1. RFC 9110: HTTP Semantics, section 9.2.2
  2. Amazon Builders' Library: Making retries safe with idempotent APIs