Worker crashes after effect but before ledger update
Detect: Operation remains pending while the business record exists.
Recover: Query the downstream key or business identity and record the confirmed result.
Make repeated attempts at one business operation converge on one recorded effect, even when agents, queues, or networks deliver the request more than once.
Idempotent execution lets a caller safely repeat an operation without repeating its intended business effect. Agent systems need this because model loops, worker recovery, queue redelivery, and network timeouts can all create duplicate attempts. The idempotency identity belongs to the business operation, not to an individual HTTP attempt.
Persist the key with a canonical request fingerprint and the operation result. A repeated key with different parameters must be rejected rather than silently treated as the original request. Exactly-once delivery is generally not the useful promise; design for repeated delivery with controlled effects and explicit reconciliation of uncertain outcomes.
A prototype can assign one stable key to each simulated command and test duplicate submission. Do not generate a fresh key inside retry logic.
Production atomically claims operation identity, stores status and results, and coordinates with the actual side effect. If the remote system cannot participate, use its idempotency support or a reconciliation protocol.
At scale, choose key scope and retention from the maximum replay horizon. Expiring keys too early allows delayed duplicates, while retaining them indefinitely increases storage and data-management cost.
Names the intended business action across retries, workers, and model turns.
Canonicalizes meaningful parameters and detects conflicting reuse of a key.
Atomically tracks pending, completed, failed, and uncertain operation outcomes.
Passes stable identity to supported downstream APIs and normalizes responses.
Resolves ambiguous outcomes using authoritative business records before another attempt.
sequenceDiagram
participant A as Agent worker
participant L as Idempotency ledger
participant T as Order service
A->>L: Claim operation key and request hash
L-->>A: New operation accepted
A->>T: Create replacement with stable key
T-->>A: Replacement identifier
A->>L: Store completed result
A->>L: Retry same key after lost response
L-->>A: Return existing replacement resultstateDiagram-v2
[*] --> Unseen
Unseen --> Pending: Atomically claim key and fingerprint
Pending --> Completed: Authoritative effect confirmed
Pending --> Uncertain: Response lost
Uncertain --> Completed: Reconciliation finds effect
Uncertain --> Pending: Safe retry with same key
Completed --> Completed: Same key and same intent
Pending --> Conflict: Same key with changed parameters
Completed --> Conflict: Same key with changed parameters
Conflict --> [*]Derive or create a stable key for the specific business intent and tenant scope.
Compare canonical parameters with any existing entry for that key.
Atomically reserve the operation or return the already recorded result.
Invoke the downstream command with matching idempotency support where available.
Store the authoritative outcome and response reference before acknowledging completion.
If confirmation is lost, query operation status and reuse the same key for any permitted retry.
Retail fulfillment · Illustrative enterprise scenario, not a reported customer outcome.
A retailer's assistant creates replacement shipments after staff approve damaged-product cases.
The shipping API can accept a request and then lose the response, causing the agent to issue a second shipment.
The assistant must recover from uncertainty without sending duplicate goods.
A replacement operation key binds the claim, order line, approved quantity, and tenant to an idempotency ledger and downstream request.
If the same key arrives with a changed address or quantity, the gateway rejects the conflict and requires a new explicitly authorized business operation.
Measure duplicate effects, unresolved operations, conflicting-key reuse, and reconciliation latency. The ledger alone cannot guarantee safety if the external command bypasses its protocol.
| Decision | Benefit | Cost |
|---|---|---|
| Durable deduplication | Retries become safer across worker and network failure. | Every command requires storage and identity discipline. |
| Long retention | Delayed replays remain protected. | Ledger size and retention obligations increase. |
| Downstream idempotency | The effect boundary can enforce duplicate prevention directly. | Provider semantics and key scope must be understood. |
Detect: Operation remains pending while the business record exists.
Recover: Query the downstream key or business identity and record the confirmed result.
Detect: Replay arrives outside the deduplication window.
Recover: Align retention with replay horizons and add business-level uniqueness where possible.
Create the key once per business intent.
Persist identity across restarts and workers.
Use explicit operation identity and canonical parameters.