Idempotency Patterns for Agent-Triggered Email Sends
Stable operation IDs, API keys, and inbound dedup stop duplicate sends.

Fourteen copies of the same welcome email landed in one mailbox because a socket timeout fired after the message had already been enqueued, and three separate retry mechanisms each tried to finish the job they thought had failed. Fixing it means treating idempotency as a property that must hold at every layer of the pipeline at once, from the moment an intent forms to the moment a message reaches an inbox. For teams running transactional and marketing mail through one API, the same mechanism decides whether a receipt or a campaign goes out once or several times.
Why agent-triggered email sends are structurally prone to duplication
A person who clicks send and watches a spinner makes a judgment call about whether to try again. An agent that gets back a timeout, a 5xx, or a response it can't parse learns only that it lost certainty about what happened, not that the send failed, so its default move is to retry. That difference, between a system that waits for confirmation and one that treats ambiguity as failure, is the root of almost every duplicate-send incident in agent infrastructure.
The fourteen-email case shows how fast this compounds. Fourteen sends reached one recipient. The post-mortem language was "the agent acted weirdly," but the actual cause was a non-idempotent operation sitting inside a system built on at-least-once delivery.
At-least-once delivery is not a flaw to patch out of the stack. A single logical intent to "send this email" can fan out into several real external writes simply because no layer knows the others exist.
Idempotency at each layer of an agent pipeline
An operation is idempotent if running it once and running it several times leave the same result behind: the email arrives once, no matter how many times the send call fires.
A workable model for agent pipelines separates idempotency into three layers. Layer 3 is the idempotency key passed at the API boundary: a deterministic key built from the action's parameters, handed to the email API so the provider itself can catch a duplicate before it sends.
A documented "ghost order" failure shows that having all three layers matters because each one closes a gap the others leave open. The operation ID is what keeps the key stable across every retry that follows.
Layer 1: generating a stable operation ID before any external call
A stable operation ID, assigned the moment an intent forms and never regenerated afterward, is the anchor that every other deduplication layer depends on. If this ID drifts across retries, nothing built on top of it can hold.
The operation ID also solves a timing problem that the API key alone cannot. Where possible, the ID should be deterministic, built from a stable hash of the intent's own parameters (the recipient's address, the message type, the ID of the event that triggered it) so that even if state gets lost somewhere in the pipeline, the same inputs reconstruct the same ID.
Closing Layer 1 means logging every completed action against this ID, checking the log for that operation ID before a send executes and returning the logged result instead of making the call again if a completed record already exists. Several durable execution frameworks expose primitives that map onto this directly. DBOS treats a workflow ID as an idempotency key. Inngest deduplicates over a 24-hour window keyed on an event ID. BullMQ drops a job outright if its jobId already exists. In each case, the operation ID is what an agent's internal state maps onto the framework's own deduplication mechanism.
Layer 2: idempotency keys at the API boundary and their limits
Once the operation ID exists, the right move is to pass it straight through as the idempotency key on the email send call, not to generate a separate key at call time. That keeps every retry of the same intent presenting the same key to the provider, which is what lets the provider catch a duplicate before it goes out.
Provider-scoped limits still create real gaps, though, even with a perfectly stable operation ID behind them. Inngest and Trigger.dev each maintain keys for a defined period, 24 hours and 30 days respectively, and a retry that lands after that window closes will produce a second send even though the operation ID never changed.
Temporal's own documentation is a clear example of how a framework's guarantee can be narrower than it sounds. The engine's record protects the engine's state. It does nothing for the recipient's inbox.
The practical consequence is that the idempotency key needs to go out on every send call, not only the ones the agent knows are retries, because the agent may have no way of knowing a prior attempt actually succeeded (a network error after the provider accepted the message looks identical, from the agent's side, to one that failed outright). Partial idempotency coverage, a stable operation ID without a matching API-level key, or a key without a stable ID behind it, leaves exactly the kind of gap agents will fall into under retry pressure. Treating the email API itself as a core part of the agent's architecture lasts longer: infrastructure built for autonomous sending can enforce idempotency keys as a baseline requirement rather than a setting a developer has to remember to turn on.
Layer 3: deduplicating inbound triggers and webhook replays before the agent acts
Not every duplicate originates inside the send logic. Webhook replays and queue redeliveries can start a second, third, or fourth agent run for an event the system already finished processing. Deduplication has to happen before the agent ever reaches Layer 1, not just inside it.
A common failure pattern: a pod processes an inbound request and starts a run successfully, but the edge proxy in front of it times out and returns a 502 to whatever triggered the request, even though the work upstream completed. With no deduplication at the point of entry, that retry starts a second agent run that proceeds through every downstream layer as though it were a brand-new intent, because as far as the system can tell, it is one.
The fix sits at ingestion: a sliding-window cache keyed on a hash of the sender's ID and the request bytes, so any payload that's byte-for-byte identical to one received recently gets rejected before any agent logic runs. This keeps the downstream layers from ever having to absorb events that should never have reached them twice. The handler pattern that closes this is the same operation-ID logic applied upstream: store processed event IDs durably the first time they arrive, and on any later delivery of that same ID, return success without running the agent logic again.
For tools built on a standardized protocol for agent-tool communication, the surface this covers has grown. One formal treatment of agents that orchestrate irreversible state changes, published in August 2026, states the requirement precisely: under a fault model that admits retries and at-least-once delivery, a session's effect on the system must come out as either nothing at all or exactly the transition that was shown to the user, exactly once. Guidance on MCP security has recommended that MCP messages carry expiration timestamps and replay-protection metadata, and a revision to the MCP specification in July 2026 removed protocol-level session tracking. The practical effect is that responsibility for idempotency state has shifted onto the tool author: each request has to carry its own idempotency information since session continuity is no longer built into the protocol itself.
Responsibility distribution across these three layers in durable execution frameworks
Durable execution frameworks take over a meaningful share of the idempotency work described above, but none of them cover all three layers at once, and each vendor's "exactly once" language describes what the engine records internally, not what happens to the external email send.
A comparison of frameworks published in October 2026 lays out what each one actually guarantees. Restate guarantees that each invocation "runs exactly once regardless of failures," replaying its journal past any step already completed after a crash, but a ctx.run block that throws gets retried, so a side effect inside it can still run twice; Restate does ship a built-in Idempotency-Key header with a 24-hour window. Trigger.dev keeps idempotency keys for 30 days but retries an entire run from the top on failure, so a model call and a send sitting in the same task both repeat; the key stops the task from triggering twice, not the code inside it from running twice.
The pattern across every one of these is the same: each framework retries a unit of code, and what happens inside that unit, including the actual HTTP call to an email provider, sits outside the framework's view. The idempotency key passed to that provider is always the tool author's responsibility, never the framework's. Two independent retry engines compound on top of each other, and the email send sits inside both of them. Choosing a durable execution framework reduces the work needed at Layers 1 and 2, stable IDs and trigger deduplication become largely automatic, but it does not remove the need for an idempotency key at the API boundary, and it does nothing about what the email infrastructure itself does once that key arrives.
Email infrastructure's role in enforcing idempotency independent of the agent
Even an agent that gets every layer right, a stable operation ID, a correctly passed idempotency key, a framework that records the step as complete, can still produce a duplicate send if the email infrastructure on the receiving end doesn't enforce deduplication on its own. If the API accepted both the original call and a retry before the framework's internal record was even written, the message goes out twice regardless of how carefully the agent behaved upstream.
Closing that gap means the infrastructure has to treat an incoming idempotency key as a first-class input: if a send carrying that key was already accepted, the correct response is to hand back the original result, the message ID and status, without queuing a second message. That behavior is what makes the key load-bearing. For an autonomous agent making thousands of calls with no human reviewing any of them, that key has to be load-bearing from the start.
This is precisely why email infrastructure built for autonomous workflows needs guardrails that run before a message ever reaches delivery, catching duplicate intent at the point of send rather than leaving idempotency keys to carry the whole burden after the fact, which is the problem GIC - Agent Send, an email infrastructure platform built from the ground up for AI agents rather than adapted from human-operated tooling, addresses through pre-send linting that intercepts malformed or duplicate sends before they reach delivery. A correctly deduplicated message can still be malformed, a failure that idempotency keys alone don't catch.
Compliance headers belong in this same category of correctness, not as a separate checklist item. Infrastructure that enforces this by default takes it off the list of things a developer or an agent has to remember to configure correctly on every single call.
How reputation damage from duplicate sends compounds
Duplicate sends caused by idempotency failures damage a sending domain's reputation at software speed, while rebuilding that reputation happens at the speed of human trust returning. That mismatch is why prevention, not cleanup, is the only strategy that actually works here.
Gmail and Yahoo's current sender rules require spam complaint rates to stay under 0.10%. A Needs work status doesn't just lower deliverability; it puts mail at risk of outright SMTP rejection.
Shared sending infrastructure makes the blast radius bigger. When several agents send from the same domain or IP pool, one agent's idempotency failure, a single retry loop producing a burst of duplicates, drags down reputation for every other agent and every legitimate send sharing that infrastructure, and figuring out afterward which agent caused it becomes close to impossible. Agents can also ramp sending volume the way software ramps anything: instantly. Storing the operation ID durably before any call leaves the system is the exact point where an agent's internal state hands off to the external email system, and when the idempotency key that reaches the API is derived from that same ID, the provider has what it needs to deduplicate with confidence, which is also why infrastructure built for agents keeps transactional and marketing sends under one API rather than splitting deduplication logic across separate platforms.
A layered idempotency checklist for agent email sends in production
Reliable agent email sending depends on all three layers holding at once, since each one closes a failure mode the others cannot reach on their own. None of this is complete without an audit trail: the action log needs to record the operation ID, the recipient, the message type, the timestamp of the attempt, the API's response including whichever idempotency key was used, and the final outcome, and a retry that gets correctly caught and deduplicated should leave a visible entry showing that it was caught.
One failure sits outside everything this checklist can fix. An LLM planner instructed to "generate a unique ID" on each attempt, rather than told to reuse the ID from the original attempt, will produce a new operation ID every time it retries, and a new ID defeats every layer built beneath it no matter how well each of those layers was designed. The systems architecture described here closes the failure modes that come from retries, timeouts, and replay. The one failure mode it cannot close comes from how the agent itself was instructed to think about identity in the first place, making idempotency a prompt design problem as much as an infrastructure one, and no amount of engineering at the API boundary substitutes for getting that instruction right.
Sources
- Safety Invariants for Agents Orchestrating Irreversible State Transitions: A Four-Dimensional Formalism Evaluated on Public Ledgers
- Retries and idempotency for AI agent tool calls (2026): retry policy, activity idempotency, idempotency keys, and at least once vs exactly once in durable execution — Cadenya


