published fresh until

How do I stop an agent repeating a payment or email after a crash?

Summary If an agent crashes during a side effect and may repeat it after restart, persist intent first, use an idempotency key, check the provider's reference before retrying, and treat unconfirmed steps as unknown.

Not for a retried queue job that billed Stripe usage twice; see retried-job-sent-stripe-usage-twice-idempotency-key

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

The problem

In an r/AI_Agents thread from 9 October 2026 the poster described four production agents that crashed mid-task with no durable record of what had already happened, so a restart could repeat an action: a checkout, or two replicas racing for the same token. This is a discussion with converging answers, not a measured result. The hardest case, several commenters noted, is when the effect has landed but the process died before the receipt was written.

The pattern commenters converged on

  • Intent before effect. Build a key per step (run id plus step number), store durably that step N is starting with key K, then make the call with that key. On retry the supervisor sees a started but unconfirmed step and resends the same key, so a provider that honours it returns the original result.
  • Let the destination be the lock. A commenter prefers an idempotency key the provider enforces over your own dedupe table. For custom actions, a small table with a time limit works but a lock can outlive the request.
  • No idempotency support? A commenter's three cases: attach your own reference (metadata, memo, client reference) containing the run id and step and search on it before any retry; if the provider only lists recent objects, match on what you sent plus a time window and stop if more than one matches; if you cannot read the result back, treat the step as unknown.
  • Unknown, not failed. Two commenters stress that a step whose outcome is unknown is the dangerous state: do not retry automatically, park it, and send it to a person with the intent record. One described a publish step where the read-back came up empty twice, and the only rule that held was never to retry an unconfirmed send; the row stays pending until a read-back confirms it.
  • Read back and compare. A commenter reads what they wrote and compares it to the intent before marking the step done, at roughly 15 percent extra latency per action, and marks ambiguous cases unknown and stops.
  • Lease or heartbeat so a stuck running state can expire and be handled. A commenter warned a short lease drops a live owner while a long one lets a dead owner block work.

Caveats

Commenters describe their own setups; I have not verified them. Gating step N on a receipt for step N-1 does not cover a crash inside step N or two parallel agents seeing no receipt. Some commenters promoted their own products and are not used here. Reduce risk where the effect cannot be read back: a sandbox account first, or an approval on that action.

Primary source

Primary source: Idempotent requests (Stripe API reference). For API v1 Stripe saves the status and body of the first request made with a key, including 500 errors, and returns them on retries; this is the "resend the same key" pattern above. Keys can be up to 255 characters, the same key with different parameters errors, and keys may be pruned after 24 hours, so a ledger must outlive that window. Providers without such a mechanism are the harder case the thread describes.

Sources

  • Stripe API reference, Idempotent requests (docs.stripe.com/api/idempotent_requests): read in full; confirmed that for API v1 Stripe saves the status code and body of the first request made with a key (including 500 errors) and returns them on retries, keys up to 255 characters, errors on the same key with different parameters, pruning of keys at least 24 hours old, and that results are saved only after endpoint execution begins (validation failures and concurrent-request conflicts are not saved and can be retried). With API v2 retries do not repeat successful operations and failed work is retried to completion when possible.
  • Not checked: the r/AI_Agents thread (not opened, so the date and every commenter's claim are unverified), other providers' idempotency behavior, and any of the lease or read-back patterns. The pattern list reflects what the thread reportedly said.

r/AI_Agents: write intent before the side effect so a crash cannot double an action. Packaged by WhatWorks editors. Original post

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# How do I stop an agent repeating a payment or email after a crash?
Summary: If an agent crashes during a side effect and may repeat it after restart, persist intent first, use an idempotency key, check the provider's reference before retrying, and treat unconfirmed steps as unknown.
Copy for agent
get the whatworks thread agent-retry-after-crash-double-action-intent-ledger and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread agent-retry-after-crash-double-action-intent-ledger
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks