Slides · LangChain ecosystem
LangGraph: persistence, human approval and failure
1 / 29
LangGraph: persistence, human approval and failure
How a graph survives a restart, waits days for a person, and recovers from a crash without paying a customer twice.
The project’s README describes LangGraph as a low-level orchestration framework for long-running, stateful agents, with durable execution and human oversight among its features.
By the end you can tell the checkpointer from the store, build a pause with interrupt, design for steps that run more than once, and use history, replay and fork.
Concept
The restart that costs money
The server restarts halfway through a job. The saved state comes back exactly as it was at the last checkpoint. Two refunds had already gone out before the crash.
- The state can be restored. The refunds cannot be taken back, because they happened outside the saved state.
- When the job runs again from its last saved step, the step that issued them may run again.
- The whole lesson is about this seam: what is saved, what runs again, and what a repeat does to the outside world.
Concept
Two stores, two jobs
LangGraph’s documentation describes two persistence systems.
- A checkpointer saves snapshots of the graph’s state for one thread. It is short-term memory and supports conversation continuity, human-in-the-loop, time travel and fault tolerance.
- A store saves application-defined data outside the graph state, shared across threads. It is long-term memory: preferences, facts, shared knowledge.
- Most applications can use both: a checkpointer for the conversation in progress and a store for what should outlive it.
Compare
Checkpointer or store
| Aspect | Checkpointer | Store |
|---|---|---|
| Scope | One thread | Across threads and sessions |
| Holds | The graph’s state, as checkpoints | Items you define: preferences, facts |
| Key | A thread_id in the run config | A namespace tuple plus a key |
| Typical use | Resume, approvals, time travel, recovery | Long-term memory |
| Development choice | InMemorySaver, SqliteSaver | InMemoryStore |
| Production choice named in the docs | PostgresSaver | PostgresStore and others |
Both attach when the graph is compiled. The thread id is chosen on each call.
Sources[2] Persistence (LangGraph documentation)[3] Memory (LangGraph documentation, add-memory page)
Diagram
Where each kind of state lives
Code
A thread id selects state, a namespace selects memory
Python
from typing import TypedDict
from langgraph.graph import StateGraph, START, END
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.store.memory import InMemoryStore
from langgraph.runtime import Runtime
class State(TypedDict, total=False):
user_id: str
turns: int
pref: str
def remember(state: State, runtime: Runtime):
hits = runtime.store.search((state["user_id"], "memories"), limit=1)
return {"turns": state.get("turns", 0) + 1,
"pref": hits[0].value["text"] if hits else "none"}
builder = StateGraph(State)
builder.add_node("remember", remember)
builder.add_edge(START, "remember")
builder.add_edge("remember", END)
store = InMemoryStore()
store.put(("u1", "memories"), "pref-lang", {"text": "prefers short replies"})
graph = builder.compile(checkpointer=InMemorySaver(), store=store)
def run(user, thread):
return graph.invoke({"user_id": user}, {"configurable": {"thread_id": thread}})Results when run with langgraph 1.2.17 on 2026-10-24:
| Call | turns | pref | Why |
|---|---|---|---|
run("u1", "chat-1") | 1 | prefers short replies | New thread, memory found in the store |
run("u1", "chat-1") | 2 | prefers short replies | Same thread id: the saved state continued |
run("u1", "chat-2") | 1 | prefers short replies | New thread id: blank state, same memory |
run("u2", "chat-3") | 1 | none | Another namespace holds nothing for this user |
Concept
The thread id is part of your security and your bill
- Reuse an id and you continue that state. Use a new id and you start blank.
- Anyone who can supply a thread id can ask for that state, so authorise ids in your own code (the course’s reading; the docs do not cover access control). The runtime does not know who a person is.
- With the Postgres savers the docs say to keep ids under 255 characters, and they suggest generating ids rather than composing long ones.
- Checkpoints accumulate over long conversations. The docs suggest pruning or a retention policy, such as a scheduled job that deletes checkpoints older than a set number of days.
- The in-memory saver keeps checkpoints in RAM, so they are lost when the process restarts. The docs say to use a persistent saver such as the Postgres one in production.
Check yourself
Check: a ticket number as the thread id
A support site builds each thread id from the ticket number: ticket-1041, ticket-1042, and so on. The server only checks that the visitor is logged in. What can go wrong, and what do you change?
Answer
Any logged-in visitor can type ticket-1042 and load another customer’s conversation, because the id is the key to the saved state and the numbers are guessable. In the course’s reading, authorise the id against the user in your own code before every call (look up that the ticket belongs to the caller), or issue unguessable ids and store the mapping from user to id. Prune old checkpoints as well, so the table does not grow without limit.
Concept
An approval cannot be a function that waits
A manager may answer in two days. A blocked process would hold memory and a connection for that long, and would not survive a restart.
interruptsolves this by saving state through the checkpointer and returning control to the caller with a payload for the reviewer.- The graph then waits until you resume it, with no process blocked (the course’s reading of the design).
- A later call with a resume command, on the same thread, continues the run.
- Requirements from the docs: a checkpointer, a thread id, and a payload that can be written as JSON.
Diagram
Pause and resume, step by step
Code
Refund approval that survives a restart
Python
from langgraph.types import interrupt, Command
from langgraph.checkpoint.sqlite import SqliteSaver
def approve_refund(state: State):
decision = interrupt({"order": state["order_id"], "amount": state["amount"]})
if decision["approved"]:
return {"status": issue_refund(state["order_id"], key=state["request_id"])}
return {"status": "rejected"}
config = {"configurable": {"thread_id": "refund-9"}}
with SqliteSaver.from_conn_string("refunds.db") as saver: # process 1
out = build(saver).invoke(first, config)
out["__interrupt__"][0].value # payload for the reviewer
with SqliteSaver.from_conn_string("refunds.db") as saver: # process 2, days later
build(saver).invoke(Command(resume={"approved": True}), config)build(saver) compiles a one-node graph with that checkpointer and issue_refund stands in for a payment provider that remembers keys. The full file was run on 2026-10-24 with langgraph 1.2.17: the first call returned the payload order 8841, amount 120, and the second process resumed from the database file and issued the refund. The interrupts page says the default invoke API still works and surfaces interrupts under __interrupt__, and it worked in this version. Newer examples use stream_events, so check the API of the version you install.
Compare
What runs on each pass
| Phase | Code before interrupt | The interrupt call | Code after interrupt |
|---|---|---|---|
| First run | Runs | Saves state and pauses | Does not run yet |
| After resume | Runs again | Returns the resume value | Runs |
The node does not continue from the interrupt line. It starts again from its beginning, and the call now returns the answer. Everything above the call therefore runs once per pass.
Worked example
Worked example: two interrupts in one node
A node appends a letter to a log, then calls interrupt twice:
Python
def node(state):
log.append("A")
x = interrupt("first?")
log.append("B")
y = interrupt("second?")
log.append("C")
return {"out": f"{x}+{y}"}Run with invoke, then Command(resume="yes"), then Command(resume="no"):
| Call | Log afterwards | What happened |
|---|---|---|
First invoke | A | Runs to the first interrupt and pauses |
| Resume “yes” | A, A, B | Node restarts, first interrupt returns “yes”, pauses at the second |
| Resume “no” | A, A, B, A, B, C | Restarts again, both interrupts return their saved values, node finishes |
Final output yes+no. Line A ran three times, B twice, C once. The docs say resume values are matched to interrupts by position, which is why the order of interrupts in a node must stay the same.
Check yourself
Check: predict the log of a two-question flow
A node logs “start”, calls interrupt("name?"), logs “mid”, calls interrupt("email?"), then logs “end”. It is resumed twice. List the full log, and say which resume value the first interrupt call receives on the last pass.
Answer
start, start, mid, start, mid, end. The first pass logs “start” and pauses. The first resume restarts the node, so “start” and “mid” appear and it pauses again. The second resume restarts again and runs to the end. On that last pass the first call returns the answer to “name?” again, because resume values are matched to interrupts by position, which is why their order must not change.
Process
Rules for using interrupt
- Keep repeatable work before it. Make anything before the call safe to run again, or move it after the call or into another node.
- Do not swallow the pause. The pause is raised as an exception, so a bare
try/exceptaround the call catches it. Catch specific exception types. - Keep the order stable. Do not skip, reorder or conditionally add interrupts between runs of the same node.
- Pass plain data, not functions or class instances.
- No
while Truearound it. Call it once per run of the node and use a conditional edge to ask again. - Parallel branches that interrupt together are resumed in one call that maps each interrupt id to its value.
Tested on 2026-10-24: a node with try: v = interrupt("q") and except Exception: v = "swallowed" returned {'status': 'swallowed'} at once. No pause happened and no reviewer was asked. Static breakpoints (interrupt_before, interrupt_after) also need a checkpointer, but the docs describe them as a debugging aid, not a tool for human approval.
Concept
Why a step can run twice
- The checkpointer saves state, not the world. It cannot see a payment, an email or a file that a node produced.
- The checkpointers page says a graph can restart from the last successful step, and that nodes which already succeeded in that step are not re-run because their writes are stored as pending writes.
- The failed node has no saved result, so it runs again from its start (the page implies this by describing only successful nodes as skipped; the restart point is tested below).
- An interrupt resume also restarts its node.
- For anything a node does outside the graph, the guarantee is at least once, not exactly once. This is the course’s reading of how the pieces fit, tested below.
- Defences, with their costs: a stable key from the request; recording “done” in state or checking for an existing result first (an extra read); putting non-repeatable work after the pause; capping retries and routing stubborn failures to a person; timeouts; and failing closed when the checkpoint database is down.
Sources[4] Interrupts (LangGraph documentation)[5] Checkpointers (LangGraph documentation)
Worked example
Tested: failure between steps and inside a node
A three-node graph s1, s2, s3 with an in-memory saver. Node s2 raises an error the first time and works the second. Each node counts its runs.
| Moment | s1 runs | s2 runs | s3 runs | Saved next |
|---|---|---|---|---|
After the first call fails inside s2 | 1 | 1 | 0 | s2 |
After invoke(None, config) resumes | 1 | 2 | 1 | none |
The finished node s1 did not run again. The failed node s2 started over from its first line, so any outside effect it had produced before raising would have repeated. Passing None as the input resumes the thread from its saved state.
Worked example
Defence: a stable key from the request
The refund example sends key=state["request_id"]. A stable key is the same on every attempt, so the receiver can recognise a repeat. Stripe’s API works this way: a retried request with the same key does not perform the operation twice.
Results from the refund file (one request id, one payment provider stand-in):
| Action | Result |
|---|---|
| Resume after the “restart” | refunded |
| Resume the finished thread again | refunded (state unchanged, no second call) |
| New thread, same request id, resumed | duplicate-ignored |
| Refunds issued in total | 1 |
Two things are guarding here. Resuming a finished thread did nothing in this version. The key stopped a second thread from paying again, but only while the provider remembers it: providers keep keys for a limited time (Stripe API v1 keys can be pruned after at least 24 hours), and here the stand-in never forgets. Generate the key once per request and keep it in state. A fresh random key per attempt would defeat the second guard, because each attempt would look like a new request.
Source[6] Idempotent requests
Compare
Durability modes: what a hard crash costs
The checkpointers page lists three durability modes, from least to most durable, and the reference page for astream gives "async" as the default (the signature default is None, which the library resolves to async). The crash tests below ran on the installed library (langgraph 1.2.17), not on the docs. A three-node graph was run in a process killed with os._exit while inside s2, then resumed in a new process with a SQLite file.
| Mode | Saved when | After a hard kill inside s2 |
|---|---|---|
exit | When the run ends | Nothing saved: 0 checkpoints, resuming with None raised EmptyInputError |
async | In the background, while the next step runs | Only the input checkpoint was saved, so the resume ran s1, s2, s3 again |
sync | Before the next step starts | Resume ran s2 and s3 only |
The async outcome depends on timing, so another run could save more. When the node raised an ordinary exception instead of killing the process, all three modes kept a checkpoint, because the run ended through an error, which every mode saves.
Sources[5] Checkpointers (LangGraph documentation)[7] astream (LangGraph Python reference, Pregel)
Check yourself
Check: price the difference between two modes
A research agent run has 12 steps at 0.40 dollars of model calls each. The process is killed during step 9, after 8 steps finished. With exit nothing from this run was saved; with sync the checkpoint after step 8 exists. Compare the money spent on the rerun, counting step 9 on both sides, and say what else besides money should decide.
Answer
Both reruns must do step 9 to 12: 4×$0.40=$1.60. The exit rerun also repeats steps 1 to 8: 8×$0.40=$3.20 more, 4.80 in all against 1.60 under sync. The difference is 3.20 dollars per crash. Weigh that against the slower writes of sync on every run, how often crashes happen, and whether the repeated steps carry outside effects. A hard kill under exit always loses the whole run so far. async can also lose recent steps (the page notes a small risk, and the test above kept only the input checkpoint). Only sync guarantees the step 8 checkpoint exists.
Concept
Because every step is saved, you can look back
- History:
get_state_history(config)lists a thread’s checkpoints, newest first. Each has anextfield naming the node that would run from there. - Replay: invoke with
Noneand an earlier checkpoint’s config. Nodes before it are not re-run. Nodes after it do run again. - Fork:
update_stateon an earlier checkpoint creates a new branch with changed values, then you invoke to continue. The original history stays as it was. - Uses: finding where a run went wrong, trying a prompt change from the same midpoint, correcting an assumption without redoing early steps.
Diagram
A fork branches, it does not rewind
Code
History, replay and fork in code
Python
history = list(graph.get_state_history(config)) # newest first
at_n4 = [h for h in history if h.next == ("n4",)][0]
graph.invoke(None, at_n4.config) # replay from here
fork = graph.update_state(at_n4.config, {"out": "FIX"}) # fork, node inferred
graph.invoke(None, fork)
fork2 = graph.update_state(at_n4.config, {"out": "FIX"}, as_node="n4")
graph.invoke(None, fork2) # fork, update counted as n4The graph is six nodes in a line, n1 to n6, each counting its runs. The docs say as_node names the node the update counts as coming from, so execution resumes at that node’s successors.
Worked example
Tested: what runs after each move
Starting from a finished run of n1 to n6, taking the checkpoint whose next is n4:
| Move | Nodes that ran | Count |
|---|---|---|
Replay from the n4 checkpoint | n4, n5, n6 | 3 |
Replay from the final checkpoint (next is empty) | none | 0 |
| Fork with the node inferred, then invoke | n4, n5, n6 | 3 |
Fork with as_node="n4", then invoke | n5, n6 | 2 |
Nodes n1 to n3 never re-ran. Replay is not a cache read: the later nodes execute live, so a model call or an email in them happens again. In a separate run, forking left the original checkpoint’s values unchanged.
Concept
Limits to know before using it on a live thread
- Time travel does not undo anything. A fork creates a branch and the effects of the first run stay in the world.
- Interrupts fire again during time travel. The interrupting node re-runs and waits for a new resume value.
- By default a subgraph runs as one step of the parent, so you can travel to points before or after the whole subgraph but not between its nodes. Compiling it with its own checkpointer lets you fork inside it.
- Check what the re-run nodes touch. If one sends mail or charges a card, protect it with a key or fork a test copy.
Check yourself
Check: count the runs on an eight-node pipeline
A pipeline runs nodes 1 to 8 in a line, and node 6 sends an email. You take the checkpoint whose next is node 3. (a) You replay from it. How many nodes run and does the email send again? (b) You instead fork with as_node set to node 3. How many nodes run?
Answer
(a) Nodes 3 to 8 run, which is six nodes, and node 6 sends the email again, because replay executes the later nodes. (b) The update counts as node 3 having run, so execution resumes at its successor: nodes 4 to 8 run, which is five nodes, and node 6 still sends the email. Nodes 1 and 2 do not run in either case. Neither move recalls the first email.
Summary
Recap
- Checkpointer: one thread’s state, found by thread id. Store: memories across threads, found by namespace and key.
- Use a durable saver in production, authorise thread ids, and prune old checkpoints.
interruptsaves and pauses. Resume on the same thread and the node restarts from its top, so earlier lines run again.- Do not wrap it in a bare
except. Keep interrupt order stable. - Outside effects are at least once: use stable keys, record completion, and put non-repeatable work after the pause.
- Durability modes trade speed for recovery. Pick by what a lost step costs.
- Replay re-runs later nodes live. A fork branches and leaves history intact. Neither undoes a side effect.
References
References & Sources (1 of 2)
langchain-ai/langgraph (GitHub repository) (opens in a new tab)
LangChain2026Repository
https://github.com/langchain-ai/langgraph
Used for A short description of LangGraph as a low-level framework for long-running, stateful agents, with durable execution and human oversight among its stated features (page read 24 October 2026).
Persistence (LangGraph documentation) (opens in a new tab)
LangChain2026Documentation
https://docs.langchain.com/oss/python/langgraph/persistence
Used for The split between checkpointers (thread-scoped state) and stores (cross-thread data), the in-memory saver being lost on restart, the 255-character limit on Postgres thread ids, and the advice to prune checkpoints (page read 24 October 2026).
Memory (LangGraph documentation, add-memory page) (opens in a new tab)
LangChain2026Documentation
https://docs.langchain.com/oss/python/langgraph/add-memory
Used for How a node reaches the store, the namespace-and-key model, put and search, and how put and search take a namespace (page read 24 October 2026).
Interrupts (LangGraph documentation) (opens in a new tab)
LangChain2026Documentation
https://docs.langchain.com/oss/python/langgraph/interrupts
Used for How interrupt pauses and resumes, the requirements, the rule that the node restarts from its start, the list of pitfalls, resuming parallel interrupts, and static breakpoints being a debugging aid (page read 24 October 2026).
Checkpointers (LangGraph documentation) (opens in a new tab)
LangChain2026Documentation
https://docs.langchain.com/oss/python/langgraph/checkpointers
Used for The durability modes (exit, async, sync) from least to most durable, restarting from the last successful step, and pending writes from nodes that succeeded in a failed step (page read 24 October 2026).
References
References & Sources (2 of 2)
Idempotent requests (opens in a new tab)
Stripe2026Documentation
https://docs.stripe.com/api/idempotent_requests
Used for An idempotency key lets a retried request avoid performing the same operation twice.
astream (LangGraph Python reference, Pregel) (opens in a new tab)
LangChain2026Documentation
https://reference.langchain.com/python/langgraph/pregel/main/Pregel/astream
Used for The durability argument and its default of async (reference page read 24 October 2026).
Use time-travel (LangGraph documentation) (opens in a new tab)
LangChain2026Documentation
https://docs.langchain.com/oss/python/langgraph/use-time-travel
Used for History, replay and fork, what re-executes on replay, the as_node argument, interrupts re-triggering, and subgraph limits (page read 24 October 2026).
Keys: ← → move, Home End first and last, F full screen.