Durable agent execution means a run saves its progress as it goes, so a crash, a deploy or a provider outage costs you one step instead of the whole run. LangGraph's docs define it as "a technique in which a process or workflow saves its progress at key points, allowing it to pause and later resume exactly where it left off," and say that "If you are using LangGraph with a checkpointer, you already have durable execution enabled." To resume, you call the graph again with the same thread_id and None as the input. The catch is in the details: a resumed run restarts the interrupted node from its first line, and side effects inside that node can run twice unless you plan for it.
This post covers the three requirements, the three durability modes, and what happened when we killed a Python process in the middle of a node. Everything was run on Python 3.13 with langgraph 1.2.25 and langgraph-checkpoint-sqlite 3.1.3, with plain functions standing in for the refund and email APIs, so no model or API key was involved.
The three requirements
The durable execution page lists them:
- "Enable persistence in your workflow by specifying a checkpointer that will save workflow progress."
- "Specify a thread identifier when executing a workflow."
- Wrap non-deterministic operations and side effects, such as random numbers, file writes and API calls, in tasks, so that on resume they are "not repeated for the particular run, and instead their results are retrieved from the persistence layer."
The checkpointer has to survive the crash you care about. The persistence docs warn that InMemorySaver keeps checkpoints in RAM, so "When the process restarts, all checkpoints are lost," and point to SqliteSaver or PostgresSaver instead. A crash that kills the process is exactly the case where InMemorySaver gives you nothing.
Where a resumed run starts
This is the part that surprises people. The docs say plainly: "When you resume a workflow run, the code does NOT resume from the same line of code where execution stopped." Instead, LangGraph finds the last saved checkpoint and replays from there. For a StateGraph, "the starting point is the beginning of the node where execution stopped." For a node that calls a subgraph, the parent node is the starting point, and inside the subgraph it is the node that stopped.
Nodes that finished in earlier super-steps are not run again. The checkpointers page puts it as "Nodes before the checkpoint are skipped (their results are already saved)." Nodes from the checkpoint onward "re-execute, including any LLM calls, API requests, or interrupts." If you have read the recursion limit post, this is the same mechanism that lets a run that hit GraphRecursionError continue with invoke(None, config).
So the unit of safety is the node. Any node that does two expensive or irreversible things can redo the first one when the second one fails.
A test graph: refund, then email
Here is a small support pipeline. summarize reads the ticket, then act issues a refund and sends an email, each wrapped in @task. Every side effect appends a line to a log file, so we can count what really ran. Setting CRASH=1 kills the process with os._exit(1) between the two tasks, which is closer to an out-of-memory kill or a pod eviction than a Python exception is.
import os
import sqlite3
import sys
from typing import NotRequired, TypedDict
from langgraph.checkpoint.sqlite import SqliteSaver
from langgraph.func import task
from langgraph.graph import END, START, StateGraph
LOG = "side_effects.log"
def log(line: str) -> None:
with open(LOG, "a") as f:
f.write(line + "\n")
class State(TypedDict):
ticket: str
summary: NotRequired[str]
refund_id: NotRequired[str]
email_id: NotRequired[str]
@task
def issue_refund(ticket: str) -> str:
log(f"refund API called for {ticket}")
return f"rf_{ticket}"
@task
def send_email(ticket: str, refund_id: str) -> str:
log(f"email sent for {ticket} ({refund_id})")
return f"em_{ticket}"
def summarize(state: State) -> dict:
log("summarize ran")
return {"summary": f"customer wants a refund on {state['ticket']}"}
def act(state: State) -> dict:
log("act started")
refund_id = issue_refund(state["ticket"]).result()
if os.environ.get("CRASH") == "1":
os._exit(1) # simulate the process dying mid-node
email_id = send_email(state["ticket"], refund_id).result()
return {"refund_id": refund_id, "email_id": email_id}
builder = StateGraph(State)
builder.add_node("summarize", summarize)
builder.add_node("act", act)
builder.add_edge(START, "summarize")
builder.add_edge("summarize", "act")
builder.add_edge("act", END)
if __name__ == "__main__":
conn = sqlite3.connect("checkpoints.db", check_same_thread=False)
graph = builder.compile(checkpointer=SqliteSaver(conn))
config = {"configurable": {"thread_id": "ticket-4417"}}
mode = sys.argv[2] if len(sys.argv) > 2 else "sync"
if sys.argv[1] == "start":
out = graph.invoke({"ticket": "T-4417"}, config, durability=mode)
else:
out = graph.invoke(None, config, durability=mode)
print(out)
Run it once with CRASH=1 python pipeline.py start sync, then once more with python pipeline.py resume sync, in a fresh process.
What the crash test showed
With durability="sync", the resumed run finished and returned the refund and email IDs. The side effect log read:
summarize ran
act started
refund API called for T-4417
act started
refund API called for T-4417
email sent for T-4417 (rf_T-4417)
summarize ran once, as promised. But the refund API was called twice. The task had finished, yet its result was not in the database when the process died. Reading the writes table right after the crash showed the writes from __start__ and summarize and nothing from the task.
The reason is in the langgraph source. In pregel/_loop.py, put_writes hands the checkpointer's put_writes call to self.submit, a background executor, whatever the durability mode. The "sync" mode is enforced elsewhere: in pregel/main.py, after each tick, if durability_ == "sync": loop._put_checkpoint_fut.result() waits for the checkpoint at the end of the super-step. Task results inside a node are saved in the background, so a hard kill right after a task can lose them.
Two variations confirm it. When we added a one second sleep before os._exit, the task's __return__ write was in the table, and the resumed run reused the refund result: the log showed act started a second time but only one refund call. When the node raised a RuntimeError instead of killing the process, the error was recorded too, and again the refund ran once. So tasks do protect you from exceptions and from most crashes, but not from a kill in the instant after a side effect. Durable execution narrows the window for duplicates; it does not close it.
The three durability modes
The durability argument works on invoke, stream and their async versions. The Durability type in langgraph's types.py documents three values, and the invoke docstring says it "defaults to "async"":
"exit": "Changes are persisted only when the graph exits." The docs add that this includes exits by error or by a human-in-the-loop interrupt, but you "cannot recover from system failures (like process crashes) mid-execution.""async": "Changes are persisted asynchronously while the next step executes." The docs call this good performance and durability, with "a small risk that checkpoints might not be written if the process crashes during execution.""sync": "Changes are persisted synchronously before the next step starts." Every checkpoint is written before execution continues, at some cost in speed.
Our crash test showed each one:
"sync":summarizewas skipped on resume, as above."async": the checkpoint aftersummarizehad not been written when the process died, so the resumed run started over fromsummarizeand called the refund API a second time."exit"with a hard kill: nothing was saved, andinvoke(None, config)raisedEmptyInputError: Received no input for __start__. The checkpointers page warns about this case: "In every mode, a crash before the first checkpoint becomes durable leaves the thread indistinguishable from a thread that was never invoked." It suggests recording that a run was admitted outside the checkpointer, for example with an outbox row."exit"with an exception: the state was saved on the way out, and the resume skippedsummarizeand reused the refund result.
For agent runs where a step can cost real money or touch the outside world, "sync" is the mode that matches the word durable. The checkpoint_during flag from older code is deprecated; the docs map checkpoint_during=True to durability="async" and False to "exit".
Make side effects idempotent anyway
The docs ask that workflows be "deterministic and idempotent" and say to "Use idempotency keys or verify existing results to avoid unintended duplication." Our test is the reason. Give every side effect a key that is the same on every replay of the same run, and let the API you call drop the repeat.
The thread ID is a good base, because a resumed run uses the same one. A node can read it from its config:
from langchain_core.runnables import RunnableConfig
def act(state: State, config: RunnableConfig) -> dict:
thread_id = config["configurable"]["thread_id"]
key = f"{thread_id}:refund:{state['ticket']}" # "ticket-4417:refund:T-4417"
...
Pass that key to the refund call as an idempotency key if the API supports one, or check for an existing refund with that key before creating one. The patterns are covered in agent tool retries. Never build the key from a timestamp or a random value generated inside the node, since a replay would generate a new one.
The docs give two more rules that follow from replay:
- One side effect per task or node. "Avoid Repeating Work" suggests wrapping each operation in its own task when a node has several. A failure in the second then does not redo the first.
- Keep randomness in tasks. A random choice or a
datetime.now()in node code will change on replay. Inside a task, the saved result is reused.
Finding and resuming crashed runs
After a crash, get_state tells you where a thread stopped. On the crashed "sync" run above, graph.get_state(config).next was ('act',) and the saved values held ticket and summary. A thread whose next is not empty has unfinished work. A worker that starts up can check its recent thread IDs this way and call graph.invoke(None, config) for each one that stopped mid-run. The checkpointers page describes that call as one that "Loads the latest checkpoint and retries unfinished work," and notes that resuming a thread with no unfinished work "returns the saved result without running nodes."
Keep the thread ID somewhere you can find it after a restart: in your job table, the ticket record, or a queue message. Resuming is only possible if you know which threads to resume. The same applies to runs paused on purpose, like the approval flows in human in the loop agents, which resume with Command(resume=...) instead of None.
Checklist
- Compile the graph with a persistent checkpointer,
SqliteSaverfor development orPostgresSaverfor production, notInMemorySaver. - Pass a stable
thread_idon every call and store it where a restarted worker can find it. - Use
durability="sync"for runs with costly or irreversible steps. - Put one side effect in each task or node.
- Give every side effect an idempotency key built from the thread ID, not from time or randomness.
- Record that a run started outside the checkpointer if losing a run before its first checkpoint matters.
- On startup, check
get_state(config).nextfor unfinished threads and resume them withinvoke(None, config). - Test it: kill the process mid-node and count the side effects, as above.
FAQ
How do I resume a LangGraph run after a crash?
Compile the graph with the same persistent checkpointer, then call graph.invoke(None, config) with the same thread_id. LangGraph loads the latest checkpoint and runs the unfinished work from there.
Does a resumed LangGraph node start where it crashed?
No. The node restarts from its first line. Nodes that finished in earlier super-steps are skipped, and tasks whose results were saved return those results instead of running again.
What is the default durability mode in LangGraph?
"async", according to the invoke docstring in langgraph 1.2.25. Checkpoints are written while the next step runs, so a crash can lose the latest one. Pass durability="sync" to wait for each checkpoint.
Do LangGraph tasks guarantee a side effect runs only once?
No. In our test, a task that finished just before the process was killed ran again on resume, because task results are saved in the background. Use idempotency keys for anything that must not happen twice.
Why does invoke(None, config) raise EmptyInputError?
The thread has no saved checkpoint. That happens with durability="exit" after a hard crash, or when the process dies before the first checkpoint is written, so LangGraph has nothing to resume.
Sources
- LangChain, Durable execution (LangGraph documentation: definition, requirements, starting points, durability modes, idempotency guidance)
- LangChain, Checkpointers (LangGraph documentation: replay, resume table, pending writes, first checkpoint warning)
- LangChain, Persistence (LangGraph documentation: InMemorySaver limits, SqliteSaver and PostgresSaver)
- LangChain, Durability (LangGraph reference)
- LangChain, langgraph (package source, version 1.2.25:
types.py,pregel/main.py,pregel/_loop.py) - LangChain, langgraph-checkpoint-sqlite (package, version 3.1.3)