# How to Prevent Duplicate Actions in AI Agents

> Learn how to prevent duplicate actions in AI agents with stable keys, reconciliation and safe retries, including when to stop and request human review.

![How to Prevent Duplicate Actions in AI Agents](https://agentic-ai.nicheflash.com/media/articles/3089-irw4xmhnmtra-16x9.jpg)

- Source: https://agentic-ai.nicheflash.com/blogs/prevent-duplicate-actions-ai-agents
- Author: [Agentic AI Editorial Team](https://agentic-ai.nicheflash.com/authors/agentic-ai-editorial-team)
- Publisher: Agentic AI
- Published: 2026-12-01
- Updated: 2026-12-01

To prevent duplicate actions in AI agents, enforce a stable operation identity and idempotency at the tool and external-service boundary. Do not rely on the model to remember whether it has already acted. Keep a durable action record and reconcile uncertain outcomes: preventing a second effect does not establish whether the first one succeeded.

 ## How duplicate actions happen

 A duplicate is a repeated external effect for the same business operation, such as issuing the same refund twice. A provider can apply a payment before the caller records completion; a blind retry can repeat the payment, while refusing every retry can leave the operation stuck.[1]

 Idempotence means repeated requests have the same intended effect as one request. The responses need not be identical; that depends on the service contract. The practical goal is an *effectively-once business outcome*, even if requests or processing steps run more than once.[1]

 ## Give each business operation a stable identity

 1. **Create an operation ID before the agent acts.** For example, create a refund-request ID when a refund is authorized. Every retry, worker and restarted workflow must retrieve that ID rather than generate a new one. A separately authorized refund gets a new ID and key.
2. **Atomically create or claim the action record.** Enforce a uniqueness constraint on the business operation ID so competing workers converge on one record. Persist the provider key and canonical request before dispatch. A worker that finds an in-progress record should wait or reconcile, not independently send a new request.
3. **Check the request on every attempt.** Store the canonical request or a fingerprint covering the amount, target and other effect-defining parameters. Reject a retry that differs from the stored request. A genuine change requires a new authorized operation, not a modified request under the old key.
4. **Carry the same key to the provider.** Follow its contract for concurrent same-key requests; do not assume the provider will safely handle simultaneous submissions. A local record alone cannot make a transaction atomic across your database and an external payment provider.[1]

 Recovery after a worker crash needs the same discipline. Reclaiming an abandoned local record does not prove the provider has stopped processing the original request. Reconcile or retry only as the provider contract permits.

 Identity must outlive a single workflow run. Temporal suggests combining a Workflow Run ID and Activity ID for retries of an activity, but that combination does not by itself identify the same business operation across separate workflow executions.[2] A completed activity does not re-execute merely because a workflow replays; an activity can run again if a worker performs the action and crashes before reporting completion.[2]

 ## Recover a timed-out refund without sending a second one

 Consider an illustrative refund: the provider applies it, but the response times out. The timeout proves neither success nor failure. Preserve the original ID, key and request, then track the operation through these states:

 - **Pending:** The request is being dispatched or processed. Competing workers must not create another operation. A timeout can move it to unknown because the original request may still be in flight.
- **Confirmed:** A provider response, lookup or webhook establishes that the original refund succeeded. Match the evidence to the stored operation using provider identifiers and the request details; record the evidence and report success.
- **Failed:** Authoritative provider evidence establishes that the operation failed without the intended effect and cannot still complete. Record that evidence before deciding what the provider contract and business authorization permit next.
- **Unknown:** Evidence is missing, delayed or inconclusive. A lookup that finds nothing is not proof of failure while the request could still commit. Keep the operation on hold, continue permitted reconciliation and route unresolved cases to a human without issuing a new key.

 Process duplicate webhooks idempotently and verify that each event belongs to the original operation. An unrelated event or an inconclusive lookup must not resolve the record. For a Stripe API v1 network error, Stripe advises retrying with the same key and parameters within the first 24 hours; if the outcome remains unknown after that window, stop retrying and reconcile.[3] Track the applicable window from the original request, not from the timeout or a later retry, and stop automatic retries before key retention can no longer be relied on.

 For API v1, Stripe saves the first status and response body after endpoint execution begins, including a 500 response; it rejects a reused key with different parameters.[4] Stripe treats a 500 as indeterminate and recommends retrieving the object, inspecting the request and using webhook events to reconcile.[3] A cached error is therefore not proof that the refund failed. API v2 handles failed or partially failed work differently, so check the contract for the version in use.[4]

 ## Match controls to the service boundary and risk

 **What common controls cover**

| Control | Scope and limit |
| --- | --- |
| SQS FIFO deduplication | Retried SendMessage calls are deduplicated within a five-minute interval; that does not establish that a downstream payment happened once.[5] |
| Stripe API v1 key | Keys may be pruned once they are at least 24 hours old; reuse after pruning creates a new request.[4] |
| Stripe API v2 retry window | Stripe documents a different 30-day window and different handling of failed or partially failed work.[4] |
| Local action record | Preserves intent and status, but cannot alone make an external payment atomic with the local database.[1] |

 If a provider offers neither idempotency nor reliable reconciliation, record the attempted operation and prevent automatic redispatch after an uncertain result. Show the operator the original request, response or timeout, and available provider evidence. Require an explicit human decision before another action; do not present that path as guaranteed safe recovery.

 ### Failure-test checklist

 - **Concurrent attempts:** Start competing workers for the same operation. Expect one claimed record and one external effect, or an unresolved hold if the provider contract cannot safely resolve concurrent dispatch.
- **Crash after provider success:** Stop the worker before it records completion. On restart, expect reconciliation to confirm the original effect, not a second effect.
- **Timeout while in flight:** Delay the provider response while the request continues. Expect a contract-safe same-key retry or an unresolved hold, never a fresh key.
- **Duplicate webhooks:** Deliver the same event repeatedly. Expect one confirmed operation and no additional external effect.
- **Expired provider key:** Attempt recovery after the applicable retention window. Expect automatic dispatch to stop and the operation to remain on hold until evidence and a human decision resolve it.

 ## Why verification helps but cannot guarantee safety

 Read-back can be effective when the target can immediately resolve an uncertain outcome. In Jiapeng Li’s narrower lost-acknowledgment cases, instructed frontier models duplicated effects in 0.5% of episodes.[6] But a lookup can find nothing while the original request is still running, so verification alone cannot guarantee exactly-once effects without a bound on in-flight time.[6]

 The chart shows the reported effect of offering a key on every write.

 **Duplicate rates under experimental tool-contract conditions, not production incident rates**

| Contract condition | Duplicate rate (%) |
| --- | --- |
| Original contracts | 28 |
| Key offered on every write | 4 |

 Source: Li’s preprint, *Where Does Exactly-Once Live?*[6]

 Song Xu’s fault-injection study tested a broader runtime with authorization, an action ledger, target-side idempotency and reconciliation.[7] In 200 known crash-and-replay pairs, the full configuration recorded no repeated effects, versus 117 for each simpler baseline; without reconciliation, 100 out of 100 known post-effect crash outcomes remained ambiguous despite no observed duplicates.[7] Suppression and recovery are separate requirements.

 The stronger runtime achieved about one-seventh of fail-open throughput in that benchmark.[7] Choose controls proportionate to the consequence of a duplicate, without treating either experiment as a production guarantee.

 ## Sources

 - Jiapeng Li, *Where Does Exactly-Once Live? Model, Harness, and Tool-Contract Effects on Duplicate Side Effects in LLM Agents*.[6]
- Song Xu, *Idempotency Is Not Recovery: A Fault-Injection Study of Language-Model Agent Tool Actions*.[7]
- Shreya Gupta, *Your Event Arrived Twice: Building Idempotent Serverless Pipelines on AWS*, AWS Builder Center.[1]
- Stripe, *Idempotent requests*.[4]
- Stripe, *Advanced error handling*.[3]
- Temporal, *Activity Definition*.[2]
- Amazon Web Services, *Exactly-once processing in Amazon SQS*.[5]

## References

1. [Your Event Arrived Twice: Building Idempotent Serverless Pipelines on AWS | AWS Builder Center](https://builder.aws.com/content/3L0Zw5ryP6tkydedkRW8hTZQNzo)
2. [Activity Definition | Temporal Documentation](https://docs.temporal.io/activity-definition)
3. [docs.stripe.com](https://docs.stripe.com/error-low-level)
4. [docs.stripe.com](https://docs.stripe.com/api/idempotent_requests.md)
5. [Exactly-once processing in Amazon SQS - Amazon Simple Queue Service](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/FIFO-queues-exactly-once-processing.html)
6. [Where Does Exactly-Once Live? Model, Harness, and Tool-Contract Effects on Duplicate Side Effects in LLM Agents](https://arxiv.org/abs/2609.29095)
7. [Idempotency Is Not Recovery: A Fault-Injection Study of Language-Model Agent Tool Actions](https://arxiv.org/abs/2611.23353)

## Recommended

- [Upgrade Your AI Automation Desk](https://agentic-ai.nicheflash.com/out/105?b=3089&p=markdown): Browse monitors, keyboards, laptop stands, mice, webcams, desk pads, and accessories for building, testing, and managing AI workflows.
- [Build Your Agentic AI Workspace](https://agentic-ai.nicheflash.com/out/104?b=3089&p=markdown): Shop practical gear for AI builders and automation-focused professionals—monitors, keyboards, microphones, notebooks, webcams, security keys, and desk tools for faster research, writing, coding, and workflow automation.
- [Gear for Agentic AI Builders](https://agentic-ai.nicheflash.com/out/106?b=3089&p=markdown): Find developer-friendly keyboards, USB-C hubs, external SSDs, portable monitors, laptop cooling stands, and home office tools for shipping AI systems.

*Affiliate links: Agentic AI may earn a commission when you buy through them, at no extra cost to you.*
