All Agent Engineering

Replaying and Forking State with LangGraph Time Travel

Pick a checkpoint from a thread, update state, rerun, and compare the results.

AINavWritten / Updated
On this page

At a glance

When debugging a thread that has already run, you can go back to a checkpoint and rerun, or change the state and fork a new path. This procedure follows the supplied LangGraph time-travel documentation, from choosing a checkpoint to comparing results, for targets at the parent level and inside a subgraph. The key fact is that nodes after the checkpoint execute again, including model calls, API requests and interrupts.

Runtime and applicability

Article type
Engineering practice
Verified
Applies to
  • LangGraph Replaying and Forking State with LangGraph Time Travel

Execution locations and responsibilities

  • LangGraph graph runtime and application host Use the workflow below to distinguish responsibilities of the caller, runtime, and external actions.
Engineering workflow order
Engineering workflow order1. Confirm the thread configuration and its history → 2. Select the parent-level target checkpoint → 3. Get the subgraph checkpoint configuration when the target is inside a subgraph → 4. Decide replay or fork and assess re-execution → 5. Create the fork with update_state → 6. Continue with None and handle interrupts → 7. Compare results and record causes. Arrows show the order of checks in the guide. Follow each step’s prerequisites, branches and stop conditions; unexecuted steps are not completed work.1. Confirm the thread configuration and its history2. Select the parent-level target checkpoint3. Get the subgraph checkpoint configuration when thetarget is inside a subgraph4. Decide replay or fork and assess re-execution5. Create the fork with update_state6. Continue with None and handle interrupts7. Compare results and record causes

Arrows show the order of checks in the guide. Follow each step’s prerequisites, branches and stop conditions; unexecuted steps are not completed work.

When to use

  • Replay and fork both resume from a prior checkpoint: nodes before it are not re-executed, nodes after it are. get_state_history returns history in reverse chronological order, and each record's next identifies the target checkpoint; its configuration holds the checkpoint_id. Replaying from the final checkpoint, which has no next nodes, does nothing.

When not to use

  • Replay is not a cache read: model calls and external requests after the checkpoint fire again and may return different results
  • A subgraph that inherits the parent's checkpointer cannot be rewound to a point between its inner nodes; it can only be rerun whole from before the subgraph
  • A node with interrupt pauses again on every time-travel run and needs a new resume value
  • as_node needs explicit setting only in the situations the documentation lists; setting it arbitrarily changes which node execution continues from

Prerequisites and input

  • The graph is compiled with a checkpointer and an already executed thread and its configuration exist
  • You know which state keys to replace, their new values, and which node produces those keys

Engineering checks

Checkpoint selection — Replay and fork both resume from a prior checkpoint: nodes before it are not re-executed, nodes after it are. get_state_history returns history in reverse chronological order, and each record's next identifies the target checkpoint; its configuration holds the checkpoint_id. Replaying from the final checkpoint, which has no next nodes, does nothing.

State update — update_state does not roll back the thread; it creates a new checkpoint branching from the given one, and the original history stays intact. Values are applied through the writers of the node treated as the producer, including reducers. as_node is inferred from version history by default, which is almost always right when forking from a checkpoint; set it explicitly for parallel branches where the last writer is ambiguous, for a thread with no execution history, or to make the graph believe a node already ran.

Interrupts and subgraph granularity — A node containing interrupt always re-triggers during time travel and needs a new Command(resume=...). A subgraph inherits the parent's checkpointer by default, so the parent treats it as one super-step and you can only go back to before the subgraph and rerun it whole. Compiling the subgraph with checkpointer=True gives it its own checkpoints. The parent's get_state_history still lists only parent-level targets; to fork between two interrupts, call get_state with subgraphs=True to obtain the subgraph's own checkpoint configuration, then call update_state on it.

1. Confirm the thread configuration and its history

Where: the application-host code that holds the thread configuration. Input: a configuration containing thread_id. Action: call get_state_history for that thread and list each record's next and checkpoint_id. Completion check: the history is non-empty and shows node execution order. Stop condition: if no checkpointer is configured or history is empty, do not continue.

2. Select the parent-level target checkpoint

Where: a debugging script or notes. Input: the history list and the name of the node to re-execute. Action: pick the checkpoint whose next is exactly that node; history is reverse-ordered, so take care to get the intended entry when a node appears more than once. Parent history can only select parent-level targets; if the target is inside a subgraph, go to the next step. Completion check: the chosen checkpoint_id and its next are recorded. Stop condition: if the chosen checkpoint has no next, it is the final one and replay would do nothing, so choose an earlier one.

3. Get the subgraph checkpoint configuration when the target is inside a subgraph

Where: debugging code, run only when the target is inside a subgraph, for example between two interrupts. Input: the thread configuration and how the subgraph was compiled. Action: confirm the subgraph is compiled with checkpointer=True; with the thread paused at the position you want to fork from, call get_state with subgraphs=True and take the subgraph's own checkpoint configuration from tasks[0].state.config in the result. Completion check: you hold a subgraph checkpoint configuration and have noted which pause position it corresponds to. Stop condition: if the subgraph uses the default inherited checkpointer, it has no inner checkpoints and can only be rerun whole from before the subgraph; skip this step and use the target from step 2.

4. Decide replay or fork and assess re-execution

Where: a design note. Input: the nodes that follow the target checkpoint. Action: replay runs from the checkpoint configuration alone; fork when state must be replaced. List every model call, API request and interrupt that will fire again. Completion check: each re-executing external action has a note. Stop condition: if an external write must not repeat and cannot be protected, stop instead of replaying.

5. Create the fork with update_state

Where: debugging code. Input: the parent checkpoint configuration from step 2 or the subgraph checkpoint configuration from step 3, plus the new state values. Action: call update_state to obtain a fork configuration; set as_node explicitly when you hit InvalidUpdateError, a fresh thread, or a need to skip nodes. Completion check: a new configuration is returned and the original history is still present. Stop condition: if you cannot tell which node should be the producer, examine parallel branches rather than guessing.

6. Continue with None and handle interrupts

Where: the code that invokes the graph. Input: the original checkpoint configuration for replay, or the configuration returned in the previous step for a fork. Action: invoke with None as input; if an interrupt fires, resume with a new Command(resume=...). Completion check: the run starts at the expected node and earlier nodes did not execute again. Stop condition: if the graph pauses at an interrupt and no resume value is available, pause and record the waiting state.

7. Compare results and record causes

Where: the debugging record. Input: the original result and the fork or replay result. Action: check the replaced keys, the regenerated downstream keys, and whether new checkpoints appeared in history. Completion check: each difference is attributed either to the state replacement or to variation from re-execution. Stop condition: if a difference cannot be attributed, redo the run from a closer checkpoint.

Task example

This is a hand-made hypothetical walkthrough, not an actual run. Suppose the graph is generate_topic followed by write_joke and has finished. You pick the history entry whose next is write_joke, change topic with update_state, then continue with None. Expected: generate_topic does not execute again, write_joke runs with the new topic, and the original thread history remains. These expectations come from the documented behavior and were not verified here; confirm them in your own environment.

Completion checks

  • The chosen checkpoint's next matches the node to re-execute and it is not the final checkpoint
  • When the target is inside a subgraph, the subgraph is confirmed as checkpointer=True and its checkpoint configuration came from get_state with subgraphs=True
  • Every model call, API request and interrupt that will re-execute is listed
  • The fork continues with the configuration returned by update_state and is not treated as a rollback

Verification scope

This text is based on reading the supplied LangGraph time-travel documentation only. Installation, login, API execution and output were not tested. Idempotency design for external writes and checkpointer storage choice are outside this topic.

Sources

All links are official pages; verification dates are listed per source, and links point to the version checked.

  1. LangGraph · LangGraph documentation: langgraph-time-travel

Found an error? Tell us →