The agent had checkpoints. The customer still got refunded twice.

TL;DR

  • A checkpoint is saved after a step finishes.
  • A crash between a payment call and that save makes the resumed agent pay again.
  • durability="sync" doesn't close that gap. An idempotency key built from stable run ids does.

A story: the names and numbers are invented, the failure is real.

What happened

I shipped a refunds agent on a Tuesday. LangGraph, a Postgres checkpointer, every step saved. I had read the docs. If a pod died, the run would pick up where it left off. I was proud of that.

On Thursday, Maya from Acme's finance team sent me a screenshot. Order 9 had two refunds. Same amount, four minutes apart.

I pulled the logs and rebuilt the morning:

  1. The agent read the ticket and decided a refund was due.
  2. It called the payment API. The API said "created".
  3. A deploy went out. Kubernetes evicted the pod.
  4. The orchestrator resumed the run from the last checkpoint.
  5. The last checkpoint was from before the refund. So the agent refunded again.

Nobody wrote a bug. The checkpoint did exactly what it promises. I had just believed it promised more.

🧙 When I'm stuck, I open the one reference that doesn't hand out answers. AI Wisdom isn't a friendly tutor. It's a guru, and it makes you earn the fix.

Draw the problem

Beginner view: the cashier and the ledger

A cashier pays out a refund, then writes it in the ledger. If the cashier faints between the two, the next cashier checks the ledger, sees nothing, and pays again. The ledger was right about everything it saw. It just never saw the payment.

%%{init: {"themeVariables": {"fontSize": "16px", "lineColor": "#8B97A8"}}}%% flowchart LR C1(["Cashier 1"]):::person -->|"1. pays the refund"| Cu["Customer"] C1 -.->|"2. faints before writing it down"| L[("Ledger: no refund")] C2(["Cashier 2"]):::person -->|"3. checks the ledger"| L C2 -->|"4. pays again"| Cu2["Customer, paid twice"]:::bad classDef person fill:#1e3a5f,stroke:#22d3ee,color:#ffffff classDef ok fill:#123524,stroke:#34d399,color:#ffffff classDef bad fill:#3b1d1d,stroke:#f87171,color:#ffffff

Technical view: the same morning as calls

%%{init: {"themeVariables": {"fontSize": "16px", "lineColor": "#8B97A8"}}}%% sequenceDiagram participant W as Workflow participant S as Checkpoint store participant P as Payment API W->>S: save step 1 W->>P: refund (order 9) P-->>W: created Note over W: pod evicted before the next save W->>S: load last checkpoint S-->>W: step 1 W->>P: refund (order 9) P-->>W: created (second refund)

A checkpoint is saved after a step finishes. The crash landed in the gap between the payment call returning and that save.

Do you have this problem?

  • Your agent has tools that change something real: payments, emails, deployments
  • A key in your tool calls comes from uuid4() inside the step
  • Something with a side effect sits before an interrupt() in the same node
  • A deploy in the middle of the day kills in-flight runs

I ticked three. How many do you tick?

The fix that is a trap

My first move was to tighten durability. LangGraph has three modes, and sync saves before the next step starts. I'd still use it for anything with side effects, because a few milliseconds per step is nothing next to a double refund.

But it doesn't close this gap. The call returns, the pod dies, the save never happens. Only the system on the other end of the call can settle that.

Where each attempt lands:

What I tried What it fixes What it leaves open
durability="sync" Saves before the next step starts The gap between the call returning and the save
Key from uuid4() inside the step Nothing: every retry gets a new key The second refund
Key from stable ids: refund:{run_id}:{order_id} A retry returns the first refund Nothing, for this failure

The real fix: a key the payment system remembers

@task def issue_refund(order_id: str, amount_cents: int, run_id: str) -> str: # Built from stable ids in the run's input, so a retry # returns the first refund instead of creating a second. refund = payments.refunds.create( order=order_id, amount=amount_cents, idempotency_key=f"refund:{run_id}:{order_id}", ) return refund.id 
%%{init: {"themeVariables": {"fontSize": "16px", "lineColor": "#8B97A8"}}}%% flowchart TD R(["Run resumes after the crash"]):::person --> T["issue_refund runs again"] T --> K{"Where does the key come from?"} K -->|"refund:run_id:order_id"| Same["Payment system sees the same key"] Same --> One["Returns the first refund"]:::ok K -->|"uuid4() inside the step"| New["New key on every retry"] New --> Two["Second refund"]:::bad classDef person fill:#1e3a5f,stroke:#22d3ee,color:#ffffff classDef ok fill:#123524,stroke:#34d399,color:#ffffff classDef bad fill:#3b1d1d,stroke:#f87171,color:#ffffff

Look at where the key comes from. If I had written idempotency_key=str(uuid4()) inside the step, every retry would get a new key, and the key would protect nothing.

The second trap: what sits before the approval

Refunds over a limit wait for a manager, with interrupt(). When the run resumes, the node restarts from its beginning. So anything with a side effect placed before the interrupt in the same node happens again: the "approval requested" email, the Slack ping, the audit row.

Put side effects in a @task, or in a separate node after the approval. The rule I work by now: a model call may repeat, but a side effect may not.

Prove it

Don't trust the reasoning. Run it:

  1. In staging, kill the worker straight after the payment call returns and before the checkpoint is written.
  2. Let the run resume.
  3. The payment system should see the same key and refuse to pay twice.

Do this in the durability mode you actually ship. Most teams learn more from this one test than from a week of design discussion.

The guru's last word

Durability keeps a run alive. It doesn't make it safe to repeat.

Go deeper

My refunds are fixed. The rest of running agents that survive crashes is in the full guide:

  • LangGraph's three durability modes side by side, and what each one risks
  • When the graph is enough, and when to put the agent inside Temporal or a similar workflow engine
  • Why deploys break workflows that paused two days ago, and how to version state
  • The sandbox side: container vs gVisor vs microVM for model-written code, deny-by-default egress, and keeping credentials out of the sandbox entirely

👉 Read the full guide on AI Wisdom

Which Amit are you?

Open the tool in your agent with the most expensive side effect and look at where its idempotency key comes from. Reply with one:

  • stable run and order ids
  • a UUID inside the step
  • no key at all