Make LangGraph node side effects safe for replay and resume
List re-executable nodes and external writes, then set replay scope, work units, and idempotency.
Prerequisites and input · Engineering checks · 1. Inventory nodes and external writes
At a glance
LangGraph saves checkpoints only at super-step boundaries, and after an interrupt or retry a node runs again from the start of its function. Any node that writes to an external system needs three answers: which statements will run again, what unit the work should be split into, and who deduplicates a repeat. This checklist addresses those three questions, using only the supplied graph API and interrupts documentation.
Runtime and applicability
- Article type
- Engineering practice
- Verified
- Applies to
- LangGraph Make LangGraph node side effects safe for replay and resume
Execution locations and responsibilities
- LangGraph graph runtime and application host Use the workflow below to distinguish responsibilities of the caller, runtime, and external actions.
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
- With a checkpointer, checkpoints are saved at super-step boundaries, not in the middle of a node function. After an interrupt or retry, the affected node runs again from the start of its function, so side effects before the pause happen again. When a subgraph is invoked as a function inside a node, both the parent node and the subgraph node restart from their own beginnings. The graph API documentation also says you can add or remove nodes and edges without breaking resume for existing threads, but for a paused thread you should not rename or remove the node it is about to enter.
When not to use
- This checklist covers duplicate writes caused by node reruns only; it does not assess the transaction guarantees of the external system itself.
- The documentation gives no concrete call syntax for
task, so this walkthrough does not prescribe one and only discusses when to choose it. - Node caching with
CachePolicyis mentioned only briefly in the graph API documentation, so it is not treated here as an idempotency mechanism.
Prerequisites and input
- You have listed the nodes that may execute again, and the external writes inside each one.
- You know whether those nodes call
interrupt(), have retries configured, or are invoked as subgraphs. - You can change how nodes are split, or can ask the external system for idempotency keys and deduplication.
Engineering checks
Replay scope: checkpoint boundaries and whole-node reruns — With a checkpointer, checkpoints are saved at super-step boundaries, not in the middle of a node function. After an interrupt or retry, the affected node runs again from the start of its function, so side effects before the pause happen again. When a subgraph is invoked as a function inside a node, both the parent node and the subgraph node restart from their own beginnings. The graph API documentation also says you can add or remove nodes and edges without breaking resume for existing threads, but for a paused thread you should not rename or remove the node it is about to enter.
Work unit: function, task, subgraph, and graph node — The graph API documentation maps four units to different recovery behavior. A plain function inside a node reruns with the node. A task has no checkpoint of its own, and a completed task returns its stored result on replay, which suits steps that have side effects or are expensive and must not repeat on resume. A subgraph in stateful modes resumes at the interrupted or failed node. A graph node is a checkpoint and retry boundary, and the choice when you need an interrupt, resume, or time-travel boundary. The test is whether the step decides what happens next or executes something already decided.
Idempotency boundary: who guarantees a repeat is harmless — The interrupts documentation asks that side effects before an interrupt be idempotent where possible: use operations such as upsert, put the side effect after interrupt(), or split it into a separate node. It also notes that approval only gates whether the side effect happens; if a node fails after committing a side effect but before completing, a retry can still repeat it, so idempotent operations or deduplication in the external system are still needed. The graph API documentation names idempotency keys, upserts, and read-before-write checks as the means.
1. Inventory nodes and external writes
Where: the graph definition and each node's source. Input: every node that may execute again. Action: list the external writes per node, such as creating a record, appending history, or sending a notification, and mark whether each sits before or after interrupt(). Completion check: every write has an owning node and a position. Stop condition: if a write cannot be attributed to a node, resolve that before moving on.
2. Set the replay scope
Where: the runtime and the caller's resume path. Input: the step-one list. Action: decide why each node would rerun: interrupt resume, retry, or being called by a parent node as a subgraph function. Completion check: each node has the conclusion that a rerun starts at the beginning of the node, and in the subgraph case both parent and subgraph nodes are marked. Stop condition: if any reasoning depends on continuing from the interrupt() line, discard that assumption and mark the nodes again.
3. Choose a work unit for each write
Where: the node-splitting design. Input: the write list and the rerun conclusions. Action: for each write ask whether it decides the next path; make it a graph node if it needs a routing fork or an interrupt boundary, use a task for steps with side effects or high cost that must not repeat, use a subgraph for a unit with its own routing or one reused by several parent graphs, and leave the rest as plain functions. Completion check: every write has a chosen unit and a reason. Stop condition: fail the design if a write that needs its own checkpoint stays in a plain function.
4. Set the idempotency mechanism
Where: the write statements and the external system interface. Input: the writes that can still repeat. Action: choose an idempotency key, an upsert, or a read-before-write check for each, or move the write after interrupt() or into a separate node. Completion check: each write can answer whether repeating it gives the same result. Stop condition: if the external system offers no deduplication and the repeat cannot be avoided, keep that write out of any retryable node.
5. Fix the order of interrupt and task calls
Where: nodes that contain interrupt() or task. Input: the call order in those nodes. Action: confirm the count and order are the same on every execution, with no conditional skipping and no non-deterministic loops; the documentation says changing task or interrupt order before the resume point can mismatch cached values. Completion check: each node has a written, fixed order. Stop condition: if input validation uses an internal while True loop, rewrite it as state plus a conditional edge.
6. Record change risks and sign off the checklist
Where: the design review record. Input: conclusions from the first five steps. Action: write down limits for future graph edits: do not rename or remove a node a paused thread is about to enter, and note that renaming a state key drops the saved value in existing threads. Completion check: every checklist item has a conclusion, an owner location, and a stop reason. Stop condition: if any item is still unknown, the review does not pass.
Task example
This is a hypothetical manual walkthrough with nothing executed. Imagine a node that creates an audit record, then calls interrupt() to wait for confirmation, then sends a notification. According to the documentation, the node restarts from its beginning on resume, so the record-creating statement is expected to run again; it should become an upsert or use an idempotency key, or move to after the pause. The notification goes into a separate node and still needs deduplication in the external system, because the documentation says a retry can happen after the side effect was committed. All of this is an expectation drawn from the documentation and must be verified on your own graph.
Completion checks
- Scope stage: every re-executable node is marked as restarting at its beginning, and parent and subgraph levels are both marked where subgraphs apply.
- Unit stage: every write maps to one of a graph node, a
task, a subgraph, or a plain function, with a stated reason. - Idempotency stage: every write has an idempotency key, upsert, read-before-write check, or external deduplication, and the order of
interrupt()andtaskcalls is fixed.
Verification scope
Only the supplied graph API and interrupts documentation was read. Installation, login, API execution, and output were not tested, and the example is a hypothetical walkthrough based on the documentation. Retry and timeout details and the deduplication interface of any particular external system are not developed in the supplied material, so they are out of scope.
Sources
All links are official pages; verification dates are listed per source, and links point to the version checked.