Your agent will send that email twice
Durable execution makes agent runs survive crashes and deploys. It does not make side effects happen exactly once. Here is where the duplicates come from and how to close each gap.
A customer-facing agent turn can call a model four times, hit three APIs, wait for a person to approve something, and take minutes. Pods get rescheduled and deploys roll in the middle of that, and a rate limit can trip halfway through a plan.
Here is the failure. A run sends the email, then dies before it records that it did. The retry starts from the top and sends it again. The fix everyone reaches for is durable execution, and it’s the right fix, but it gets oversold. Durable execution resumes a run after a crash. Whether the email goes out once is still your job, and that’s where the duplicates come from.
The examples use a store support agent that issues refunds and emails customers.
There is no exactly-once
Tyler Treat put it bluntly in 2015: you cannot have exactly-once delivery. A process that calls a payment API and then crashes can’t know whether the call landed. It either retries and risks a duplicate, or doesn’t and risks a missing refund. What real systems offer is at-least-once execution plus a receiver that recognizes a repeat. People call the result exactly-once, but it’s exactly-once effect, and you have to build the receiver half.
The engines’ own docs say so. DBOS says steps “are tried at least once but are never re-executed after they complete.” Temporal says an activity may run more than once and recommends making activities idempotent. Both mean the same thing: if the process dies after the API call returned but before the engine recorded the result, the step runs again on recovery.
What the engine does give you
A durable workflow records each step’s output as it completes. On recovery, a new process runs the workflow function from the top, and every step that already finished returns its recorded output instead of running. The email that went out and got recorded doesn’t go out again.
What it can’t cover is a step that was in flight. The ambiguous window runs from the moment the request leaves your process to the moment the checkpoint commits, so it’s as long as the call: seconds for a payment API, tens of seconds for a model call. A deploy that kills pods with work in flight lands in that window. Graceful shutdown helps by letting in-flight steps finish first, but an OOM kill or a node failure skips it.
Record the model calls too
The planning call is a step too, and it needs the same recording as the refund.
Suppose the agent plans “refund order A-1001, then email the customer,” executes the refund, and the process dies. On recovery, if the planning call runs again, the model can produce a different plan. Maybe this time it decides to offer store credit. Now you have a refund that went out under a plan that no longer exists, and a new plan that’s about to issue store credit as well. Each log line looks fine. Nothing in the trace shows the plan was regenerated, so you find out from the customer.
Model calls are the least deterministic thing in the system, so they have to replay from the record. For agents this is the main reason to put the whole loop in a durable workflow and not just the tool calls: on recovery, the run continues the plan it already made.
Streaming makes this visible to the user. If the process dies halfway through a streamed reply, the user has already read half a sentence. The recovered run calls the model again and gets a different reply, and the UI either shows a sentence that changes direction mid-thought or two answers that disagree. Either buffer the reply and commit it as a step before streaming it out, which costs you time to first token, or persist the chunks as they stream, replay them on recovery, and send the saved prefix back to the model to continue. The continuation is a new call, so it can still drift, but the user never sees text change after they’ve read it.
Checkpoints are not steps
LangGraph has persistence, and teams often assume it covers this. It covers part. A LangGraph checkpoint is written at step boundaries, so if a node calls two APIs and dies after the first, the whole node reruns on resume and the first call fires again. The durability modes are worth reading for what they leave open: in async mode the checkpoint is written while the next step is already running, and the docs note a small risk of losing it on a crash. The functional API says to put side effects in tasks so a resume doesn’t repeat them, and adds that a task that started but didn’t finish may run again.
I like LangGraph for control flow and a durable workflow engine for side effects. With DBOS, every side effect is a step whose output lands in Postgres, in tables you can query when something looks wrong. LangGraph decides what happens next. The engine makes sure finished steps don’t run again.
Combining them causes two problems. You now have two persistence layers, the LangGraph checkpointer and the workflow engine, and after a crash they can disagree about where the run is. Pick one as the source of truth. I’d make the engine authoritative and treat the graph state as something rebuilt from recorded steps. And replay matches recorded steps to calls in the order they start. Parallel nodes can start their steps in a different order on recovery, so a recorded result gets handed to the wrong call. Give parallel steps deterministic identities, or run side effects from one branch at a time.
Close the gap with keys the retry can reproduce
The in-flight window from earlier still exists, so every external call needs an idempotency key the retry will regenerate exactly.
# Same value on every retry of this step.
key = f"refund:{workflow_id}:{step_id}"
stripe.Refund.create(
payment_intent=payment_intent_id,
amount=amount_cents,
idempotency_key=key,
)
Derive it from the workflow ID and a stable step identity. Never from a UUID minted inside the step, because a retry mints a new one and the receiver sees a brand-new request. Never from a timestamp, for the same reason.
That key catches retries of the same step. Agents also duplicate intent. The customer asks for the refund in chat, gets impatient, and asks again by email: two workflows, two keys, two refunds. Or the model puts create_refund in its plan twice: two steps, two keys. When an action should happen once per business fact, build the key from the fact, as in refund:{order}:{items}, so the second workflow collides with the first.
A second request can arrive days later, after the receiver may have dropped the key (Stripe prunes after 24 hours), so the receiver’s key only guards retries that land within a day. A step that can retry later than that should look the effect up by your own reference before causing it.
Catching a repeated intent needs your own ledger: a table with a unique constraint on the business fact, holding the workflow ID that claimed it, written before the call. A run that finds its own row carries on with the same key. A run that finds someone else’s row stops. Delete the row if the call fails for good. Use workflow and step keys only for actions where a repeat is legitimate, like a second reminder email, and decide which kind each tool is when you write it.
Then read the fine print of each receiver. Stripe stores the result for an Idempotency-Key, returns the same response on a retry, including a stored 500, and errors if the same key arrives with different parameters. That stored 500 matters: a durable step that retries with the same key gets the same 500 back every time, so retrying can’t succeed. On a stored error, look the refund up by your own reference before deciding whether a fresh key is safe.
A request that collides with one still executing under the same key gets an error with no saved result. That’s the case where a slow original attempt, from a process you thought was dead, overlaps its own recovery. Treat that error as “unknown, try again shortly,” never as success or failure.
Many APIs take no key at all. SMTP is the classic one. For those, in the order I’d try them:
- Use the provider’s own deduplication if it has one, such as a message ID or reference field you set and can query.
- Write the intent to your database first, and have a separate relay send it and mark it done. This is the transactional outbox, and its own docs say the relay can publish twice, so the receiver still has to tolerate a repeat.
- Accept a rare duplicate and make it harmless. A second “your refund is on its way” is embarrassing. A second refund is a finance ticket.
Brandur Leach’s post on Stripe-style idempotency keys in Postgres is the best long treatment of the receiving side. If you own the API your agent calls, build it that way.
Deploys are the other crash
Replay works by running your workflow code again and matching each step to a recorded output, in order. Anything non-deterministic outside a step breaks that match: the current time, a random ID, iteration over a set. So does a code change. Reorder two steps in Tuesday’s deploy and a run that started Monday replays Tuesday’s code against Monday’s history.
DBOS handles this by recovering workflows only on processes running compatible code. Temporal has patching for branching on version. Both push the same choice onto you: keep old code alive until its runs drain, or branch explicitly.
Agents add one problem ordinary workflows don’t have: the prompt is code too, and it changes between deploys. Change the system prompt and a recovered run’s recorded model outputs no longer match what the new prompt would have produced. Usually nothing breaks, because the recorded outputs replay. But every model call after recovery runs under a prompt the earlier steps never saw, so the run finishes as a hybrid of two agents.
Tool schemas are code too. If Tuesday’s deploy renames amount to amount_cents, the replayed plan calls a tool that rejects its arguments. If the deploy instead keeps the name and changes the unit to cents, the replay goes through and refunds a hundredth of what the plan meant. A floating model alias causes the same split more quietly: the steps after recovery are planned by a different model than the steps before. Short runs can ignore this. Runs that wait days on a human should pin the prompt, the tool schemas and the model ID when the run starts, and load them from there on recovery.
The payoff is waiting
Once a run survives a crash and a deploy, a pause costs one database row. The agent can ask for approval at 6pm and continue at 9am. It can email a customer and resume when they reply three days later. Neither works if the process has to finish before the next deploy.
Sources
- Tyler Treat, You cannot have exactly-once delivery (2015)
- DBOS, Workflows tutorial and Architecture
- Temporal, Activity definition and Workflow definition
- LangChain, LangGraph durability modes and functional API
- Stripe, Idempotent requests
- Brandur Leach, Implementing Stripe-like idempotency keys in Postgres (2017)
- Chris Richardson, Pattern: Transactional outbox