Retry-Safe AI Agents Need Stable Effect IDs
An agent can retry a thought. It must not casually retry an effect.
That distinction sounds obvious until a process dies between two facts: the external system accepted an action, but the agent runtime did not record the response. On restart, the runtime sees an unfinished step. The model sees an open goal. Both are tempted to try again.
The result can be a second ticket, a repeated notification, another deployment request, or a duplicate mutation. Better prompting cannot resolve this ambiguity. The missing primitive is stable effect identity: a runtime-owned name for the one logical change the workflow intends to make.
This article develops that primitive as a small protocol. It does not claim exactly-once execution across arbitrary systems. It shows how to make retries converge when the destination supports idempotency or when an adapter owns a durable deduplication record.
Three candidate identities—and only one survives a retry
A tool invocation usually has several IDs available:
| Candidate | What it identifies | Why it fails as an effect ID |
|---|---|---|
| inference ID | one model response | a retry creates another response |
| attempt ID | one execution attempt | it changes precisely when deduplication is needed |
| effect ID | one intended external mutation | it remains stable across attempts |
This is the key separation. An attempt is an operational event. An effect is a business-level intention.
If an agent retries create_issue, the new attempt should have a new attempt_id for observability but retain the same effect_id for deduplication. If the agent genuinely decides to create a second issue, that is a new effect and must receive a new identity. The runtime—not the language model—must decide which case applies.
A compact envelope can make the distinction explicit:
{
"effect_id": "run-7/task-12/publish-report/v1",
"attempt_id": "attempt-3",
"tool": "issue.create",
"target": "repo:acme/service",
"payload_hash": "sha256:…",
"base_revision": "report:8f2c…",
"expires_at": "2026-07-15T08:30:00Z"
}
The exact syntax is not important. The invariants are:
- the effect ID is generated before the side effect;
- it is stable across transport and worker retries;
- it is bound to the tool, target, and canonical payload;
- reusing it with a different payload is an error;
- the resulting receipt is stored before the step is declared complete.
Stripe documents the same defensive behavior at an API boundary: repeated requests with one idempotency key return the saved result, while reuse with different parameters is rejected. Temporal recommends idempotent Activities because a worker can complete an external operation and crash before reporting completion; its documentation suggests combining workflow-run and activity identities into a stable key.
The effect record is a state machine, not a cache entry
Calling this a “dedup cache” undersells the problem. A cache can be evicted without changing correctness. An effect record is part of execution truth.
I would model it with explicit states:
PROPOSED -> AUTHORIZED -> DISPATCHED -> CONFIRMED
| |
v v
UNKNOWN REJECTED
UNKNOWN matters most. It means the request may have reached the destination, but the runtime cannot prove whether the effect happened. A naive retry policy converts uncertainty into duplication. A reliable runtime first asks the destination for the result associated with the same effect ID. If the destination cannot answer and does not support idempotency, the system should stop for reconciliation rather than invent certainty.
This extends the idea in Agent Change Sets. A change set names the proposed mutation and its base revision. Effect identity names the authorized attempt to make that mutation real. The first artifact is reviewable intent; the second is retry-safe execution lineage.
It also sharpens Why I Want Recoverable Agents. A checkpoint can recover internal state, but it cannot by itself prove what happened outside the process. Recovery needs a join between checkpoint, effect record, and destination receipt.
A five-step execution protocol
1. Canonicalize the intent
Before authorization, normalize the tool name, target, operation, payload, and relevant base revision. Hash this canonical form. Do not hash raw model prose; hash the typed action the executor understands.
2. Allocate the effect ID outside the model
The runtime derives or allocates the ID from stable workflow coordinates: workflow, logical task, operation, and artifact revision. Random IDs can work if persisted before dispatch, but generating one inside each retry defeats the purpose.
3. Authorize the exact envelope
Approval should bind the effect ID and payload hash. This prevents a retry from quietly changing arguments while presenting itself as the same approved action. The principle matches the blog’s broader distinction between probabilistic proposals and deterministic authority in Agent Policy Should Be Executable.
4. Dispatch through an idempotent boundary
Pass the effect ID to the destination’s native idempotency mechanism when available. Otherwise, place a durable adapter in front of the destination. For local database-plus-message operations, a transactional outbox can atomically record state and the event to be delivered; AWS’s pattern guidance still warns that consumers must tolerate duplicate delivery.
5. Persist a receipt and resolve ambiguity
A receipt should bind at least:
effect_id + payload_hash + destination_id + outcome + observed_at
On retry, the executor looks up the effect ID first. CONFIRMED returns the previous receipt. REJECTED returns the previous rejection. DISPATCHED or UNKNOWN triggers destination lookup or human reconciliation. Only an absent record allows a first dispatch.
The hard boundary: idempotency is not semantic equivalence
Two prompts that “mean roughly the same thing” are not one effect. Two payloads that create equivalent-looking final text are not safely interchangeable. Deduplication requires an identity and comparison rules that deterministic code can enforce.
Nor does an idempotency key make every operation reversible. Sending an email twice may be preventable; unsending the first email is not. Provisioning can be made convergent toward a named desired resource, while arbitrary shell commands may have no safe replay semantics at all.
This produces a useful tool classification:
| Effect class | Retry rule |
|---|---|
| pure read | retry under normal transport policy |
| convergent write | retry with stable resource/effect identity |
| append/create | require destination deduplication or durable adapter |
| irreversible external action | require effect identity, receipt, and often approval |
| unknown semantics | fail closed; no automatic retry |
The model may propose the class, but the tool registry must declare and enforce it.
Boundary conditions
This protocol does not guarantee exactly-once behavior if the destination neither accepts an idempotency key nor exposes a lookupable business identifier. It does not solve malicious destinations, expired deduplication windows, or actions whose payload cannot be canonicalized. It also requires retention to match the workflow’s maximum retry and recovery horizon; deleting the effect record too early reopens the duplication risk.
Those are not reasons to abandon the mechanism. They are reasons to label unsupported effects honestly. “Not safely retryable” is a valid tool contract.
The engineering rule
Retries belong to the runtime, not to the model’s improvisation loop.
A production agent should be able to answer three questions before repeating any write:
$ what logical effect is this?
$ did that effect already reach the world?
$ can the destination return the same result safely?
If it cannot answer them, it does not have retry semantics. It has repetition with hope.
Stable effect identity turns that hope into a protocol: new attempts remain observable, one logical effect remains singular, and uncertainty becomes an explicit state instead of a duplicate action.