---
title: "AI Agent Idempotency: Test Retries Safely"
description: "Test AI agent idempotency across retries, double clicks, restarts, and replay. Use stable intent keys and verify that only one action commits."
canonical: "https://scalewithsearch.com/articles/test-ai-agent-idempotency-and-retries"
date: "2026-08-19"
modified: "2026-11-10"
---
## Site navigation

- [Scale With Search](https://scalewithsearch.com/)
- Services
  - Local
    - [All services](https://scalewithsearch.com/services)
    - [AI visibility tracking](https://scalewithsearch.com/services/ai-visibility-tracking)
    - [Google Maps rank tracking](https://scalewithsearch.com/services/google-maps-rank-tracking)
    - [Local SEO](https://scalewithsearch.com/services/local-seo)
    - [Google Business Profile management](https://scalewithsearch.com/services/google-business-profile)
  - Website and search
    - [SEO solutions](https://scalewithsearch.com/seo)
    - [Technical SEO](https://scalewithsearch.com/seo/technical-seo)
    - [On-page and content SEO](https://scalewithsearch.com/seo/on-page-and-content-seo)
    - [Semantic SEO and topical authority](https://scalewithsearch.com/seo/semantic-seo-and-topical-authority)
    - [Custom SEO tools](https://scalewithsearch.com/seo/custom-seo-tools)
    - [Site build](https://scalewithsearch.com/work#site-build)
    - [Whole website fix](https://scalewithsearch.com/work#whole-website-fix)
  - AI functions
    - [AI operations](https://scalewithsearch.com/ai-systems)
  - First step
    - [Working session](https://scalewithsearch.com/audit)
  - Start here
    - [Send your brief](https://scalewithsearch.com/work#send-your-brief)
    - [Example scope](https://scalewithsearch.com/work#review-the-example-scope)
    - [Prices and terms](https://scalewithsearch.com/work#prices-and-terms)
- Industries
  - Agencies
    - [SEO agencies and consultants](https://scalewithsearch.com/for/seo-agencies-and-consultants)
    - [Marketing agencies and freelancers](https://scalewithsearch.com/for/marketing-agencies-and-freelancers)
    - [AI visibility check for SEO agencies](https://scalewithsearch.com/check/seo-agencies-and-consultants)
    - [Marketing and SEO agencies](https://scalewithsearch.com/for/#group-agencies)
  - Browse by business
    - [Trades and field service](https://scalewithsearch.com/for/#group-trades)
    - [Real estate agents and teams](https://scalewithsearch.com/for/real-estate)
    - [Health, wellness, and animal care](https://scalewithsearch.com/for/#group-practices)
    - [Chiropractic and wellness practices](https://scalewithsearch.com/for/chiropractic-and-wellness-practices)
    - [Law, finance, and IT](https://scalewithsearch.com/for/#group-professional)
    - [Machine shops and manufacturers](https://scalewithsearch.com/for/#group-manufacturing)
    - [Restaurants, shops, studios, and nonprofits](https://scalewithsearch.com/for/#group-local-services)
  - [All industries](https://scalewithsearch.com/for/)
- Resources
  - Free tools
    - [AI visibility check](https://scalewithsearch.com/check)
    - [All free tools](https://scalewithsearch.com/tools/)
    - [Free starter kit (.zip)](https://scalewithsearch.com/kit/business-memory-starter-kit.zip)
  - Guides
    - [AI-native library](https://scalewithsearch.com/ai-native)
    - [Industry intelligence](https://scalewithsearch.com/intelligence)
    - [Office job guides](https://scalewithsearch.com/guides/)
    - [Business memory](https://scalewithsearch.com/articles/business-memory-for-ai-agents-guide)
    - [Agent governance](https://scalewithsearch.com/articles/ai-agent-governance-guide-small-business)
    - [Ownership and migration](https://scalewithsearch.com/articles/leaving-vendor-ai-memory-guide)
  - Articles
    - [All articles](https://scalewithsearch.com/articles/)
- About
  - Evidence
    - [Proof](https://scalewithsearch.com/proof)
  - Scale With Search
    - [About](https://scalewithsearch.com/about)
    - [How it works](https://scalewithsearch.com/how-it-works)

# Test an AI Agent for Duplicate Runs, Retries, and Double Clicks.

Built from 6 notes in Victor's vault. Drafted with Claude Fable 5 and Claude Fable 5.1, rewritten against Victor's notes with Claude Opus 5.5. Reviewed by Victor on 2026.11.11.

Idempotency means one intended action produces one side effect, even when the request repeats. Test the duplicate paths before an agent gets send, payment, booking, deployment, or live-record capability.

A prompt rule like "only send when appropriate" fails under automation. Mechanical guards hold: dry-run defaults, one record per transaction, a duplicate check before every write, and a breaker.

## One intent needs one stable key

Give each business action a caller-generated idempotency key.

The key represents the intent, not one network attempt. A retry uses the same key. A new approved action uses a new key.

AWS defines an idempotent operation as one that can be retried without additional side effects. Its Builders' Library recommends unique caller-provided request identifiers so a service can recognize repeated intent. [AWS Builders' Library: Making retries safe with idempotent APIs](https://aws.amazon.com/builders-library/making-retries-safe-with-idempotent-APIs/)

For an approved email, derive or store the key from stable fields:

```text
action_type:: send_email
business_id:: BIZ-01
account_id:: ACCT-104
recipient_id:: PERSON-882
artifact_hash:: 7ce4...
approval_id:: APR-1902
intent_id:: FOLLOWUP-2026-0819-001
```

Do not use the current timestamp alone. Each retry would get a new key and look like new intent.

## Test five duplicate paths

Test five scenarios:

1. Double click before the first response.
2. Timeout after the destination commits.
3. Process restart after local intent is recorded.
4. Overlapping scheduler runs.
5. Manual replay of an old run.

Each scenario must create exactly one downstream object or effect.

Test concurrent arrival, not only sequential replay. Two workers can receive the same intent before either records completion. The store needs an atomic claim around the key and the effect. Record which worker won. The loser returns the existing result. It must not generate a new key and act again.

The [pre-production agent test](/articles/test-an-ai-agent-before-production) should use a recorder, test account, or reversible fixture. Do not learn about duplicate charges from a live customer.

## Record intent, commit, response, and receipt separately

One "success" field cannot describe a distributed action.

Record four checkpoints:

**Intent recorded.** The system accepted one exact proposed action and key.

**Commit attempted.** The executor called the destination.

**Response observed.** The executor received a provider response or a timeout.

**Result verified.** The executor queried the destination or received a stable object identifier.

The destination can commit before the response reaches the agent. That is the dangerous gap.

AWS notes that recording the token and mutating state must avoid partial outcomes. In its example, a resource is created and the response never returns. The retry should resolve the same request.

The write gates I build log every attempt as executed, dry run, skipped duplicate, or failed. A skipped duplicate carries the ID of the record that already exists.

## Resolve unknown state before retrying

When a timeout occurs after the commit request, mark the action `uncertain`.

Use the idempotency key, provider object ID, recipient, or approved fields to query downstream state. If the intended object exists, write the receipt and stop. If it does not exist and the provider supports safe idempotency, retry with the same key.

With no safe read-back or idempotent contract, route the uncertain action to a person. Uncertainty is not permission to retry.

Stripe's API documents that it stores the status code and response body for the first request associated with an idempotency key. Later requests with the same key return the same result. [Stripe: Idempotent requests](https://docs.stripe.com/api/idempotent_requests)

Not every provider behaves like Stripe. Record the contract and retention window for each executor. Two failed calls in one run should trip a breaker that stops every write after them.

## Test restart and schedule overlap

The key and action ledger must survive a restart. A production job climbs back on its own after a crash. Climbing back must not mean acting twice.

Persist intent before the external call. On restart, read the ledger. Resume from the last confirmed checkpoint. Do not regenerate a key from memory or a new run timestamp.

Schedulers overlap when a run outlasts its interval or a manual run starts near the timer. Use a lock, a job-window key, or a claim in the work queue. A status flip works too. In a publishing queue I built, an item moves from approved to published once, and the next poll skips it.

Test the lock. Kill the process after it claims work. Confirm the lease expires or recovery resumes it without a duplicate.

The [run receipt requirement](/articles/receipt-is-part-of-the-output) shows you the logical run, each attempt, and the observed downstream result.

## Verify the destination

The agent's statement "sent once" is not proof. A dispatch is verified by the receiving side's record, not by the sender's report.

Count provider message IDs, payment objects, bookings, CRM changes, or deployment revisions. Query the exact destination when possible.

A message recorder needs one object for the recipient and artifact hash. A payment fixture needs one charge and one ledger entry. A CRM fixture needs one field transition and no unrelated changes.

Record the downstream count in the acceptance receipt. In live sending, enforce the cap before any API call and reconcile your count against the provider's own count every day.

If read-back is unavailable, name the limitation. You may keep that action manual or require a broker that provides idempotency and queryable state.

## Inspect `idempotency-fixture.csv`

Use five rows and exact expected side-effect counts.

```csv
fixture_id,scenario,intent_id,attempts,fault,expected_effects,expected_status,required_evidence
IDEM-01,double_click,ACT-101,2,requests_arrive_together,1,completed,one downstream object and one receipt
IDEM-02,timeout_after_commit,ACT-102,2,first_response_dropped,1,completed,read-back finds first object
IDEM-03,process_restart,ACT-103,2,restart_after_commit_attempt,1,completed,persisted ledger resumes same key
IDEM-04,schedule_overlap,ACT-104,2,two workers claim window,1,completed,one claim wins and one duplicate receipt
IDEM-05,manual_replay,ACT-105,2,replay_consumed_approval,1,denied,original object remains unchanged
```

The replay case expects one total side effect, because the first accepted execution already happened. The replay itself adds zero.

## Run the acceptance fixture

For each row:

1. Start with an empty recorder and ledger.
2. Create one approved intent and stable key.
3. Apply the named fault.
4. Allow the documented retry or recovery path.
5. Query the downstream recorder.
6. Count exact side effects.
7. Inspect the logical run ID and attempt IDs.
8. Confirm the approval was consumed once.
9. Confirm the receipt explains duplicate suppression or denial.
10. Reset the test environment through the documented path.

The [buyer acceptance checklist](/articles/ai-agent-acceptance-checklist) marks any duplicate as a critical failure.

## Fail on mismatched reuse too

An idempotency key cannot authorize changed intent.

If a retry uses the same key with a new recipient, amount, account, artifact, or action class, reject it. Return a mismatch error and keep both payloads. A consumed approval cannot be reused for another action.

The key store needs a retention rule. If keys expire before delayed retries arrive, an old request looks new. Set retention from the maximum replay window and the action's consequence.

## Separate duplicate suppression from business deduplication

Idempotency prevents repeated execution of one intent. Business deduplication decides whether two different intents target the same real-world item.

Two approved follow-ups may have different intent IDs and still address the same lead and campaign. A separate eligibility rule catches that business duplicate before approval. Run eligibility, dedupe, and suppression checks in code before a model is called.

Test both layers. The idempotency fixture alone does not prove the lead should receive the message.

## Approval and stopping boundary for AI agent duplicate run and retry testing

The test agent may create fixture intents, inject failures, query a recorder, and write receipts. It stops before real sending, payment, booking, deployment, or CRM credentials.

The executor stops when the key is missing, reused with changed intent, outside its retention window, tied to an expired or consumed approval, or left in uncertain state without reliable read-back.

Passing the fixture does not authorize production access. Activation, credentials, live schedules, and external actions need separate owner approval. Anything that spends money or cannot be undone waits for a person.

## Three public sources on AI agent duplicate run and retry testing

- [AWS Builders' Library: Making retries safe with idempotent APIs](https://aws.amazon.com/builders-library/making-retries-safe-with-idempotent-APIs/)
- [Stripe: Idempotent requests](https://docs.stripe.com/api/idempotent_requests)
- [OpenTelemetry: Tracing API](https://opentelemetry.io/docs/specs/otel/trace/api/)


## Questions about Test an AI Agent for Duplicate Runs, Retries, and Double Clicks

### How are you retrying agent write actions without doing them twice?

Give one business intent a stable caller-generated idempotency key and reuse that key for every retry of the same action. Record the intent, request, provider response, external read-back, and receipt separately so an uncertain result is resolved before another write.

### How to handle repeated button clicks / duplicated customer messages without triggering the same path twice?

Run a duplicate fixture that includes a double click, timeout after commit, process restart, schedule overlap, and replay. The destination should show one side effect for one intended action, while mismatched reuse of the same key must fail.

### Which tool calls are safe to retry?

Retry only when the action has a stable intent key or when read-back proves the earlier attempt did not commit. If the external state remains uncertain, stop and record that condition instead of risking a duplicate send, payment, booking, deployment, or live-record change.

## More reading on AI agent duplicate run and retry testing

- [Five AI Agent Reliability Metrics a Small Team Can Verify](/articles/ai-agent-reliability-metrics-small-business)
- [What an AI Agent Rollback Plan Must Contain Before Production Access](/articles/ai-agent-rollback-plan)
- [Claude vs ChatGPT for HR Policy Work: Test the Handbook Job, Not the Chatbot](/articles/claude-vs-chatgpt-hr-policy-work)

----

```text
                  .|########||.                                       .|########||.                                       .|########||.
               |##||.      .||##|.                                 |##||.      .||##|.                                 |##||.      .||##|.
             |#|.              .|#|.                             |#|.              .|#|.                             |#|.              .|#|.
           |#|                    |#|                          |#|                    |#|                          |#|                    |#|
         .#|                        |#.                      .#|                        |#.                      .#|                        |#.
        .#.                          .#|                    .#.                          .#|                    .#.                          .#|
       |#.                            .#|                  |#.                            .#|                  |#.                            .#|
      |#             ......             #|                |#             ......             #|                |#             ......             #|
     .#           ||#########|           #|              .#           ||#########|           #|              .#           ||#########|           #|
    .#.         |######||######|.        .#.            .#.         |######||######|.        .#.            .#.         |######||######|.        .#.
    #.        .##|###|##|#|######|        .#            #.        .##|###|##|#|######|        .#            #.        .##|###|##|#|######|        .#
   ||        |##|#||||||||||||#||#|        ||          ||        |##|#||||||||||||#||#|        ||          ||        |##|#||||||||||||#||#|        ||
   #        |#||||||||||||||||||||#|        #.         #        |#||||||||||||||||||||#|        #.         #        |#||||||||||||||||||||#|        #.
  ||       |#||||||||||||||||||||||#|       ||        ||       |#||||||||||||||||||||||#|       ||        ||       |#||||||||||||||||||||||#|       ||
  #       .#||||||||||||||||||||||||#|       #        #       .#||||||||||||||||||||||||#|       #        #       .#||||||||||||||||||||||||#|       #
 ||   ....|||#||||||##|#|||#|#||##||||....|. ||      ||   ....|||#||||||##|#|||#|#||##||||....|. ||      ||   ....|||#||||||##|#|||#|#||##||||....|. ||
 #.  .  ....|#  ....#|||   ||| .#|||  ....#. .#      #.  .  ....|#  ....#|||   ||| .#|||  ....#. .#      #.  .  ....|#  ....#|||   ||| .#|||  ....#. .#
 #   .  ||||#| .#####||  . .#| .#|||  ||||#   #.     #   .  ||||#| .#####||  . .#| .#|||  ||||#   #.     #   .  ||||#| .#####||  . .#| .#|||  ||||#   #.
.|   |||||  #. |#|||||. ||  #. |#||. .|||||   ||    .|   |||||  #. |#|||||. ||  #. |#||. .|||||   ||    .|   |||||  #. |#|||||. ||  #. |#||. .|||||   ||
||   |....  #. ....|#.      |. ...|. ....||   ||    ||   |....  #. ....|#.      |. ...|. ....||   ||    ||   |....  #. ....|#.      |. ...|. ....||   ||
#.  .||||||##||||||##||####|||||||#||||||#|   .#    #.  .||||||##||||||##||####|||||||#||||||#|   .#    #.  .||||||##||||||##||####|||||||#||||||#|   .#
#    .||####|###########################|.     #    #    .||####|###########################|.     #    #    .||####|###########################|.     #
#      .#||||||.#.|| # |. ..# #| #|||||#|      #    #      .#||||||.#.|| # |. ..# #| #|||||#|      #    #      .#||||||.#.|| # |. ..# #| #|||||#|      #
#      .#|||||| ..  |# ## |#| ...#|#|||#|      #    #      .#|||||| ..  |# ## |#| ...#|#|||#|      #    #      .#|||||| ..  |# ## |#| ...#|#|||#|      #
#      .#|||#|# .# .#| #| ##|.#..#|||||#|      #    #      .#|||#|# .# .#| #| ##|.#..#|||||#|      #    #      .#|||#|# .# .#| #| ##|.#..#|||||#|      #
#      .#||||||############|######|||||#|      #    #      .#||||||############|######|||||#|      #    #      .#||||||############|######|||||#|      #
#   |...||#||||||#||||#|#||||||#|||||#||| |.|  #    #   |...||#||||||#||||#|#||||||#|||||#||| |.|  #    #   |...||#||||||#||||#|#||||||#|||||#||| |.|  #
#. .. ||||# .|||##|.  |#| .|| || .|||#. #|  # .#    #. .. ||||# .|||##|.  |#| .|| || .|||#. #|  # .#    #. .. ||||# .|||##|.  |#| .|| || .|||#. #|  # .#
|| |  ...||  ...##| |  #| .|. |. #####  .. .| ||    || |  ...||  ...##| |  #| .|. |. #####  .. .| ||    || |  ...||  ...##| |  #| .|. |. #####  .. .| ||
|| ||||| || ||||#|  .  |. |. |#. ||||| |#| || ||    || ||||| || ||||#|  .  |. |. |#. ||||| |#| || ||    || ||||| || ||||#|  .  |. |. |#. ||||| |#| || ||
.# |.....#|....|#.||||.|||##.|#|....||.#||.#. #.    .# |.....#|....|#.||||.|||##.|#|....||.#||.#. #.    .# |.....#|....|#.||||.|||##.|#|....||.#||.#. #.
 #.|||||||#############################| ||| .#      #.|||||||#############################| ||| .#      #.|||||||#############################| ||| .#
 ||       ##||#||#||||||#||#||#||#||##.      ||      ||       ##||#||#||||||#||#||#||#||##.      ||      ||       ##||#||#||||||#||#||#||#||##.      ||
  #       .#|||||||||#||#|||||||||||#|       #        #       .#|||||||||#||#|||||||||||#|       #        #       .#|||||||||#||#|||||||||||#|       #
  ||       |#||||||||||||||||||||||#|       ||        ||       |#||||||||||||||||||||||#|       ||        ||       |#||||||||||||||||||||||#|       ||
  .#        |#||||||||||||||||||||#|        #.        .#        |#||||||||||||||||||||#|        #.        .#        |#||||||||||||||||||||#|        #.
   ||        |#||||||||||||||||||#|        ||          ||        |#||||||||||||||||||#|        ||          ||        |#||||||||||||||||||#|        ||
    #.        .######|#|#########|        .#            #.        .######|#|#########|        .#            #.        .######|#|#########|        .#
    .#.         |#####||||#####|         .#.            .#.         |#####||||#####|         .#.            .#.         |#####||||#####|         .#.
     |#           ||########||           #.              |#           ||########||           #.              |#           ||########||           #.
      |#             ......             #|                |#             ......             #|                |#             ......             #|
       |#.                            .#|                  |#.                            .#|                  |#.                            .#|
        |#.                          .#.                    |#.                          .#.                    |#.                          .#.
         .#|                        |#.                      .#|                        |#.                      .#|                        |#.
           |#|                    |#|                          |#|                    |#|                          |#|                    |#|
            .|#|.              .|#|.                            .|#|.              .|#|.                            .|#|.              .|#|.
               |##||.      .||##|                                  |##||.      .||##|                                  |##||.      .||##|
                 .||########||.                                      .||########||.                                      .||########||.

Scale With Search  2026  [scalewithsearch.com](https://scalewithsearch.com)
```
