
Durable Execution for AI Agents: Step Limits, Replay Traps
Durable execution for AI agents explained: why tool calls still run twice, step and history caps in Temporal, Inngest and Step Functions, and the fix.
- What: Durable execution saves an agent’s progress after every step, so a crash resumes the run instead of restarting it.
- Why it matters: Recovery only happens at step boundaries. Anything inside a step, including a tool call, can run twice.
- What to do: Size steps deliberately, pass idempotency keys to side effects, and budget steps against your engine’s history cap.
- Key stat: Inngest caps a function at 1,000 steps, which is about 500 agent turns at two steps per turn.
Durable execution for AI agents means running the agent loop on an engine that records each completed step, so a crashed or redeployed worker replays the log and continues from the last finished step. It removes repeated LLM spend after failures, but steps still run at least once, so tool calls need idempotency keys and step budgets.
Durable execution is a programming model in which a runtime persists the result of each step of a function to an event log. When the process fails, the runtime replays the function, returns saved results for finished steps, and executes only the remaining ones. Temporal, AWS Step Functions, Inngest, Cloudflare Workflows and Vercel Workflow all implement variants of it.
Durable execution for AI agents is the fix for a failure most teams discover in production. An agent plans, calls several tools, and is halfway through drafting a reply when the pod is evicted. A plain queue worker retries the whole job. That means paying for every LLM call again, and possibly issuing the same refund twice. Temporal’s own guidance is blunt about the underlying rule: Activities retry without limit by default, which it describes as “at least once” execution.
Most guides stop at “wrap your agent in a workflow.” They skip the two things that decide whether it works. First, recovery granularity is the step, not the line of code. Second, every engine caps how long a run’s history can get, and agent loops are unbounded by nature. This post covers both, with a runnable Node.js demo and a limits table built from each vendor’s documentation. If you are still choosing between one agent and several, start with our guide to single vs multi-agent orchestration.
How does durable execution for AI agents actually work?
The engine splits your code into a deterministic orchestrator and non-deterministic steps. The orchestrator decides what to do next. Steps do the I/O: LLM calls, tool calls, database writes. Each step’s result is written to the run’s history before the orchestrator moves on.
On a restart, the engine runs the orchestrator from the top. When it reaches a step that already has a recorded result, it returns that result without executing the step. Temporal’s TypeScript docs explain that side effects must go through Activities because Activity outputs are recorded in the Event History.
That is why the orchestrator must be deterministic. Temporal enforces it by running workflow code in a sandbox where Math.random(), Date and setTimeout() are swapped for deterministic versions. In that sandbox, Date.now() returns the time of the last Workflow Task completion and only advances when you await something.
For an agent, the mapping is simple:
- The agent loop (plan, choose tool, decide when to stop) is the workflow.
- Each LLM call is one step, because its output is non-deterministic.
- Each tool call is its own step, because it touches the outside world.
- Waiting for a human approval is a durable sleep or event wait, not a polling loop.
Why do tool calls run twice with durable execution for AI agents?
Tool calls run twice because the engine can only record a step after it finishes. If the worker dies after the side effect but before the result is saved, the log has no record of it. Replay will execute that step again.
We ran this exact failure in the sandbox. The demo below is a short journal-based runner on Node.js v22.23.4. It is not a real engine, but it reproduces the gap every engine has. The agent plans a refund, calls a payment tool, and replies. We kill the process right after the refund runs and before the journal write.
// durable.mjs: minimal journal-based runner (demo only)
import fs from 'node:fs';
const JOURNAL = './journal.json';
const load = () => fs.existsSync(JOURNAL)
? JSON.parse(fs.readFileSync(JOURNAL, 'utf8')) : {};
const save = (j) => fs.writeFileSync(JOURNAL, JSON.stringify(j));
export async function step(name, fn) {
const j = load();
if (name in j) { console.log(`replay ${name} -> cached`); return j[name]; }
const out = await fn();
if (process.env.CRASH_AFTER === name) process.exit(1); // simulated eviction
j[name] = out; save(j);
console.log(`execute ${name}`);
return out;
}
async function agentRun(runId) {
const plan = await step('llm:plan', async () => ({ action: 'refund', amount: 40 }));
const res = await step('tool:refund', async () =>
chargeCard(plan.amount, `${runId}:tool:refund`)); // fake provider; key is stable per step
const msg = await step('llm:reply', async () => `Refunded ${plan.amount}, ref ${res.id}`);
console.log('done ', msg);
}
Here is the raw output of both runs, first without an idempotency check at the payment provider, then with one:
=== USE_KEY=0 ===
execute llm:plan
CRASH after tool:refund ran, before journal write
-- worker restarts --
replay llm:plan -> cached
execute tool:refund
execute llm:reply
payments.log lines: 2 <-- customer refunded twice
=== USE_KEY=1 ===
execute llm:plan
CRASH after tool:refund ran, before journal write
-- worker restarts --
replay llm:plan -> cached
provider: duplicate key run-42:tool:refund, no new charge
execute tool:refund
execute llm:reply
payments.log lines: 1 <-- one refund
Note what replay saved: the llm:plan call was not repeated, so no tokens were spent twice. Note also what it could not save: the refund. Durable execution removed the cost problem but not the correctness problem.
How do you build the idempotency key?
Use a key that stays the same across retries of one step and differs across runs. Temporal’s blog suggests workflowRunId + '-' + activityId, which is constant across Activity retries. Then pass it to an API that honours it. Stripe accepts keys up to 255 characters and, for API v1, may prune them once they are at least 24 hours old. So a run that resumes days later can’t rely on Stripe alone. Record the key in your own table too. Our idempotency keys system design guide covers that table design.
What step limits do durable execution engines enforce?
Every engine caps the history of a single run, and long-looping agents hit it. This is the hidden constraint in durable execution for AI agents: the docs mention it, agent tutorials skip it.
- Inngest allows 1,000 steps per function. Its docs warn this is easy to reach with one step per loop item.
- Temporal limits a Workflow Execution’s Event History to 51,200 events or 50 MB, with a warning at 10,240 events or 10 MB.
- AWS Step Functions Standard Workflows fail when a single execution history reaches 25,000 events.
- Cloudflare Workflows on Workers Paid allow 10,000 steps by default, configurable to 25,000; the Free plan allows 1,024.
- Vercel Workflow on the default Node.js runtime caps a run at 25,000 events and 10,000 steps.
How many agent turns fit in one run?
Convert the cap into turns before you ship. A typical agent turn is two steps: one LLM call and one tool call. On Inngest that gives roughly 500 turns per run (1,000 ÷ 2). Vercel documents that a step succeeding on its first attempt writes three events, plus three for the run itself. That puts its 25,000-event ceiling at about 8,332 first-try steps, or about 4,166 two-step turns. Retries add events, so the real number is lower.
The softer limit matters more. Vercel notes that runs past 2,000 events can replay more slowly, and an orchestration attempt over 240 seconds may be aborted.
The fix is the same everywhere. Start a fresh run with the current state once history gets long. Temporal calls this Continue-As-New. On other engines you start a child workflow or a new run that receives a summary of the conversation. My recommendation: trigger it on a turn count you choose, such as every 100 turns, rather than waiting for the engine’s warning.
How large can each step’s output be?
Step output limits are small compared to an LLM conversation, and agents break them by returning the whole transcript from every step. Check these before you return messages:
- Step Functions limits task, state and execution input or output to 256 KiB as a UTF-8 string.
- Cloudflare Workflows limits a non-stream step result to 1 MiB, with 1 GB of persisted state per instance on Workers Paid.
- Inngest limits one step’s return to 4 MiB and total run state to 32 MiB.
- Vercel Workflow allows payloads up to 50 MB and 2 GB of entity storage per run.
The pattern that works everywhere is simple. Store large artifacts, such as retrieved documents and full transcripts, in object storage or a database. Return a reference plus a short summary from the step. History stays small and replays stay fast.
Is a LangGraph checkpointer the same as durable execution?
A LangGraph checkpointer gives you resumable state, but the guarantee depends on the durability mode and the node size. LangGraph saves a checkpoint at each super-step boundary. When you resume from a checkpoint, nodes after it re-execute, and the docs state this includes any LLM calls and API requests.
LangGraph offers three durability modes:
"exit"persists only when the graph exits, so you cannot recover from a mid-run process crash."async"persists while the next step runs, with a small risk of a lost checkpoint on a crash."sync"persists before the next step starts, at some performance cost.
In practice, a LangGraph node that calls the LLM and then a tool is one recovery unit. If it fails between the two, both re-run. Split side-effecting tool calls into their own nodes, use durability="sync" for agents that touch money or user data, and use a persistent checkpointer. The docs warn that MemorySaver loses all checkpoints on restart.
Which engine is best for durable execution for AI agents in Node.js?
Pick the engine that matches where your code already runs, then check its limits against your longest expected run. Here is the comparison, built from each vendor’s limits page.
| Engine | History / step cap per run | Per-step payload | Max run length | Best fit |
|---|---|---|---|---|
| Temporal | 51,200 events / 50 MB | See Temporal docs | No run-length cap listed on the limits page | Long, complex agents; self-host or cloud |
| AWS Step Functions (Standard) | 25,000 events | 256 KiB | 1 year (Express: 5 minutes) | AWS-native, Bedrock-based agents |
| Inngest | 1,000 steps | 4 MiB | 30 days Free / 90 Pro / 366 Business | Event-driven apps on any host |
| Cloudflare Workflows (Paid) | 10,000 steps (up to 25,000) | 1 MiB | Unlimited while each step stays in CPU limits | Workers-based agents |
| Vercel Workflow | 25,000 events / 10,000 steps | 50 MB | No limit | Next.js apps on Vercel |
Cost follows the event count too. Vercel bills $0.02 per 1,000 Workflow Events on demand. A suspended run uses no compute while it sleeps or waits on a hook. Inngest counts a function run with five steps as six executions. Finer-grained steps are safer, but each one costs events.
If you are building agents locally first, our local AI coding agent setup guide shows how to iterate before choosing hosting.
The NexGismo verdict: Durable execution for AI agents is worth it for any agent that runs longer than one HTTP request or touches money, email or user data. I’d treat it as a cost and resumability tool, not a correctness guarantee: the correctness still comes from idempotency keys on every side-effecting step. Budget steps per run on day one, because the history cap is the limit agent teams hit first.
- Durable execution engines replay a run from its event log and skip steps that already have recorded results.
- Recovery happens only at step boundaries, so a side effect that finishes before its result is saved will run again.
- Temporal Activities retry without limit by default, which Temporal itself describes as at-least-once execution.
- Inngest allows 1,000 steps per function, about 500 two-step agent turns per run.
- AWS Step Functions Standard executions fail at 25,000 history events and limit payloads to 256 KiB.
- LangGraph’s “exit” durability mode cannot recover from a mid-run crash; “sync” persists before every step.
Frequently Asked Questions
What is durable execution in AI agents?
Durable execution in AI agents means the agent loop runs on an engine that saves each completed step, such as an LLM call or tool call, to an event log. If the worker crashes or redeploys, the engine replays the log, skips finished steps and continues from the next one, so the run resumes instead of restarting from scratch.
How is durable execution different from a message queue?
A message queue redelivers a whole job when a worker fails, so every step in that job runs again. Durable execution records the result of each step inside the job, so only the unfinished step re-runs. Queues suit single-shot tasks; durable execution suits multi-step agents with tool calls, waits and human approvals.
Does durable execution guarantee exactly-once tool calls?
No. Engines record a step only after it completes, so a crash between the side effect and the save causes a re-run. Temporal documents Activity execution as at least once by default. Exactly-once effects need idempotency keys that the downstream API or your own database enforces.
What is the Temporal event history limit?
Temporal limits a single Workflow Execution’s Event History to 51,200 events or 50 MB and warns at 10,240 events or 10 MB. Long-running agents should use Continue-As-New to start a fresh run with the current state before reaching that limit, which also keeps replay fast.
Do I need Temporal to use LangGraph in production?
Not necessarily. LangGraph with a persistent checkpointer such as Postgres or MongoDB can resume from super-step boundaries, and durability=”sync” saves state before each step. A separate engine adds stronger retries, timers and long waits. Either way, split side-effecting tool calls into their own nodes or steps.
Conclusion: what should you change in your agent this week?
Durable execution for AI agents starts with your step boundaries. Every LLM call and every tool call should be its own step. Every tool that changes the world should receive a key derived from the run ID and step name. Then take your engine’s history cap, divide it by steps per turn, and set a Continue-As-New threshold well below the result. Finally, keep step outputs small by storing transcripts and documents outside the run. Those three changes let an agent survive deploys and evictions without double-charging anyone. If you run the demo’s crash test against your own engine, it is a cheap check worth adding to CI.
Sources
- Temporal Docs — Workflow Execution limits
- Temporal Docs — Workflow basics, TypeScript SDK
- Temporal Blog — What is idempotency? And why it matters for durable systems
- AWS Documentation — Step Functions service quotas
- Inngest Docs — Durable Execution limits
- Cloudflare Docs — Workflows limits
- Vercel Docs — Workflow pricing and limits
- LangChain Docs — LangGraph checkpointers and durability modes
- Stripe API Reference — Idempotent requests