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
refactor(execution): route four-level nested For
JPPhoto0ca641c93676
diff --git a/docs/src/content/docs/contributing/loop-nodes.md b/docs/src/content/docs/contributing/loop-nodes.mdindex 535738caab..c3334be495 100644--- a/docs/src/content/docs/contributing/loop-nodes.md+++ b/docs/src/content/docs/contributing/loop-nodes.md@@ -105,8 +105,8 @@ iteration, and finalizes the aggregate. An empty literal collection completes th`For` result without running the body or `ForReturn`. The generic scheduler remains opaque and never receives a literalsuccessor node ID. The compatibility continuation bridge is retained only for unsupported loop shapes and explicitlylegacy-loaded snapshots. Empty input-driven shapes outside the exact four-node/four-edge bounded topology, unsupported-input-driven outer collections, four-level-or-deeper or unsupported sibling nested loops, and unsupported mixed control flow remain on the-compatibility scheduler; the exact fresh two-sibling `For`/`ForReturn` `CollectionConcat` fan-in shape, the narrow canonical two-level, and exact fresh three-level serial nested-`For` shapes+input-driven outer collections, five-level-or-deeper or unsupported sibling nested loops, and unsupported mixed control flow remain on the+compatibility scheduler; the exact fresh two-sibling `For`/`ForReturn` `CollectionConcat` fan-in shape, the narrow canonical two-level, and exact fresh three-level and four-level serial nested-`For` shapes(one literal outer collection, one direct child at each level, no continuation nodes) and the exactbounded outer-`For`/`Iterate`/`Collect` shape are now generic-routed. This additive effect seam does not claim genericscheduling for the remaining shapes. `Iterate` records ordered item tokens in@@ -204,7 +204,7 @@ lowerings, legacy snapshots, and unsupported mixed loop shapes. No activation orgraph JSON.Exact fresh serial nested-`Iterate` chains through eight levels use the generic planner for ordered frame expansion,empty-stream closure, checkpoint rehydration, source completion, and failure parity. Nine-level or deeper chains,-other four-level-or-deeper or unsupported sibling nested loops, and unsupported mixed shapes remain compatibility-owned. The exact fresh two-sibling `For`/`ForReturn` `CollectionConcat` fan-in shape is generic-routed. This migration does not modify any file under `invokeai/frontend/...`, including generated schemas; the existing+five-level-or-deeper or unsupported sibling nested loops, and unsupported mixed shapes remain compatibility-owned. The exact fresh two-sibling `For`/`ForReturn` `CollectionConcat` fan-in shape and the exact fresh four-level serial nested-`For` shape are generic-routed. This migration does not modify any file under `invokeai/frontend/...`, including generated schemas; the existingfrontend/backend external interface remains frozen. Branch-membership analysis remains internal, while fresh executionno longer creates skipped-state projection and old snapshots retain it for compatibility.diff --git a/invokeai/app/services/shared/README.md b/invokeai/app/services/shared/README.mdindex f42c11835b..7a67120b10 100644--- a/invokeai/app/services/shared/README.md+++ b/invokeai/app/services/shared/README.md@@ -93,7 +93,7 @@ with one ordinary `outer For.output_collection` consumer, is also generic-routedThe nested planner owns per-outer-frame stream expansion, parent-frame streamidentity, empty closure, `Collect` readiness/hydration, checkpoint rehydration,and failure parity for this shape without calling the materializer's nested-copy-helper. Four-level-or-deeper or sibling nested `For` outside the exact two-sibling `CollectionConcat` fan-in shape, deeper or multiple nested iterators,+helper. Five-level-or-deeper or sibling nested `For` outside the exact two-sibling `CollectionConcat` fan-in shape, deeper or multiple nested iterators,other input-driven outer collections, other mixed control flow, and legacy snapshots retaincompatibility materializer ownership.The exact eight-node producer-driven extension—one inputless ordinary@@ -142,19 +142,22 @@ The exact seventeen-node/sixteen-edge serial chain extends the same planner toeight `Iterate` nodes and eight-component frame paths, with the sameempty-stream, checkpoint, source-completion, and failure-parity guarantees.Nine-level or deeper chains and all other expanded, fan-in, sibling shapes outside the exact two-sibling `For`/`ForReturn` `CollectionConcat` contract, mixed,-four-level-or-deeper `For`, `Collect`, and legacy shapes remain compatibility-owned.+five-level-or-deeper `For`, `Collect`, and legacy shapes remain compatibility-owned.A fresh graph with exactly one flat `For`/`ForReturn` pair and ordinary body nodes also uses the generic adapter for aliteral collection, a supported non-empty input-driven collection, or the exact four-node/four-edge empty input-drivenshape with one inputless producer and no downstream node. It projects readiness and invokes the graph-statecontinuation boundary, which selects the next iteration or finalizes the aggregate without exposing a successor node IDto the generic scheduler. The materializer still owns execution-node copies, input hydration, iteration paths, and body- expansion. Other empty/input-driven shapes, four-level-or-deeper or sibling loops outside the exact two-sibling nested-`For` `CollectionConcat` fan-in shape, mixed control flow, and saved-workflow calls remain+expansion. Other empty/input-driven shapes, five-level-or-deeper or sibling loops outside the exact two-sibling nested-`For` `CollectionConcat` fan-in shape, mixed control flow, and saved-workflow calls remainon the compatibility scheduler until their own differential gates are complete. One narrow fresh two-level nested-`For` shape (one non-empty literal outercollection, one inner `For` sourced from `outer.item`, and no continuation nodes) now uses the generic adapter;-deeper-than-three-level, multiple-child shapes outside the exact two-sibling `CollectionConcat` fan-in contract, other empty/input-driven, mixed, and legacy-loaded shapes remain compatibility-owned.+deeper-than-four-level, multiple-child shapes outside the exact two-sibling `CollectionConcat` fan-in contract, other empty/input-driven, mixed, and legacy-loaded shapes remain compatibility-owned.The exact fresh three-level serial nested-`For` shape (one literal outer collection,-one direct child at each level, no continuation nodes) also uses the generic adapter;-four-level-or-deeper and sibling nested-`For` shapes outside the exact two-sibling `CollectionConcat` fan-in contract remain compatibility-owned.+one direct child at each level, no continuation nodes) also uses the generic adapter. The exact fresh+four-level serial nested-`For` shape (one literal outer collection, one direct child at each level, no continuation+nodes) is also generic-routed. Its deepest-empty behavior matches compatibility at the trace, output, and completion+boundaries; the generic projection may retain synthetic empty-frame records. Five-level-or-deeper and sibling nested-`For` shapes outside the exact two-sibling+`CollectionConcat` fan-in contract remain compatibility-owned.The runtime also exposes an additive execution-engine seam: frame-scoped gates, ordered streams, continuations, andauthorized child-dependency records are stored in`invokeai.app.services.shared.execution_engine`; legacy graph and queue behavior is retained behind adapters while@@ -276,7 +279,7 @@ completion mirrors Iterate outputs into the stream ledger. A fresh graph with onincluding a supported non-empty input-driven collection producer or the exact bounded empty input-driven producershape, also uses the adapter for readiness and continuation transitions; graph state owns the invocation-specificcontinuation boundary while the generic scheduler remains opaque. Other empty or unsupported input-driven shapes,-four-level-or-deeper or sibling loops outside the exact two-sibling nested-`For` `CollectionConcat` fan-in contract, saved-workflow calls, and unsupported mixed control-flow shapes outside the bounded per-item+five-level-or-deeper or sibling loops outside the exact two-sibling nested-`For` `CollectionConcat` fan-in contract, saved-workflow calls, and unsupported mixed control-flow shapes outside the bounded per-itemtopology continue to usethe legacy compatibility scheduler until their differential coverage is complete. The narrow canonical two-levelnested-`For` shape, the canonical outer-`For`/bounded-`Iterate`/`Collect` shape,@@ -289,8 +292,8 @@ including an empty inner collection, remains isolated by its frame path. `Iteratfor this exact seven-node shape, the private nested planner owns per-outer-framecopy expansion, stream identity, empty closure, `Collect` readiness/hydration,checkpoint rehydration, and failure parity. The exact producer-driven outer-extension described above is also generic-routed. The exact fresh three-level serial nested-`For` shape is also-generic-routed; four-level-or-deeper or sibling nested `For` outside the exact two-sibling `CollectionConcat` fan-in contract, nine-level+extension described above is also generic-routed. The exact fresh three-level serial nested-`For` shape and the exact+fresh four-level serial nested-`For` shape are also generic-routed; five-level-or-deeper or sibling nested `For` outside the exact two-sibling `CollectionConcat` fan-in contract, nine-levelor deeper nested iterators, other input-driven outer collections, mixed controlflow, and legacy snapshots retain compatibility materializer ownership. Theexact nested-`Iterate` chains above do not admit `For`, `Collect`, fan-in, sibling,@@ -343,8 +346,8 @@ mutation helpers. Those helpers reject changes once the affected nodes have alre- **Ready queues grouped by class** (private projection): `_ready_queues: dict[class_name, deque[str]]` and`_active_class: Optional[str]`. Ordinary static DAGs and legacy-shaped `If` graphs derive readiness from the genericscheduler; the `If` adapter stores frame-local activation dependencies whose private gate state plus persisted token- checks control generic branch readiness. Supported static flat `For` graphs and the narrow canonical two-level nested- `For` shape, the exact producer-driven nested extension, the exact bounded empty input-driven flat `For`, the bounded+ checks control generic branch readiness. Supported static flat `For` graphs, the narrow canonical two-level nested+ `For` shape, the exact fresh three-level and four-level serial nested-`For` shapes, the exact producer-driven nested extension, the exact bounded empty input-driven flat `For`, the boundedtwo- through eight-level serial nested-`Iterate` chains, and the bounded per-item `Iterate`/`If`/`Collect` topology usethe generic adapter for readiness and continuation projection; other unsupported input-driven, nine-level or deeper,mixed graphs outside that topology, and saved-workflow graphs retain the legacy scheduler. Optional@@ -428,7 +431,7 @@ the generic path completes through the existing synthetic terminal `For` resultThe generic scheduler receives only opaque node IDs and dependencies; it never receives a literal next node ID. Thecompatibility continuation bridge remains available only for unsupported loop shapes and explicitly legacy-loaded snapshots.The exact four-node/four-edge empty input-driven shape with one inputless static-list producer is also generic-routed.-Other input-driven outer collections, four-level-or-deeper or sibling nested loops outside the exact two-sibling `CollectionConcat` fan-in contract, or unsupported mixed loop shapes remain compatibility-owned; the exact fresh two-sibling `For`/`ForReturn` `CollectionConcat` fan-in shape, the narrow canonical two-level and exact fresh three-level serial nested-`For` shapes, the canonical bounded+Other input-driven outer collections, five-level-or-deeper or sibling nested loops outside the exact two-sibling `CollectionConcat` fan-in contract, or unsupported mixed loop shapes remain compatibility-owned; the exact fresh two-sibling `For`/`ForReturn` `CollectionConcat` fan-in shape, the narrow canonical two-level, and exact fresh three-level and four-level serial nested-`For` shapes, the canonical boundedinternal `Iterate`/`Collect` shape, the exact producer-driven outer nested extension, and the bounded two- throughsix-, seven-, and eight-level serial nested-`Iterate` chains are generic-routed. Onrehydration, the generic adapter restores the active class-drain@@ -496,11 +499,11 @@ compatibility loader. `For` start payloads must match the prepared index, collecseam: the generic adapter calls the graph-state generic continuation boundary,which creates the next prepared iteration, aggregates outputs, and finalizes thesupported flat loop. The compatibility bridge remains for other unsupported input-driven,-four-level-or-deeper/sibling nested outside the exact two-sibling `CollectionConcat` fan-in contract, mixed-loop, and legacy-snapshot execution; those paths+five-level-or-deeper/sibling nested outside the exact two-sibling `CollectionConcat` fan-in contract, mixed-loop, and legacy-snapshot execution; those pathsretain their existing materialization and linkage ownership. The supported-fresh static flat `For`/`ForReturn` shape, the exact bounded empty input-driven-flat shape, the narrow canonical two-level and exact fresh three-level serial nested-`For`-nested-`For` shape, and the canonical bounded internal `Iterate`/`Collect`+ fresh static flat `For`/`ForReturn` shape, the exact bounded empty input-driven+ flat shape, the narrow canonical two-level and exact fresh three-level and four-level serial nested-`For`+ shapes, and the canonical bounded internal `Iterate`/`Collect`shape use the generic adapter. For`If`, generic readiness consumes opaque frame-local plan dependencies and requiresboth matching private `ActivationGate` runtime state and a persisted activation token. Fresh resolution attaches onlydiff --git a/tests/app/services/shared/test_execution_engine_differential.py b/tests/app/services/shared/test_execution_engine_differential.pyindex e40e681b98..08a8846361 100644--- a/tests/app/services/shared/test_execution_engine_differential.py+++ b/tests/app/services/shared/test_execution_engine_differential.py@@ -2382,6 +2382,19 @@ def test_four_level_nested_for_generic_rehydrates_without_replaying_completed_boassert isinstance(resumed_state._execution_scheduler, _GenericGraphSchedulerAdapter)assert _state_projection(resumed_state) == _state_projection(expected_state)+ compatibility_partial_trace, compatibility_partial_state = _run_graph(+ GraphExecutionState(graph=_four_level_nested_for_graph()),+ force_compatibility_scheduler=True,+ stop_after=6,+ )+ compatibility_resumed_trace, compatibility_resumed_state = _run_graph(+ load_execution_state(dump_execution_state(compatibility_partial_state)),+ force_compatibility_scheduler=True,+ )++ assert compatibility_partial_trace + compatibility_resumed_trace == expected_trace+ assert _state_projection(compatibility_resumed_state) == _state_projection(expected_state)+def test_four_level_nested_for_generic_failure_matches_compatibility() -> None:generic_trace, generic_state = _run_graph_with_effects(