Skip to content

fix: include task in next if it has pending interrupt even with writes#6960

Open
yz (iCanDoAllThingszz) wants to merge 1 commit intolangchain-ai:mainfrom
iCanDoAllThingszz:fix/6956-interrupt-twice
Open

fix: include task in next if it has pending interrupt even with writes#6960
yz (iCanDoAllThingszz) wants to merge 1 commit intolangchain-ai:mainfrom
iCanDoAllThingszz:fix/6956-interrupt-twice

Conversation

@iCanDoAllThingszz
Copy link

Description

When a node calls interrupt() twice, after resuming from the first interrupt and hitting the second, get_state().next incorrectly returns an empty tuple even though the graph is still waiting for user input.

This happens because the RESUME pending write gets added to task.writes, which causes the task to be excluded from next (since the logic checks if not t.writes). However, if the task also has a pending interrupt, it should still be included in next.

Fix

This fix adds a check for pending interrupts: if a task has writes but also has a pending interrupt, it should still be included in next because the graph is waiting for user input.

Related Issue

Fixes #6956

Testing

Tested with the reproduction case from the issue:

from langgraph.checkpoint.memory import InMemorySaver
from langgraph.constants import START, END
from langgraph.graph import StateGraph
from langgraph.types import Command, interrupt

def ask_twice(state):
    interrupt("first question")
    interrupt("second question")

checkpointer = InMemorySaver()
builder = StateGraph(dict)
builder.add_node("ask_twice", ask_twice)
builder.add "ask_tw_edge(START,ice")
builder.add_edge("ask_twice", END)
graph = builder.compile(checkpointer=checkpointer)

config = {"configurable": {"thread_id": "1"}}

graph.invoke({}, config)
graph.invoke(Command(resume="ans1"), config)

snap = graph.get_state(config)
print(snap.next)  # Before fix: () | After fix: ("ask_twice",)

Checklist

  • I have tested the fix locally
  • I have added a test case for the bug
  • I have updated documentation if needed
  • I have run make format and make lint
When a node calls interrupt() twice, after resuming from the first interrupt
and hitting the second, get_state().next incorrectly returns empty tuple
even though the graph is still waiting for user input.

This happens because the RESUME pending write gets added to task.writes,
which causes the task to be excluded from next (since the logic checks
). However, if the task also has a pending interrupt,
it should still be included in next.

This fix adds a check for pending interrupts: if a task has writes but
also has a pending interrupt, it should still be included in next
because the graph is waiting for user input.

Fixes langchain-ai#6956
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant