Checkpointers, Threads and Time Travel
A checkpointer saves a snapshot of graph state at every super-step and groups the snapshots into threads keyed by `thread_id`. That one mechanism gives you conversation memory, human-in-the-loop pauses, recovery after failures and time travel. Know what a `StateSnapshot` contains, how replay differs from forking with `update_state`, what pending writes save you, and how backend, serializer and state size decide whether persistence holds up in production. Targets langgraph 1.2 / langgraph-checkpoint 4.x.
Key points
- 1
Compile with
graph.compile(checkpointer=...)and pass{"configurable": {"thread_id": ...}}on every call. Without a thread id, a graph with a checkpointer raisesValueError. A new thread id starts with empty state, and the same id continues from the latest checkpoint, with new input merged through the reducers. - 2
Backends:
InMemorySaver(inlanggraph-checkpoint; tests and experiments only; lost on restart and not shared between processes),SqliteSaver/AsyncSqliteSaver(langgraph-checkpoint-sqlite; local development) andPostgresSaver/AsyncPostgresSaver(langgraph-checkpoint-postgres; production). Callcheckpointer.setup()once on first use of Postgres. Manual psycopg connections needautocommit=Trueandrow_factory=dict_row. - 3
A linear
START -> a -> b -> ENDrun writes 4 checkpoints: input (step -1, next__start__), step 0 (nexta), step 1 (nextb) and step 2 (next()).stepkeeps counting across runs on the same thread. - 4
StateSnapshotfields:values,next(empty means finished),config(thread_id,checkpoint_ns,checkpoint_id),metadata(sourceisinput,looporupdate, plusstep),created_at,parent_config(None for the first) andtasks(each withname,error,interrupts, andstatewhen you passsubgraphs=True). - 5
get_state(config)returns the latest snapshot, or a specific one whencheckpoint_idis in the config.get_state_history(config, filter=..., before=..., limit=...)yields every checkpoint on the thread, newest first. - 6
Replay is
graph.invoke(None, snapshot.config): nodes before the checkpoint are skipped, and nodes after it re-execute, including LLM calls, API calls and interrupts. New checkpoints are appended. Replaying from the final checkpoint is a no-op. - 7
Fork:
fork_config = graph.update_state(snapshot.config, values, as_node=None)writes a new checkpoint (sourceupdate) that branches from the chosen one, theninvoke(None, fork_config)continues. Values go through reducers, so a list withoperator.addgets appended to. Nothing is rolled back or deleted. - 8
as_nodemakes the update count as that node's output, so execution resumes at its successors. Set it on a fresh thread (for example to seed state in tests), when parallel nodes wrote in the last step, or to skip nodes. - 9
Pending writes: as each task in a super-step finishes, its writes are saved and linked to the in-progress checkpoint. If a sibling fails, resuming with
invoke(None, config)re-runs only the failed task. After a failure,get_stateshows the failed node innextand the error on its task. - 10
Serialization: the default
JsonPlusSerializer(msgpack plus extensions) handles LangChain messages, datetimes, enums, sets, Pydantic models and dataclasses. Arbitrary classes raiseTypeError: Type is not msgpack serializableunless you passJsonPlusSerializer(pickle_fallback=True). Encrypt withserde=EncryptedSerializer.from_pycryptodome_aes()(readsLANGGRAPH_AES_KEY; needspycryptodome). - 11
Subgraph
compile(checkpointer=...):None(default) is per-invocation (interrupts within a call, fresh each call, safe for parallel calls);Trueis per-thread (memory across calls, no parallel or repeated calls to the same instance);Falseis stateless (no checkpoints and no state inspection). Subgraph checkpoints live in the namespace"node:<id>", and the root graph's namespace is"". - 12
Storage cost is roughly threads x checkpoints per thread x checkpoint size. By default every channel's full value is written at each super-step, so keep blobs out of state (store references), delete expired threads with
delete_thread, and considerDeltaChannel(beta, langgraph>=1.2) for append-heavy channels. A custom saver implementsput,put_writes,get_tuple(latest and by id),listanddelete_thread.
Common traps
Putting
thread_idin the input dict instead ofconfig["configurable"]: the key is dropped, and every call starts an empty thread.InMemorySaverbehind several workers or across restarts: each process has its own memory, so threads disappear or split between replicas.Expecting
update_stateto roll back or overwrite: it appends a checkpoint, and reducer keys accumulate instead of being replaced.Treating replay as reading from a cache: nodes after the checkpoint really run again, so non-idempotent side effects fire again and LLM outputs can differ.
Tuples in state come back as lists once loaded from a checkpoint, so code can break on the second turn or after a resume even though the first run worked.
Calling
pruneon the bundledInMemorySaverorSqliteSaver: they inherit the base method, which raisesNotImplementedError.A per-thread subgraph (
checkpointer=True) exposed as a tool and called in parallel: the calls collide in one namespace.Reading
next == ()as "thread does not exist": a finished thread also has an emptynext; checkvaluesor the history.
Read the source
Further reading
Suggest a resourceNo extra reading for Checkpointers, Threads and Time Travel yet. Found a guide, video or cheat sheet that made it click? Share it and help the next learner.
Test yourself on Checkpointers, Threads and Time Travel
Ten questions, with the answer and explanation after each one.