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
Preserve scheduler parity across rollback
JPPhotofd9cb34cfbbf
diff --git a/invokeai/app/services/shared/README.md b/invokeai/app/services/shared/README.mdindex f4d7049c16..6ea17e7544 100644--- a/invokeai/app/services/shared/README.md+++ b/invokeai/app/services/shared/README.md@@ -192,6 +192,12 @@ currently additive. Ordinary static-DAG readiness comes from the generic schedulmaterialization and type-specific control paths remain authoritative for loop, branch, and workflow-call graphs. Afuture migration may make tokens authoritative only after compatibility is proven.+The generic scheduler is an in-memory graph-state component only. It does not+create, update, retry, cancel, delete, or recover `SessionQueueItem` rows and+does not own queue statuses or events. A graph containing a saved-workflow call+therefore stays on the legacy scheduler and the dedicated workflow-call queue+adapters.+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/execution_engine/scheduler.py b/invokeai/app/services/shared/execution_engine/scheduler.pyindex d2089430e4..64e08f7b8f 100644--- a/invokeai/app/services/shared/execution_engine/scheduler.py+++ b/invokeai/app/services/shared/execution_engine/scheduler.py@@ -201,9 +201,7 @@ class ExecutionScheduler:if not self._enqueued:return None- if self._active_class not in {- self.plan.nodes[node_id].class_name for node_id in self._enqueued- }:+ if self._active_class not in {self.plan.nodes[node_id].class_name for node_id in self._enqueued}:self._active_class = self._next_class()assert self._active_class is not Nonenode_id = self._next_id_for_class(self._active_class)diff --git a/invokeai/app/services/shared/graph.py b/invokeai/app/services/shared/graph.pyindex 5c4ddb4160..57ff412f0b 100644--- a/invokeai/app/services/shared/graph.py+++ b/invokeai/app/services/shared/graph.py@@ -4420,22 +4420,22 @@ class GraphExecutionState(BaseModel):queue.remove(value)def _reset_apply_derived_caches(self) -> None:- object.__setattr__(self, "_prepared_exec_registry", None)- object.__setattr__(self, "_if_branch_scheduler", None)- object.__setattr__(self, "_execution_materializer", None)- object.__setattr__(self, "_execution_scheduler", None)- object.__setattr__(self, "_generic_graph_scheduler", None)- object.__setattr__(self, "_execution_runtime", None)- object.__setattr__(self, "_if_branch_exclusive_sources", {})- object.__setattr__(self, "_source_graph_flat", None)- object.__setattr__(self, "_execution_graph_flat", None)- object.__setattr__(self, "_completed_source_ids_cache", None)- object.__setattr__(self, "_for_source_by_return_id", None)- object.__setattr__(self, "_for_parent_iteration_paths_cache", {})- object.__setattr__(self, "_all_for_contexts_finalized_cache", {})- object.__setattr__(self, "_prepared_for_index", None)- object.__setattr__(self, "_final_prepared_for_index", None)- object.__setattr__(self, "_prepared_for_index_by_exec", {})+ self._prepared_exec_registry = None+ self._if_branch_scheduler = None+ self._execution_materializer = None+ self._execution_scheduler = None+ self._generic_graph_scheduler = None+ self._execution_runtime = None+ self._if_branch_exclusive_sources = {}+ self._source_graph_flat = None+ self._execution_graph_flat = None+ self._completed_source_ids_cache = None+ self._for_source_by_return_id = None+ self._for_parent_iteration_paths_cache = {}+ self._all_for_contexts_finalized_cache = {}+ self._prepared_for_index = None+ self._final_prepared_for_index = None+ self._prepared_for_index_by_exec = {}def _type_key(self, node_obj: BaseInvocation) -> str:return node_obj.__class__.__name__@@ -5279,6 +5279,7 @@ class GraphExecutionState(BaseModel):transaction.rollback()finally:self._reset_apply_derived_caches()+ self._rehydrate_ready_queues()raisefinally:object.__setattr__(self, "_apply_transaction", None)diff --git a/tests/app/services/shared/test_execution_engine_scheduler.py b/tests/app/services/shared/test_execution_engine_scheduler.pyindex 3f89d7a3fe..dc260ce5d6 100644--- a/tests/app/services/shared/test_execution_engine_scheduler.py+++ b/tests/app/services/shared/test_execution_engine_scheduler.py@@ -9,7 +9,7 @@ from invokeai.app.services.shared.execution_engine.scheduler import (ExecutionPlan,ExecutionScheduler,)-from invokeai.app.services.shared.graph import Edge, EdgeConnection, Graph, GraphExecutionState+from invokeai.app.services.shared.graph import Edge, EdgeConnection, Graph, GraphExecutionState, _ExecutionSchedulerdef _plan() -> ExecutionPlan:@@ -234,15 +234,23 @@ def test_graph_state_static_dag_preserves_legacy_fifo_for_released_nodes() -> Nodestination=EdgeConnection(node_id="a", field="a"),))- state = GraphExecutionState(graph=graph)- trace: list[str] = []- while (node := state.next()) is not None:- trace.append(state.prepared_source_mapping[node.id])- state.complete(node.id, node.invoke(Mock()))+ def run(use_legacy_scheduler: bool) -> tuple[list[str], GraphExecutionState]:+ state = GraphExecutionState(graph=graph.model_copy(deep=True))+ if use_legacy_scheduler:+ object.__setattr__(state, "_execution_scheduler", _ExecutionScheduler(state))+ trace: list[str] = []+ while (node := state.next()) is not None:+ trace.append(state.prepared_source_mapping[node.id])+ state.complete(node.id, node.invoke(Mock()))+ return trace, state- assert trace == ["q", "p", "b", "a"]- assert state.is_complete()+ legacy_trace, legacy_state = run(use_legacy_scheduler=True)+ generic_trace, generic_state = run(use_legacy_scheduler=False)++ assert legacy_trace == generic_trace == ["q", "p", "b", "a"]+ assert legacy_state.is_complete()+ assert generic_state.is_complete()def test_graph_state_static_dag_delegates_readiness_to_generic_scheduler() -> None:@@ -280,6 +288,48 @@ def test_graph_state_static_dag_rehydrates_generic_scheduler_after_partial_run()assert restored.prepared_source_mapping[second.id] == "second"[email protected]("use_legacy_scheduler", [False, True])+def test_graph_state_static_dag_apply_and_rollback_match_scheduler_paths(use_legacy_scheduler: bool) -> None:+ graph = Graph()+ graph.add_node(AddInvocation(id="add", a=1, b=2))+ state = GraphExecutionState(graph=graph)+ if use_legacy_scheduler:+ object.__setattr__(state, "_execution_scheduler", _ExecutionScheduler(state))++ node = state.next()+ assert node is not None+ execution_ref = state.get_execution_ref(node.id)+ output = node.invoke(Mock())+ state.apply(execution_ref, output)+ assert {+ state.prepared_source_mapping[node_id] for node_id in state.executed if node_id in state.prepared_source_mapping+ } == {"add"}++ rollback_state = GraphExecutionState(graph=graph.model_copy(deep=True))+ if use_legacy_scheduler:+ object.__setattr__(rollback_state, "_execution_scheduler", _ExecutionScheduler(rollback_state))+ rollback_node = rollback_state.next()+ assert rollback_node is not None+ rollback_ref = rollback_state.get_execution_ref(rollback_node.id)+ original_record_effect_streams = rollback_state._record_effect_streams++ def fail_after_completion(*args: object, **kwargs: object) -> None:+ raise RuntimeError("effect recording failed")++ rollback_state._record_effect_streams = fail_after_completion # type: ignore[method-assign]+ try:+ with pytest.raises(RuntimeError, match="effect recording failed"):+ rollback_state.apply(rollback_ref, rollback_node.invoke(Mock()))+ finally:+ rollback_state._record_effect_streams = original_record_effect_streams # type: ignore[method-assign]++ assert rollback_state.executed == set()+ assert rollback_state.results == {}+ retried_node = rollback_state.next()+ assert retried_node is not None+ assert rollback_state.prepared_source_mapping[retried_node.id] == "add"++def test_graph_state_apply_rolls_back_generic_scheduler_transition() -> None:graph = Graph()graph.add_node(AddInvocation(id="add", a=1, b=2))