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(execution): keep saved workflow If on fallback

JPPhoto8ab9edc0255b
diff --git a/invokeai/app/services/shared/README.md b/invokeai/app/services/shared/README.md
index f599116bcc..1699012552 100644
--- a/invokeai/app/services/shared/README.md
+++ b/invokeai/app/services/shared/README.md
@@ -8,12 +8,13 @@ Provide a typed, acyclic workflow model (**Graph**) plus a runtime scheduler (**
iterator patterns, tracks readiness via indegree (the number of incoming edges to a node in the directed graph), and
executes nodes from class-grouped ready queues. In normal execution, runtime expansion happens in a separate execution graph
instead of mutating the source graph. Ordinary static DAGs and legacy-shaped `If` graphs use the opaque `ExecutionPlan`
-and deterministic `ExecutionScheduler` in `execution_engine/scheduler.py`. For a fresh generic `If`, the dedicated
-`_IfActivationController` is the sole runtime dependency owner for `If` admission and produces opaque, frame-local
-activation dependencies. Legacy skipped-state projection remains only for old snapshots. Fresh `If` materialization
-prepares the condition boundary first, resolves the activation token, and attaches only the selected branch input.
+and deterministic `ExecutionScheduler` in `execution_engine/scheduler.py`. The bounded fresh flat `If` shape records
+opaque, frame-local activation dependencies privately; other fresh `If` shapes use the dedicated
+`_IfActivationController` as the fallback runtime dependency owner. Legacy skipped-state projection remains only for old
+snapshots. Fresh `If` materialization prepares the condition boundary first, resolves the activation token, and
+attaches only the selected branch input.
Unselected branch nodes are never prepared, skipped, or added to fresh execution history. Both scheduler adapters
-consume the controller's decisions without pruning execution edges or calling a type-specific branch scheduler.
+consume these dependency decisions without pruning execution edges or calling a type-specific branch scheduler.
Legacy skipped-state metadata remains only for snapshots that already contain the old projection. Branch-membership
analysis remains an internal author-graph admission decision.
Direct `Iterate`/`Collect` graphs that do not contain `If`, `For`, `ForReturn`, or saved-workflow control flow also use
@@ -243,7 +244,7 @@ and attaches only the selected branch input; rejected branch sources remain unpr
consumes those records through the opaque plan: its readiness
callback accepts a node only when the required private `ActivationGate` runtime state is resolved and a matching
persisted activation token is present for its frame, while rejected dependencies cause scheduler discard. Both scheduler
-adapters use this same dependency controller; neither prunes execution edges or calls a type-specific branch scheduler.
+adapters consume these dependency records; neither prunes execution edges or calls a type-specific branch scheduler.
The compatibility path still projects discarded prepared nodes into legacy skipped metadata for rehydration and
completion accounting when loading old execution graphs; fresh runs do not create those nodes. `apply()`
validates and persists the invocation-emitted effect afterward, replacing the compatibility token by stable identity.
@@ -406,14 +407,15 @@ Workflow-call note:
ready work. It owns iterator expansion, collector grouping, prepared-parent selection, and creation of execution-graph
edges. When matching prepared parents for a downstream exec node, skipped prepared exec nodes are ignored and cannot
be selected as live inputs.
-- `_IfActivationController` Owns all runtime `If` admission and compiles opaque, frame-local activation dependency
- records for prepared nodes. Fresh admission leaves rejected branch sources unprepared; legacy skipped-state
- projections remain loadable.
+- `_IfActivationController` Owns fallback runtime `If` admission and compiles opaque, frame-local activation dependency
+ records for prepared nodes. The bounded fresh flat `If` shape records those dependencies privately in graph state.
+ Fresh admission leaves rejected branch sources unprepared; legacy skipped-state projections remain loadable.
Branch-membership analysis remains internal to the controller.
- `_GenericGraphSchedulerAdapter` Projects the generic `ExecutionPlan`/`ExecutionScheduler` into the existing state
fields for ordinary static DAGs and legacy-shaped `If` graphs; the generic scheduler owns opaque readiness,
intentional discards, indegree transitions, deterministic ordering, claimed work, and completion. The adapter registers
- the controller's activation dependencies and checks private gate state plus persisted activation tokens. Fresh `If`
+ activation dependencies from bounded flat graph state or the fallback controller and checks private gate state plus
+ persisted activation tokens. Fresh `If`
branch nodes are admitted before materialization; legacy prepared nodes may still be discarded for compatibility.
`If` scheduling does not call a type-specific branch scheduler, prune, or delete execution edges.
- `_ExecutionScheduler` Owns materialized-graph indegree transitions, class-grouped ready queues, downstream release,
diff --git a/invokeai/app/services/shared/graph.py b/invokeai/app/services/shared/graph.py
index bdd66e7f58..aa1d499bf2 100644
--- a/invokeai/app/services/shared/graph.py
+++ b/invokeai/app/services/shared/graph.py
@@ -4685,7 +4685,17 @@ class GraphExecutionState(BaseModel):
return False
if_node = if_nodes[0]
if any(
- isinstance(node, (IfInvocation, ForInvocation, ForReturnInvocation, IterateInvocation, CollectInvocation))
+ isinstance(
+ node,
+ (
+ IfInvocation,
+ CallSavedWorkflowInvocation,
+ ForInvocation,
+ ForReturnInvocation,
+ IterateInvocation,
+ CollectInvocation,
+ ),
+ )
for node in self.graph.nodes.values()
if node is not if_node
):
diff --git a/tests/app/services/shared/test_execution_engine_differential.py b/tests/app/services/shared/test_execution_engine_differential.py
index 2d97afab12..44a7631716 100644
--- a/tests/app/services/shared/test_execution_engine_differential.py
+++ b/tests/app/services/shared/test_execution_engine_differential.py
@@ -8,6 +8,7 @@ from unittest.mock import Mock, patch
import pytest
from pydantic import ValidationError
+from invokeai.app.invocations.call_saved_workflow import CallSavedWorkflowInvocation
from invokeai.app.invocations.collections import CollectionConcatInvocation
from invokeai.app.invocations.logic import IfInvocation
from invokeai.app.invocations.loops import (
@@ -41,6 +42,7 @@ from tests.test_nodes import (
ErrorInvocation,
PolymorphicStringTestInvocation,
UnionCollectionTestInvocation,
+ create_edge,
create_loop_linkage,
)
@@ -2170,6 +2172,35 @@ def test_fresh_flat_if_records_dependencies_without_author_graph_branch_analysis
assert state.is_complete()
+def test_fresh_flat_if_with_saved_workflow_uses_controller_fallback(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ graph = _flat_if_graph()
+ graph.delete_node("sink")
+ graph.add_node(CallSavedWorkflowInvocation(id="call", workflow_id="saved-workflow"))
+ graph.add_edge(create_edge("if", "value", "call", "saved_workflow_input::input::value"))
+ state = GraphExecutionState(graph=graph)
+ branch_analysis_calls: list[tuple[str, str]] = []
+ original_branch_sources = graph_module._IfActivationController._branch_sources
+
+ def record_branch_analysis(
+ controller: graph_module._IfActivationController,
+ if_node_id: str,
+ branch_field: str,
+ source_graph: Any,
+ ) -> set[str]:
+ branch_analysis_calls.append((if_node_id, branch_field))
+ return original_branch_sources(controller, if_node_id, branch_field, source_graph)
+
+ monkeypatch.setattr(graph_module._IfActivationController, "_branch_sources", record_branch_analysis)
+
+ assert not state._can_use_fresh_flat_if_activation()
+ assert state._get_source_activation_dependencies("true_branch") == (
+ graph_module.ActivationDependency(owner_id="if", branch="true_input", frame=()),
+ )
+ assert branch_analysis_calls
+
+
@pytest.mark.parametrize(
("outer_condition", "inner_condition", "expected_trace", "expected_history", "expected_value"),
[