Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

Fix saved workflow execution ledger completion

JPPhotoa7c666bed1c2
diff --git a/invokeai/app/services/session_processor/workflow_call_runtime.py b/invokeai/app/services/session_processor/workflow_call_runtime.py
index e85c07922d..94221852c8 100644
--- a/invokeai/app/services/session_processor/workflow_call_runtime.py
+++ b/invokeai/app/services/session_processor/workflow_call_runtime.py
@@ -158,6 +158,13 @@ class WorkflowCallQueueLifecycle:
return output
+ @staticmethod
+ def _apply_workflow_call_output(
+ queue_item: SessionQueueItem, invocation: CallSavedWorkflowInvocation, output: WorkflowReturnOutput
+ ) -> None:
+ execution_ref = queue_item.session.get_execution_ref(invocation.id)
+ queue_item.session.apply(execution_ref, output)
+
def resume_waiting_workflow_call(self, queue_item: SessionQueueItem) -> None:
invocation = self.get_waiting_workflow_call_invocation(queue_item)
child_session = queue_item.session.waiting_workflow_call_child_session
@@ -165,7 +172,7 @@ class WorkflowCallQueueLifecycle:
raise ValueError("Execution state is waiting on a workflow call but has no attached child session.")
output = self.get_child_workflow_return_output(child_session)
queue_item.session.end_waiting_on_workflow_call(status="completed")
- queue_item.session.complete(invocation.id, output)
+ self._apply_workflow_call_output(queue_item, invocation, output)
self._session_runner._on_after_run_node(invocation, queue_item, output)
def fail_waiting_workflow_call(self, queue_item: SessionQueueItem, error_message: str) -> None:
@@ -226,7 +233,7 @@ class WorkflowCallQueueLifecycle:
waiting_invocation = self.get_waiting_workflow_call_invocation(parent_queue_item)
parent_queue_item.session.end_waiting_on_workflow_call(status="completed")
parent_output = WorkflowReturnOutput(values=aggregated_values)
- parent_queue_item.session.complete(waiting_invocation.id, parent_output)
+ self._apply_workflow_call_output(parent_queue_item, waiting_invocation, parent_output)
self._session_runner._on_after_run_node(waiting_invocation, parent_queue_item, parent_output)
self._session_runner._services.session_queue.save_queue_item_session(
parent_queue_item.item_id, parent_queue_item.session
diff --git a/tests/app/services/test_workflow_call_runtime.py b/tests/app/services/test_workflow_call_runtime.py
index 6f8a469a89..d6a40af4a5 100644
--- a/tests/app/services/test_workflow_call_runtime.py
+++ b/tests/app/services/test_workflow_call_runtime.py
@@ -27,6 +27,10 @@ def test_workflow_call_queue_lifecycle_resumes_parent_from_completed_child(monke
workflow_call_tests.test_workflow_call_queue_lifecycle_resumes_parent_from_completed_child(monkeypatch)
+def test_resume_waiting_workflow_call_applies_parent_output_to_execution_ledger(monkeypatch) -> None:
+ workflow_call_tests.test_resume_waiting_workflow_call_applies_parent_output_to_execution_ledger(monkeypatch)
+
+
def test_run_preserves_canceled_child_workflow_chain_without_failing_parent(monkeypatch) -> None:
workflow_call_tests.test_run_preserves_canceled_child_workflow_chain_without_failing_parent(monkeypatch)
diff --git a/tests/app/services/workflow_call_test_utils.py b/tests/app/services/workflow_call_test_utils.py
index 34368cff03..1cdd66216f 100644
--- a/tests/app/services/workflow_call_test_utils.py
+++ b/tests/app/services/workflow_call_test_utils.py
@@ -1133,6 +1133,9 @@ class _WorkflowCallBoundarySession:
def complete(self, node_id: str, output) -> None:
self.completed.append((node_id, output))
+ def get_execution_ref(self, node_id: str, *, effect_count: int | None = None):
+ return SimpleNamespace(frame=SimpleNamespace(iteration_path=()))
+
def is_waiting_on_workflow_call(self) -> bool:
return self.waiting is not None
@@ -1538,6 +1541,53 @@ def test_workflow_call_queue_lifecycle_resumes_parent_from_completed_child(
]
assert len(parent_outputs) == 1
assert parent_outputs[0].values == {"result": [3]}
+ prepared_call_node_id = next(
+ exec_node_id
+ for exec_node_id, source_node_id in session.prepared_source_mapping.items()
+ if source_node_id == "call-node"
+ )
+ parent_ref = session.execution_refs[prepared_call_node_id]
+ assert session.execution_tokens[f"{parent_ref.reference_id}:values"].value == {"result": [3]}
+ assert session.execution_effects[parent_ref.reference_id] == []
+
+
+def test_resume_waiting_workflow_call_applies_parent_output_to_execution_ledger(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ runner, events, _workflow_records = _build_workflow_runner(monkeypatch)
+ lifecycle = WorkflowCallQueueLifecycle(runner)
+
+ parent_graph = Graph()
+ parent_graph.add_node(CallSavedWorkflowInvocation(id="call-node", workflow_id="workflow-a"))
+ parent_session = GraphExecutionState(graph=parent_graph)
+ parent_invocation = parent_session.next()
+ assert isinstance(parent_invocation, CallSavedWorkflowInvocation)
+ parent_session.begin_waiting_on_workflow_call(
+ parent_session.build_workflow_call_frame(parent_invocation.id, "workflow-a")
+ )
+
+ child_graph = Graph()
+ child_graph.add_node(WorkflowReturnInvocation(id="return"))
+ child_session = GraphExecutionState(graph=child_graph)
+ return_invocation = child_session.next()
+ assert isinstance(return_invocation, WorkflowReturnInvocation)
+ child_output = WorkflowReturnOutput(values={"result": 3})
+ child_session.complete(return_invocation.id, child_output)
+ parent_session.attach_waiting_workflow_call_child_session(child_session)
+
+ queue_item = SimpleNamespace(
+ item_id=1,
+ session=parent_session,
+ session_id=parent_session.id,
+ )
+ lifecycle.resume_waiting_workflow_call(queue_item)
+
+ assert not parent_session.is_waiting_on_workflow_call()
+ assert parent_session.results[parent_invocation.id] == child_output
+ parent_ref = parent_session.execution_refs[parent_invocation.id]
+ assert parent_session.execution_tokens[f"{parent_ref.reference_id}:values"].value == {"result": 3}
+ assert parent_session.execution_effects[parent_ref.reference_id] == []
+ assert [invocation.get_type() for invocation, _queue_item, _output in events.completed] == ["call_saved_workflow"]
def test_run_queue_item_tolerates_queue_item_deleted_mid_run(monkeypatch: pytest.MonkeyPatch) -> None: