Compare commits

...
Author SHA1 Message Date
Sydney Runkle 9f8e2c83ac error message 2026-03-09 11:20:47 -04:00
Sydney Runkle 4826222d4d raise on update input 2026-03-09 11:00:34 -04:00
2 changed files with 33 additions and 0 deletions
+8
View File
@@ -637,6 +637,14 @@ class PregelLoop:
# map command to writes
if isinstance(self.input, Command):
if self.input.update:
raise ValueError(
"Command(update=...) is not allowed as graph input. "
"To modify state before resuming, use graph.update_state(...) "
"to fork the graph state, then resume with Command(resume=...). "
"Note: Command(update=...) can still be used as a return "
"value from a node to update graph state during execution."
)
if (resume := self.input.resume) is not None:
if not self.checkpointer:
raise RuntimeError(
+25
View File
@@ -5850,6 +5850,31 @@ def test_task_before_interrupt_resume(
assert result == {"answers": ["answer1", "answer2"]}
def test_command_with_update_input_raises(
sync_checkpointer: BaseCheckpointSaver,
) -> None:
"""Test that Command(update=...) raises ValueError when used as graph input."""
@entrypoint(checkpointer=sync_checkpointer)
def workflow(inputs: str) -> str:
answer = interrupt("question")
return answer
config = {"configurable": {"thread_id": "1"}}
# First invocation triggers interrupt
result = workflow.invoke("start", config=config)
assert "__interrupt__" in result
# Command with update (and resume) should raise
with pytest.raises(ValueError, match="Command\\(update="):
workflow.invoke(Command(resume="answer", update={"foo": "bar"}), config=config)
# Command with update only (no resume) should also raise
with pytest.raises(ValueError, match="Command\\(update="):
workflow.invoke(Command(update={"foo": "bar"}), config=config)
def test_multiple_tasks_before_interrupt_resume(
sync_checkpointer: BaseCheckpointSaver,
) -> None: