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): preserve compatibility adapter contexts
JPPhoto7076cf18e6e8
diff --git a/invokeai/app/services/shared/README.md b/invokeai/app/services/shared/README.mdindex 9f999df65c..31cd674316 100644--- a/invokeai/app/services/shared/README.md+++ b/invokeai/app/services/shared/README.md@@ -212,6 +212,22 @@ does not own queue statuses or events. A graph containing a saved-workflow calltherefore stays on the legacy scheduler and the dedicated workflow-call queueadapters.+Target migration contract: control-flow nodes remain concrete invocation+subclasses that declare frame-scoped data, activation, stream-closure, child,+and terminal effects. The generic scheduler selects nodes from required+effects for the current frame; it never receives a literal successor-node ID.+Current implementation is narrower: `IfInvocation` is the only control-flow+invocation using the effect recorder, while `Iterate`, `Collect`, `For`,+`ForReturn`, and workflow-call invocations remain on compatibility paths. The+generic scheduler currently consumes opaque plan dependencies, not token-built+successor topology. The current `If` adapter still owns branch topology and+compatibility skips, while loop and workflow-call adapters still own+materialization and durable queue lifecycle. Those owners may be removed only+after differential tests cover fresh, partially completed, rehydrated, failed,+canceled, and retried sessions. The frontend boundary remains frozen: this+refactoring does not modify `invokeai/frontend/...` or existing web/webv2+interactions.+Workflow-call note:- `GraphExecutionState` can represent a paused parent execution plus an attached child execution state, but it does notdiff --git a/invokeai/app/services/shared/graph.py b/invokeai/app/services/shared/graph.pyindex d7d6b055ad..459728d733 100644--- a/invokeai/app/services/shared/graph.py+++ b/invokeai/app/services/shared/graph.py@@ -2328,6 +2328,11 @@ class _GenericGraphSchedulerAdapter:) -> list[tuple[BaseInvocation, BaseInvocationOutput]]:if exec_node_id not in self._state.execution_graph.nodes:return []+ # A few compatibility callers register prepared execution nodes directly on the+ # execution graph. Ensure those nodes are represented in the opaque plan before+ # applying their completion, just as materialized nodes are.+ if exec_node_id not in self._scheduler.plan.nodes:+ self.register_node(exec_node_id)if exec_node_id not in self._state.indegree:raise KeyError(f"indegree missing for exec node {exec_node_id}")dependents = self._scheduler.plan.dependents(exec_node_id)diff --git a/tests/app/services/test_session_processor_callbacks.py b/tests/app/services/test_session_processor_callbacks.pyindex c402493af3..e5f0fd0465 100644--- a/tests/app/services/test_session_processor_callbacks.py+++ b/tests/app/services/test_session_processor_callbacks.py@@ -7,6 +7,7 @@ import pytestfrom invokeai.app.services.progress_previews.progress_previews_default import MemoryProgressPreviewsfrom invokeai.app.services.session_processor.session_processor_default import DefaultSessionRunner+from invokeai.app.services.shared.execution_effects import ExecutionEffectsRecorderfrom invokeai.app.services.shared.graph import CollectInvocation, Graph, GraphExecutionState, IterateInvocation@@ -32,7 +33,13 @@ def test_after_run_node_callback_receives_control_node_inputs(monkeypatch: pytesservices.performance_statistics.collect_stats.return_value = nullcontext()monkeypatch.setattr("invokeai.app.services.session_processor.session_processor_default.build_invocation_context",- lambda data, services, is_canceled: context_data.append(data) or None,+ lambda data, services, is_canceled: context_data.append(data)+ or SimpleNamespace(+ execution_effects=ExecutionEffectsRecorder(+ source_node_id=data.invocation.id,+ frame_path=data.execution_frame,+ )+ ),)def on_after_run_node(invocation, queue_item, output):diff --git a/tests/app/services/workflow_call_test_utils.py b/tests/app/services/workflow_call_test_utils.pyindex f17cf41502..aee545ba66 100644--- a/tests/app/services/workflow_call_test_utils.py+++ b/tests/app/services/workflow_call_test_utils.py@@ -15,6 +15,7 @@ from invokeai.app.invocations.workflow_return import (WorkflowReturnInvocation,WorkflowReturnOutput,)+from invokeai.app.services.invocation_cache.invocation_cache_memory import MemoryInvocationCachefrom invokeai.app.services.progress_previews.progress_previews_default import MemoryProgressPreviewsfrom invokeai.app.services.session_processor.session_processor_default import (DefaultSessionProcessor,@@ -25,6 +26,7 @@ from invokeai.app.services.session_processor.workflow_call_runtime import (WorkflowCallQueueLifecycle,)from invokeai.app.services.session_queue.session_queue_common import SessionQueueItemNotFoundError+from invokeai.app.services.shared.execution_effects import ExecutionEffectsRecorder, ExecutionInterfacefrom invokeai.app.services.shared.graph import Graph, GraphExecutionState, WorkflowCallFramefrom invokeai.app.services.workflow_records.workflow_records_common import WorkflowCategoryfrom tests.dangerously_run_function_in_subprocess import dangerously_run_function_in_subprocess@@ -833,6 +835,13 @@ def _build_workflow_runner(monkeypatch: pytest.MonkeyPatch, session_queue=None):lambda data, services, is_canceled: SimpleNamespace(_services=services,_data=data,+ execution_effects=(+ execution_effects := ExecutionEffectsRecorder(+ source_node_id=data.invocation.id,+ frame_path=data.execution_frame,+ )+ ),+ execution=ExecutionInterface(execution_effects),images=SimpleNamespace(get_dto=services.images.get_dto),boards=SimpleNamespace(get_all_image_names_for_board=services.board_images.get_all_board_image_names_for_board@@ -853,6 +862,7 @@ def _build_workflow_runner(monkeypatch: pytest.MonkeyPatch, session_queue=None):"events": events,"logger": _DummyLogger(),"configuration": _DummyConfig(),+ "invocation_cache": MemoryInvocationCache(max_cache_size=0),"workflow_records": workflow_records,"users": _DummyUsers(),"board_images": _DummyBoardImages(),@@ -1954,6 +1964,13 @@ def test_run_completes_call_saved_workflow_and_runs_downstream_nodes(downstream_outputs = [output for invocation, _queue_item, output in events.completed if invocation.get_type() == "if"]+ downstream_if_node_id = next(+ exec_node_id+ for exec_node_id, source_node_id in session.prepared_source_mapping.items()+ if source_node_id == "downstream-if"+ )+ downstream_if_ref = session.execution_refs[downstream_if_node_id]+ assert session.execution_effects[downstream_if_ref.reference_id]assert len(parent_outputs) == 1assert parent_outputs[0].values == {"result": [3]}assert len(downstream_outputs) == 1diff --git a/tests/test_graph_execution_state.py b/tests/test_graph_execution_state.pyindex 316c1d16c5..2b6d6f4bc3 100644--- a/tests/test_graph_execution_state.py+++ b/tests/test_graph_execution_state.py@@ -1,5 +1,6 @@from collections import defaultdict, dequefrom collections.abc import Iterator+from types import SimpleNamespacefrom typing import Any, Optionalfrom unittest.mock import Mock@@ -41,6 +42,8 @@ from invokeai.app.invocations.primitives import (from invokeai.app.services.invocation_cache.invocation_cache_memory import MemoryInvocationCachefrom invokeai.app.services.shared.execution_effects import (EmitEffect,+ ExecutionEffectsRecorder,+ ExecutionInterface,)from invokeai.app.services.shared.execution_effects import (ExecutionRef as ProtocolExecutionRef,@@ -48,6 +51,7 @@ from invokeai.app.services.shared.execution_effects import (from invokeai.app.services.shared.execution_effects import (ExecutionToken as ProtocolExecutionToken,)+from invokeai.app.services.shared.execution_state_migration import dump_execution_state, load_execution_statefrom invokeai.app.services.shared.graph import (CollectInvocation,Graph,@@ -3712,6 +3716,78 @@ def test_if_graph_state_resumes_resolved_branch_after_json_round_trip():assert "false_value" not in executed_source_ids+def test_if_graph_state_rehydrates_persisted_activation_over_stale_condition():+ graph = Graph()+ graph.add_node(BooleanInvocation(id="condition", value=True))+ graph.add_node(PromptTestInvocation(id="true_value", prompt="true branch"))+ graph.add_node(PromptTestInvocation(id="false_value", prompt="false branch"))+ graph.add_node(IfInvocation(id="if"))+ graph.add_node(PromptTestInvocation(id="selected_output"))++ graph.add_edge(create_edge("condition", "value", "if", "condition"))+ graph.add_edge(create_edge("true_value", "prompt", "if", "true_input"))+ graph.add_edge(create_edge("false_value", "prompt", "if", "false_input"))+ graph.add_edge(create_edge("if", "value", "selected_output", "prompt"))++ state = GraphExecutionState(graph=graph)+ for _ in range(2):+ invocation, output = invoke_next(state)+ assert invocation is not None+ assert output is not None++ if_node = state.next()+ assert isinstance(if_node, IfInvocation)+ if_exec_id = if_node.id+ context = SimpleNamespace(+ execution_effects=ExecutionEffectsRecorder(+ source_node_id=if_exec_id,+ frame_path=state._get_iteration_path(if_exec_id),+ )+ )+ context.execution = ExecutionInterface(context.execution_effects)+ run_result = if_node.invoke_internal_with_effects(context, Mock())+ state.apply(state.get_execution_ref(if_exec_id, effect_count=len(run_result.effects)), run_result)+ assert if_exec_id in state.executed+ assert state.execution_effects++ snapshot = dump_execution_state(state)+ snapshot["execution_graph"]["nodes"][if_exec_id]["condition"] = False++ restored = load_execution_state(snapshot)++ restored_if = restored.execution_graph.get_node(if_exec_id)+ assert isinstance(restored_if, IfInvocation)+ assert restored_if.condition is False+ assert restored._activation_gate(if_exec_id).selected_branch == "true_input"++ executed_source_ids = execute_all_nodes(restored)++ prepared_selected_output_id = next(iter(restored.source_prepared_mapping["selected_output"]))+ assert restored.results[prepared_selected_output_id].prompt == "true branch"+ assert set(executed_source_ids) == {"selected_output"}+ assert "false_value" not in executed_source_ids+++def test_late_prepared_node_completion_after_generic_scheduler_initialization():+ graph = Graph()+ graph.add_node(PromptTestInvocation(id="source", prompt="source"))+ state = GraphExecutionState(graph=graph)++ # Force generic scheduler construction before materializing late work.+ assert state.next() is not None++ late_node = PromptTestInvocation(id="late", prompt="late")+ state.execution_graph.add_node(late_node)+ state._register_prepared_exec_node(late_node.id, "late_source")+ state._prepared_registry().set_iteration_path(late_node.id, ())+ state.indegree[late_node.id] = 0++ state.complete(late_node.id, late_node.invoke(Mock(InvocationContext)))++ assert state.results[late_node.id].prompt == "late"+ assert late_node.id in state.executed++def test_graph_state_prepares_eagerly():"""Tests that all prepareable nodes are prepared"""graph = Graph()