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.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
fix(execution): ignore completed lifecycle effects during reload
JPPhotof3f59fdaef71
diff --git a/invokeai/app/services/shared/graph.py b/invokeai/app/services/shared/graph.pyindex 1a2e267f2e..88b5b14fb3 100644--- a/invokeai/app/services/shared/graph.py+++ b/invokeai/app/services/shared/graph.py@@ -2605,8 +2605,11 @@ class GraphExecutionState(BaseModel):effect_kinds = cls._lifecycle_effect_kinds(effects)return bool(effect_kinds & {"spawn_execution", "await"}) and "fail" not in effect_kinds+ def _is_pending_lifecycle_execution(self, exec_node_id: str, effects: Iterable[Any]) -> bool:+ return exec_node_id not in self.executed and self._is_pending_lifecycle_effects(effects)+def _update_pending_lifecycle_execution(self, exec_node_id: str, effects: Iterable[Any]) -> None:- if self._is_pending_lifecycle_effects(effects) and exec_node_id not in self.executed:+ if self._is_pending_lifecycle_execution(exec_node_id, effects):self._pending_lifecycle_execution_nodes.add(exec_node_id)else:self._pending_lifecycle_execution_nodes.discard(exec_node_id)@@ -2624,7 +2627,9 @@ class GraphExecutionState(BaseModel):ref = self._validate_execution_ref(execution_ref)persisted_effects = self.execution_effects.get(ref.reference_id)- pending_resume = persisted_effects is not None and self._is_pending_lifecycle_effects(persisted_effects)+ pending_resume = persisted_effects is not None and self._is_pending_lifecycle_execution(+ ref.exec_node_id, persisted_effects+ )if ref.exec_node_id in self.executed or (persisted_effects is not None and not pending_resume):raise ValueError(f"Execution reference {ref.reference_id} has already been applied")if pending_resume and self.is_waiting_on_workflow_call():@@ -3236,7 +3241,7 @@ class GraphExecutionState(BaseModel):execution_ref = references_by_id.get(reference_id)if execution_ref is None:raise ValueError("Execution effects contain an unknown execution reference")- lifecycle_pending = self._is_pending_lifecycle_effects(effects)+ lifecycle_pending = self._is_pending_lifecycle_execution(execution_ref.exec_node_id, effects)lifecycle_failed = "fail" in self._lifecycle_effect_kinds(effects)if execution_ref.exec_node_id not in self.results and not lifecycle_pending and not lifecycle_failed:raise ValueError("Execution effects belong to a pending execution node")@@ -3342,9 +3347,9 @@ class GraphExecutionState(BaseModel):reference.exec_node_idfor reference_id, effects in self.execution_effects.items()if effects- and self._is_pending_lifecycle_effects(effects)and (reference := references_by_id.get(reference_id)) is not Noneand reference.exec_node_id not in self.errors+ and self._is_pending_lifecycle_execution(reference.exec_node_id, effects)}self._rehydrate_runtime_state()diff --git a/tests/test_graph_execution_state.py b/tests/test_graph_execution_state.pyindex 684eb2544e..ef71c5ba77 100644--- a/tests/test_graph_execution_state.py+++ b/tests/test_graph_execution_state.py@@ -14,6 +14,7 @@ from invokeai.app.invocations.baseinvocation import (invocation,invocation_output,)+from invokeai.app.invocations.call_saved_workflow import CallSavedWorkflowInvocationfrom invokeai.app.invocations.collections import (CollectionCartesianInvocation,CollectionConcatInvocation,@@ -39,11 +40,14 @@ from invokeai.app.invocations.primitives import (BooleanOutput,IntegerCollectionInvocation,)+from invokeai.app.invocations.workflow_return import WorkflowReturnOutputfrom invokeai.app.services.invocation_cache.invocation_cache_memory import MemoryInvocationCachefrom invokeai.app.services.shared.execution_effects import (+ AwaitEffect,EmitEffect,ExecutionEffectsRecorder,ExecutionInterface,+ SpawnExecutionEffect,)from invokeai.app.services.shared.execution_effects import (ExecutionRef as ProtocolExecutionRef,@@ -3313,6 +3317,54 @@ def test_graph_execution_state_serializes_workflow_call_state():assert restored.max_workflow_call_depth == 4+def test_graph_state_rehydrates_after_a_completed_call_before_a_later_call_waits():+ graph = Graph()+ graph.add_node(CallSavedWorkflowInvocation(id="call_a", workflow_id="workflow-a"))+ graph.add_node(CallSavedWorkflowInvocation(id="call_b", workflow_id="workflow-b"))+ state = GraphExecutionState(graph=graph)++ def lifecycle_effects(reference: Any, child_id: str) -> list[Any]:+ owner = ProtocolExecutionRef(+ execution_node_id=reference.exec_node_id,+ state_id=reference.state_id,+ frame_path=reference.frame.iteration_path,+ frame_id=reference.frame.frame_id,+ workflow_call_depth=reference.frame.workflow_call_depth,+ )+ child = ProtocolExecutionRef(+ execution_node_id=child_id,+ state_id=reference.state_id,+ frame_path=reference.frame.iteration_path,+ frame_id=reference.frame.frame_id,+ workflow_call_depth=reference.frame.workflow_call_depth,+ )+ return [+ SpawnExecutionEffect(execution_ref=owner, parent=owner, graph={}, child_execution_id=child_id),+ AwaitEffect(execution_ref=owner, dependency=child),+ ]++ first = state.next()+ assert isinstance(first, CallSavedWorkflowInvocation)+ first_ref = state.get_execution_ref(first.id)+ state.apply(first_ref, WorkflowReturnOutput(values={}), effects=lifecycle_effects(first_ref, "child-a"))+ state.begin_waiting_on_workflow_call(state.build_workflow_call_frame(first.id, "workflow-a"))+ state = load_execution_state(dump_execution_state(state))++ state.end_waiting_on_workflow_call()+ state.apply(state.get_execution_ref(first.id), WorkflowReturnOutput(values={}))++ second = state.next()+ assert isinstance(second, CallSavedWorkflowInvocation)+ second_ref = state.get_execution_ref(second.id)+ state.apply(second_ref, WorkflowReturnOutput(values={}), effects=lifecycle_effects(second_ref, "child-b"))+ second_frame = state.build_workflow_call_frame(second.id, "workflow-b")+ state.begin_waiting_on_workflow_call(second_frame)++ restored = load_execution_state(dump_execution_state(state))++ assert restored.waiting_workflow_call == second_frame++def test_graph_waiting_on_workflow_call_blocks_until_suspended_node_is_completed():graph = Graph()graph.add_node(PromptTestInvocation(id="prompt_a", prompt="a"))