Resuming one of two parallel interrupts inside a subgraph re-runs a sibling node that already completed
Checked other resources
- This is a bug, not a usage question.
- I added a clear and descriptive title that summarizes this issue.
- I used the GitHub search to find a similar question and didn't find it.
- I am sure that this is a bug in LangGraph rather than my code.
- The bug is not resolved by updating to the latest stable version of LangGraph (or the specific integration package).
- This is not related to the langchain-community package.
- I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.
Related Issues / PRs
- #6792 (open): the same root cause, reported for nested
@entrypointand, in the comments, forStateGraphsubgraphs that use@task. - #6793 (open, fixes #6792): on current
mainit setsself.skip_done_tasks, which nothing reads any more. With it applied, the repro below still fails. - #6050 and #6161: the same root cause was fixed for nested graphs.
- #6227 and #6223: #6227 reverted that fix. The discussion in #6223 concerns subgraph time travel, and recommends
checkpointer=True, which does not help here (see Description). - langchain-ai/langgraphjs#2667 and langchain-ai/langgraphjs#2679 (open): the same bug in JS, where the fix gates on
isTimeTraveling. - #8579: a related issue with the same topology. A scalar resume is accepted when one subgraph task has several pending interrupts.
Reproduction Steps / Example Code (Python)
import operator
from collections import Counter
from typing import Annotated
from typing_extensions import TypedDict
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.graph import START, StateGraph
from langgraph.types import Command, interrupt
runs = Counter() # times each node got past interrupt(), i.e. did its side effect
class State(TypedDict):
log: Annotated[list[str], operator.add]
def approve_a(state: State) -> State:
interrupt("approve a?")
runs["a"] += 1 # e.g. an API write
return {"log": ["a"]}
def approve_b(state: State) -> State:
interrupt("approve b?")
runs["b"] += 1
return {"log": ["b"]}
child = (
StateGraph(State)
.add_node("approve_a", approve_a)
.add_node("approve_b", approve_b)
.add_edge(START, "approve_a")
.add_edge(START, "approve_b")
.compile()
)
parent = (
StateGraph(State)
.add_node("child", child)
.add_edge(START, "child")
.compile(checkpointer=InMemorySaver())
)
config = {"configurable": {"thread_id": "1"}}
result = parent.invoke({"log": []}, config)
# Resume the two interrupts one at a time, each by its own id.
while pending := result.get("__interrupt__"):
result = parent.invoke(Command(resume={pending[0].id: "yes"}), config)
print("log: ", result["log"])
print("runs:", dict(runs))
assert runs == {"a": 1, "b": 1}, f"a completed node ran again: {dict(runs)}"Error Message and Stack Trace (if applicable)
log: ['a', 'b']
runs: {'a': 2, 'b': 1}
Traceback (most recent call last):
File "issue_repro.py", line 55, in <module>
assert runs == {"a": 1, "b": 1}, f"a completed node ran again: {dict(runs)}"
AssertionError: a completed node ran again: {'a': 2, 'b': 1}Description
What I'm doing. A subgraph has two parallel nodes, and each calls interrupt() before a side effect. I resume the interrupts one at a time, each by its interrupt id.
What I expect. Each node's side effect runs once. The node resumed first completes, and its writes are saved in the subgraph's checkpoint as pending writes. When I resume the second interrupt, the first node should be skipped, the same way it is when both nodes sit directly in the root graph. I checked the root-graph case and it runs each node once.
What happens instead.
- Resuming the second interrupt runs the first node again. Its saved
RESUMEwrite answers itsinterrupt()immediately, so it repeats its side effect without asking again. - With more parallel subgraphs, a completed node re-runs once for every later resume.
- The final state is still correct, because the re-run writes under the same task id.
Where we hit it. The graph is a deepagents agent. Its task tool runs a subagent, a langchain create_agent graph, so the subagent is a nested graph. The subagent makes two tool calls in one step, and each tool calls interrupt() for human approval before writing to an external API. Approving the first call runs its write. Approving the second call runs the second write and repeats the first one, so the external system gets a duplicate record.
Cause. Line numbers are from main at 07b33185.
PregelLoop.__init__setsself.is_replaying = CONFIG_KEY_CHECKPOINT_ID in config[CONF](pregel/_loop.py:315).- Every task config carries
CONFIG_KEY_CHECKPOINT_ID: None(pregel/_algo.py:745,921,1091and1232). A graph running inside a task therefore hasis_replaying == Trueon every run, including a plain resume. tick()re-applies saved writes to tasks that already succeeded only whennot self.is_replaying(pregel/_loop.py:662). The same guard appears at584,1609and1864. In a nested graph those writes are never re-applied, so completed tasks run again.
checkpointer=True does not help. Compiling the child with checkpointer=True, as recommended in #6223, gives the same {'a': 2, 'b': 1}, whether the child is a node or is invoked inside a node function. The measurements posted in #6792 on 1.0.8 and 1.2.11 agree.
The existing test misses it. test_parallel_interrupts_double in tests/test_pregel.py has this topology: a child graph with two parallel interrupting nodes, run twice through Send, with the interrupts resumed one at a time. It asserts only the final state and the number of invokes, and both are correct. With a counter added to each node, on 1.2.12, one node in each child ran 2 and 4 times.
Candidate fix. This keeps a nested graph in replay mode only while it is time traveling. _first() already computes that predicate for dropping stale RESUME writes. langgraphjs#2679 takes the same approach. Top-level graphs are unaffected.
--- a/libs/langgraph/langgraph/pregel/_loop.py
+++ b/libs/langgraph/langgraph/pregel/_loop.py
@@ -894,6 +894,12 @@ class PregelLoop:
or configurable.get(CONFIG_KEY_RESUMING, False)
)
)
+ if self.is_nested and not is_time_traveling:
+ # A nested graph always carries checkpoint_id (as None) in its
+ # config, so is_replaying is True even on a plain resume. Treat
+ # a plain resume as one, so tasks that already succeeded in this
+ # step keep their saved writes instead of running again.
+ self.is_replaying = False
if is_time_traveling:
self.checkpoint_pending_writes = [
w for w in self.checkpoint_pending_writes if w[1] != RESUMEWhat the fix changes.
- The repro above prints
runs: {'a': 1, 'b': 1}. - Counted
test_parallel_interrupts_double: each node runs once. - The same
create_agentsubagent topology as above, with a scalar resume: each tool's write happens once. NO_DOCKER=true uv run pytest tests/inlibs/langgraph: 2027 passed, 4 skipped.
Two simpler fixes that fail.
- Treating
checkpoint_id=Noneas not pinned (is_replaying = config[CONF].get(CONFIG_KEY_CHECKPOINT_ID) is not None) also removes the duplicates. It fails 27 subgraph time-travel tests intests/test_time_travel.py. - Applying the fix to every graph, not only nested ones, fails 5 tests in
tests/test_checkpoint_migration.py. They expect a top-levelCommand(resume=...)sent with an explicit oldercheckpoint_idto re-run the task.
System Info
OS: Darwin 24.6.0 (arm64) Python Version: 3.12.13
langgraph: 1.2.10 (also reproduced on 1.2.12) langgraph-checkpoint: 4.1.1 langchain_core: 1.5.3 langchain: 1.3.14 deepagents: 0.6.12 langgraph_sdk: 0.4.2
Source: langchain-ai/langgraph