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 sibling For fan-in generically
JPPhoto8bcb82b0d386
diff --git a/docs/src/content/docs/contributing/loop-nodes.md b/docs/src/content/docs/contributing/loop-nodes.mdindex ad4f45ed2a..535738caab 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 sibling nested loops, and unsupported mixed control flow remain on the-compatibility scheduler; the narrow canonical two-level and exact fresh three-level serial nested-`For` shapes+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(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 sibling nested loops, and unsupported mixed shapes remain compatibility-owned. This migration does not modify any file under `invokeai/frontend/...`, including generated schemas; the existing+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 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 f0322876a9..f42c11835b 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`, deeper or multiple nested iterators,+helper. Four-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@@ -141,20 +141,20 @@ grouping, and empty-source handling on the legacy compatibility route.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, mixed,+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.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, mixed control flow, and saved-workflow calls remain+ 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 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, other empty/input-driven, mixed, and legacy-loaded shapes remain compatibility-owned.+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.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 remain compatibility-owned.+four-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 +276,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, saved-workflow calls, and unsupported mixed control-flow shapes outside the bounded per-item+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-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,@@ -290,7 +290,7 @@ for 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 outerextension 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`, nine-level+generic-routed; four-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,@@ -428,7 +428,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, or unsupported mixed loop shapes remain compatibility-owned; the narrow canonical two-level and exact fresh three-level serial nested-`For` shapes, the canonical bounded+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 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,7 +496,7 @@ 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, mixed-loop, and legacy-snapshot execution; those paths+four-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 supportedfresh static flat `For`/`ForReturn` shape, the exact bounded empty input-drivenflat shape, the narrow canonical two-level and exact fresh three-level serial nested-`For`diff --git a/invokeai/app/services/shared/graph.py b/invokeai/app/services/shared/graph.pyindex bdd881b1e5..2f1609baa4 100644--- a/invokeai/app/services/shared/graph.py+++ b/invokeai/app/services/shared/graph.py@@ -46,6 +46,7 @@ from invokeai.app.invocations.baseinvocation import (invocation_output, # noqa: F401)from invokeai.app.invocations.call_saved_workflow import CallSavedWorkflowInvocation+from invokeai.app.invocations.collections import CollectionConcatInvocationfrom invokeai.app.invocations.fields import Input, InputField, OutputField, OutputScope, UIType # noqa: F401from invokeai.app.invocations.logic import IfInvocationfrom invokeai.app.invocations.loops import (@@ -763,6 +764,114 @@ class GraphExecutionState(BaseModel):return self._apply_generic_for_continuation(exec_node_id, output)+ def _can_use_generic_two_sibling_nested_for_scheduler(+ self, for_nodes: list[ForInvocation], return_nodes: list[ForReturnInvocation], source_graph: Any+ ) -> bool:+ if len(for_nodes) != 3 or len(return_nodes) != 3 or len(self.graph.nodes) != 10 or len(self.graph.edges) != 13:+ return False++ outer_candidates = []+ nested_bodies = {}+ for node in for_nodes:+ nested_body = self.graph._get_supported_for_nested_for_body(node.id, source_graph)+ if nested_body is not None:+ nested_bodies[node.id] = nested_body+ if len(nested_body.inner_for_ids) == 2 and len(nested_body.continuation_nodes) == 1:+ outer_candidates.append(node)+ if len(outer_candidates) != 1:+ return False++ outer_for = outer_candidates[0]+ nested_body = nested_bodies[outer_for.id]+ child_ids = set(nested_body.inner_for_ids)+ if self.graph._get_input_edges(outer_for.id, COLLECTION_FIELD) or not outer_for.collection:+ return False+ outer_return_id = nested_body.outer_return_id+ child_return_ids = {self.graph._get_linked_for_return_id(child_id) for child_id in child_ids}+ if None in child_return_ids or child_return_ids | {outer_return_id} != {node.id for node in return_nodes}:+ return False++ join_id = next(iter(nested_body.continuation_nodes))+ join = self.graph.get_node(join_id)+ if not isinstance(join, CollectionConcatInvocation):+ return False+ join_inputs = self.graph._get_input_edges(join_id)+ if len(join_inputs) != 2 or {edge.destination.field for edge in join_inputs} != {"first", "second"}:+ return False+ if {edge.source.node_id for edge in join_inputs} != child_ids or any(+ edge.source.field != "output_collection" for edge in join_inputs+ ):+ return False++ outer_return_inputs = self.graph._get_input_edges(outer_return_id, "output")+ if len(outer_return_inputs) != 1 or (+ outer_return_inputs[0].source.node_id != join_id or outer_return_inputs[0].source.field != "collection"+ ):+ return False+ if self.graph._get_input_edges(outer_return_id) != outer_return_inputs:+ return False+ if self.graph._get_linked_for_return_id(outer_for.id) != outer_return_id:+ return False++ control_types = (ForInvocation, ForReturnInvocation, IterateInvocation, CollectInvocation, IfInvocation)+ outer_item_edges = self.graph._get_output_edges(outer_for.id, ITEM_FIELD)+ if len(outer_item_edges) != 2:+ return False+ body_ids: set[str] = set()++ for child_id in child_ids:+ child_collection_edges = self.graph._get_input_edges(child_id, COLLECTION_FIELD)+ if len(child_collection_edges) != 1 or self.graph._get_input_edges(child_id) != child_collection_edges:+ return False+ child_collection_edge = child_collection_edges[0]+ if child_collection_edge.source.node_id != outer_for.id or child_collection_edge.source.field != ITEM_FIELD:+ return False+ if child_collection_edges[0] not in outer_item_edges:+ return False++ child_return_id = self.graph._get_linked_for_return_id(child_id)+ if child_return_id is None:+ return False+ child_body_path = self.graph._get_for_body_path_to_return(child_id, source_graph)+ if child_body_path is None or len(child_body_path[0]) != 2 or child_body_path[1] != child_return_id:+ return False+ child_body_ids = child_body_path[0] - {child_return_id}+ if len(child_body_ids) != 1:+ return False+ body_id = next(iter(child_body_ids))+ body_ids.add(body_id)+ body = self.graph.get_node(body_id)+ if isinstance(body, control_types):+ return False+ body_inputs = self.graph._get_input_edges(body_id)+ body_outputs = self.graph._get_output_edges(body_id)+ if len(body_inputs) != 1 or len(body_outputs) != 1:+ return False+ if body_inputs[0].source.node_id != child_id or body_inputs[0].source.field != ITEM_FIELD:+ return False+ if self.graph._get_output_edges(child_id, ITEM_FIELD) != body_inputs:+ return False+ if body_outputs[0].destination.node_id != child_return_id or body_outputs[0].destination.field != "output":+ return False+ if self.graph._get_input_edges(child_return_id) != body_outputs:+ return False+ if self.graph._get_for_final_output_edges(child_id) != [+ edge for edge in self.graph._get_output_edges(child_id) if edge.source.field == "output_collection"+ ]:+ return False++ outer_final_edges = self.graph._get_for_final_output_edges(outer_for.id)+ if len(outer_final_edges) != 1 or outer_final_edges[0].source.field != "output_collection":+ return False+ after_id = outer_final_edges[0].destination.node_id+ after = self.graph.get_node(after_id)+ if isinstance(after, control_types) or outer_final_edges[0].destination.field != "value":+ return False+ if self.graph._get_input_edges(after_id) != outer_final_edges:+ return False+ expected_nodes = {outer_for.id, *child_ids, outer_return_id, join_id, after_id, *child_return_ids, *body_ids}+ return set(self.graph.nodes) == expected_nodes+def _can_use_generic_three_level_nested_for_scheduler(self, for_nodes: list[ForInvocation], return_nodes: list[ForReturnInvocation], source_graph: Any) -> bool:@@ -842,6 +951,8 @@ class GraphExecutionState(BaseModel):return self._can_use_generic_nested_iterate_scheduler(for_nodes, return_nodes)source_graph = self._get_source_graph_flat()if len(for_nodes) == 3 and len(return_nodes) == 3:+ if self._can_use_generic_two_sibling_nested_for_scheduler(for_nodes, return_nodes, source_graph):+ return Truereturn self._can_use_generic_three_level_nested_for_scheduler(for_nodes, return_nodes, source_graph)if len(for_nodes) == 2 and len(return_nodes) == 2:outer_for = next(diff --git a/tests/app/services/session_processor/test_for_loop_processor_sqlite.py b/tests/app/services/session_processor/test_for_loop_processor_sqlite.pyindex 1361e52a63..9283383f80 100644--- a/tests/app/services/session_processor/test_for_loop_processor_sqlite.py+++ b/tests/app/services/session_processor/test_for_loop_processor_sqlite.py@@ -151,6 +151,34 @@ def _build_nested_for_graph(*, fail_on: int | None = None) -> Graph:return graph+def _build_two_sibling_nested_for_fan_in_graph() -> Graph:+ graph = Graph()+ graph.add_node(ForInvocation(id="outer_for", collection=[[1, 2], [3, 4]]))+ graph.add_node(ForInvocation(id="left_for"))+ graph.add_node(ForInvocation(id="right_for"))+ graph.add_node(ForSqliteBodyInvocation(id="left_body"))+ graph.add_node(ForSqliteBodyInvocation(id="right_body"))+ graph.add_node(ForReturnInvocation(id="left_return"))+ graph.add_node(ForReturnInvocation(id="right_return"))+ graph.add_node(CollectionConcatInvocation(id="join"))+ graph.add_node(ForReturnInvocation(id="outer_return"))+ graph.add_node(ForSqliteAfterInvocation(id="after"))+ graph.add_edge(create_edge("outer_for", "item", "left_for", "collection"))+ graph.add_edge(create_edge("outer_for", "item", "right_for", "collection"))+ graph.add_edge(create_edge("left_for", "item", "left_body", "value"))+ graph.add_edge(create_edge("right_for", "item", "right_body", "value"))+ graph.add_edge(create_edge("left_body", "value", "left_return", "output"))+ graph.add_edge(create_edge("right_body", "value", "right_return", "output"))+ graph.add_edge(create_edge("left_for", "output_collection", "join", "first"))+ graph.add_edge(create_edge("right_for", "output_collection", "join", "second"))+ graph.add_edge(create_edge("join", "collection", "outer_return", "output"))+ graph.add_edge(create_edge("outer_for", "output_collection", "after", "collection"))+ graph.add_edge(create_loop_linkage("outer_for", "outer_return"))+ graph.add_edge(create_loop_linkage("left_for", "left_return"))+ graph.add_edge(create_loop_linkage("right_for", "right_return"))+ return graph++def _build_three_level_nested_for_graph() -> Graph:graph = Graph()graph.add_node(ForInvocation(id="outer_for", collection=[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]))@@ -606,6 +634,147 @@ def test_processor_sqlite_three_level_nested_for_cancel_restart_retry_isolates_eassert not completed_runtime.streams+def test_processor_sqlite_two_sibling_nested_for_cancel_root_retry_cleans_identity(+ monkeypatch: pytest.MonkeyPatch,+ mock_invoker: Invoker,+ registered_event_bus: _RecordingRegisteredEventService,+) -> None:+ monkeypatch.setattr(+ "invokeai.app.services.session_processor.session_processor_default.build_invocation_context",+ _build_test_invocation_context,+ )++ queue = SqliteSessionQueue(db=mock_invoker.services.board_records._db)+ mock_invoker.services.events = registered_event_bus+ mock_invoker.services.session_queue = queue+ mock_invoker.services.performance_statistics = _Stats()+ queue.start(mock_invoker)++ child_ids = {"left_for", "right_for"}+ cancel_requested = False++ def cancel_after_first_child_finalization(invocation, queue_item, output) -> None:+ del invocation, output+ nonlocal cancel_requested+ finalized_children = {+ source_id+ for source_id, _parent_path in queue_item.session.finalized_loop_contexts+ if source_id in child_ids+ }+ if not cancel_requested and len(finalized_children) == 1:+ cancel_requested = True+ queue.cancel_queue_item(queue_item.item_id)++ item_id = _insert_session(queue, _build_two_sibling_nested_for_fan_in_graph(), versioned=True)+ session_persisted = Event()+ processor = DefaultSessionProcessor(+ session_runner=DefaultSessionRunner(+ on_after_run_node_callbacks=[cancel_after_first_child_finalization],+ on_after_run_session_callbacks=[lambda queue_item: session_persisted.set()],+ ),+ polling_interval=0,+ )+ try:+ processor.start(mock_invoker)+ assert registered_event_bus.wait_for_status(item_id, "canceled")+ assert session_persisted.wait(timeout=5)+ finally:+ _stop_processor(processor)++ canceled_item = queue.get_queue_item(item_id)+ assert canceled_item.status == "canceled"+ assert cancel_requested+ assert not canceled_item.session.is_complete()+ assert len({source_id for source_id, _ in canceled_item.session.finalized_loop_contexts} & child_ids) == 1+ assert "outer_return" not in canceled_item.session.source_prepared_mapping+ assert "after" not in canceled_item.session.source_prepared_mapping+ canceled_snapshot = dump_execution_state(canceled_item.session)+ canceled_execution_ids = set(canceled_item.session.prepared_source_mapping)+ canceled_frame_ids = {+ reference.frame.frame_id+ for reference in canceled_item.session.execution_refs.values()+ if reference.frame.frame_id+ }+ assert canceled_frame_ids+ assert all(+ reference.state_id == canceled_item.session.id and reference.frame.state_id == canceled_item.session.id+ for reference in canceled_item.session.execution_refs.values()+ )++ with queue._db.transaction() as cursor:+ cursor.execute("UPDATE session_queue SET status = 'in_progress' WHERE item_id = ?", (item_id,))+ restarted_queue = SqliteSessionQueue(db=mock_invoker.services.board_records._db)+ restarted_queue.start(mock_invoker)+ mock_invoker.services.session_queue = restarted_queue+ reloaded_canceled_item = restarted_queue.get_queue_item(item_id)+ assert reloaded_canceled_item.status == "canceled"+ assert dump_execution_state(reloaded_canceled_item.session) == canceled_snapshot+ assert restarted_queue.dequeue() is None++ assert mock_invoker.services.session_queue is restarted_queue+ retry_result = restarted_queue.retry_items_by_id("default", [item_id])+ assert retry_result.retried_item_ids == [item_id]+ [retried_item] = [+ queue_item+ for queue_item in restarted_queue.list_all_queue_items("default")+ if queue_item.retried_from_item_id == item_id+ ]+ assert retried_item.session.id != canceled_item.session.id+ assert retried_item.session.results == {}+ assert retried_item.session.execution_refs == {}+ assert retried_item.session.execution_tokens == {}+ assert retried_item.session.execution_effects == {}+ assert not retried_item.session._generic_runtime().gates+ assert not retried_item.session._generic_runtime().streams+ assert not retried_item.session._generic_runtime().continuations++ retry_session_persisted = Event()+ retry_processor = DefaultSessionProcessor(+ session_runner=DefaultSessionRunner(+ on_after_run_session_callbacks=[lambda queue_item: retry_session_persisted.set()],+ ),+ polling_interval=0,+ )+ try:+ retry_processor.start(mock_invoker)+ assert registered_event_bus.wait_for_status(retried_item.item_id, "completed")+ assert retry_session_persisted.wait(timeout=5)+ finally:+ _stop_processor(retry_processor)++ canceled_item = restarted_queue.get_queue_item(item_id)+ completed_item = restarted_queue.get_queue_item(retried_item.item_id)+ assert canceled_item.status == "canceled"+ assert dump_execution_state(canceled_item.session) == canceled_snapshot+ assert completed_item.status == "completed"+ assert completed_item.session.is_complete()+ completed_execution_ids = set(completed_item.session.prepared_source_mapping)+ assert canceled_execution_ids.isdisjoint(completed_execution_ids)+ completed_frame_ids = {+ reference.frame.frame_id+ for reference in completed_item.session.execution_refs.values()+ if reference.frame.frame_id+ }+ assert completed_frame_ids+ assert all(+ reference.state_id == completed_item.session.id and reference.frame.state_id == completed_item.session.id+ for reference in completed_item.session.execution_refs.values()+ )+ assert canceled_frame_ids.isdisjoint(completed_frame_ids)+ [after_execution_id] = completed_item.session.source_prepared_mapping["after"]+ assert completed_item.session.results[after_execution_id].collection == [+ [1, 2, 1, 2],+ [3, 4, 3, 4],+ ]+ completed_runtime = completed_item.session._generic_runtime()+ assert not completed_runtime.gates+ assert not completed_runtime.streams+ assert all(+ continuation.frame.state_id == completed_item.session.id+ for continuation in completed_runtime.continuations.values()+ )++@pytest.mark.parametrize("outcome", ["success", "canceled", "failure"])def test_processor_sqlite_queue_nested_for_cleanup(monkeypatch: pytest.MonkeyPatch,diff --git a/tests/app/services/shared/test_execution_engine_differential.py b/tests/app/services/shared/test_execution_engine_differential.pyindex 6c71ce3c9a..4047bc6fd4 100644--- a/tests/app/services/shared/test_execution_engine_differential.py+++ b/tests/app/services/shared/test_execution_engine_differential.py@@ -41,6 +41,7 @@ from invokeai.app.services.shared.invocation_context import InvocationContextDatfrom tests.test_nodes import (AnyTypeTestInvocation,ErrorInvocation,+ MarkedAnyTypeTestInvocation,PolymorphicStringTestInvocation,UnionCollectionTestInvocation,create_edge,@@ -540,6 +541,42 @@ def _nested_for_graph(*, outer_collection: list[list[str]] | None = None) -> Grareturn graph+def _two_sibling_nested_for_fan_in_graph(+ *, outer_collection: list[list[str]] | None = None, outer_output_field: str = "output_collection"+) -> Graph:+ graph = Graph()+ graph.add_node(+ ForInvocation(id="outer_for", collection=[["a", "b"], ["c"]] if outer_collection is None else outer_collection)+ )+ graph.add_node(ForInvocation(id="left_for"))+ graph.add_node(ForInvocation(id="right_for"))+ graph.add_node(MarkedAnyTypeTestInvocation(id="left_body", marker="left:"))+ graph.add_node(MarkedAnyTypeTestInvocation(id="right_body", marker="right:"))+ graph.add_node(ForReturnInvocation(id="left_return"))+ graph.add_node(ForReturnInvocation(id="right_return"))+ graph.add_node(CollectionConcatInvocation(id="join"))+ graph.add_node(ForReturnInvocation(id="outer_return"))+ graph.add_node(AnyTypeTestInvocation(id="after"))++ def connect(source: str, source_field: str, destination: str, destination_field: str) -> None:+ graph.add_edge(create_edge(source, source_field, destination, destination_field))++ connect("outer_for", "item", "left_for", "collection")+ connect("outer_for", "item", "right_for", "collection")+ connect("left_for", "item", "left_body", "value")+ connect("right_for", "item", "right_body", "value")+ connect("left_body", "value", "left_return", "output")+ connect("right_body", "value", "right_return", "output")+ connect("left_for", "output_collection", "join", "first")+ connect("right_for", "output_collection", "join", "second")+ connect("join", "collection", "outer_return", "output")+ connect("outer_for", outer_output_field, "after", "value")+ graph.add_edge(create_loop_linkage("outer_for", "outer_return"))+ graph.add_edge(create_loop_linkage("left_for", "left_return"))+ graph.add_edge(create_loop_linkage("right_for", "right_return"))+ return graph++def _three_level_nested_for_graph(*, outer_collection: list[list[list[str]]] | None = None) -> Graph:graph = Graph()graph.add_node(@@ -2013,6 +2050,55 @@ def test_nested_for_generic_and_compatibility_paths_have_matching_completion() -assert compatibility_state.results[compatibility_after_exec_id].value == [["a", "b"], ["c"]]+def test_two_sibling_nested_for_fan_in_uses_generic_scheduler() -> None:+ compatibility_trace, compatibility_state = _run_graph(+ GraphExecutionState(graph=_two_sibling_nested_for_fan_in_graph()),+ force_compatibility_scheduler=True,+ )+ generic_trace, generic_state = _run_graph(GraphExecutionState(graph=_two_sibling_nested_for_fan_in_graph()))++ assert generic_trace == compatibility_trace+ assert isinstance(generic_state._execution_scheduler, _GenericGraphSchedulerAdapter)+ assert isinstance(compatibility_state._execution_scheduler, _ExecutionScheduler)+ assert generic_state.is_complete()+ assert compatibility_state.is_complete()+ assert _state_projection(generic_state) == _state_projection(compatibility_state)+ assert _source_output(generic_state, "after").value == [+ ["left:a", "left:b", "right:a", "right:b"],+ ["left:c", "right:c"],+ ]+++def test_two_sibling_nested_for_final_state_consumer_uses_compatibility_scheduler() -> None:+ state = GraphExecutionState(graph=_two_sibling_nested_for_fan_in_graph(outer_output_field="final_state"))+ trace, state = _run_graph(state)++ assert trace+ assert isinstance(state._execution_scheduler, _ExecutionScheduler)+ assert state.is_complete()+ assert _source_output(state, "after").value.values == {}+++def test_two_sibling_nested_for_fan_in_failure_matches_compatibility() -> None:+ generic_trace, generic_state = _run_graph_with_effects(+ GraphExecutionState(graph=_two_sibling_nested_for_fan_in_graph()),+ fail_source_id="left_body",+ )+ compatibility_trace, compatibility_state = _run_graph_with_effects(+ GraphExecutionState(graph=_two_sibling_nested_for_fan_in_graph()),+ force_compatibility_scheduler=True,+ fail_source_id="left_body",+ )++ assert generic_trace == compatibility_trace+ assert generic_state.has_error() and compatibility_state.has_error()+ assert generic_state.is_complete() and compatibility_state.is_complete()+ assert "join" not in generic_trace+ assert "outer_return" not in generic_trace+ assert "after" not in generic_trace+ assert _state_projection(generic_state) == _state_projection(compatibility_state)++def test_nested_for_generic_and_compatibility_paths_handle_empty_inner_collection() -> None:def run(force_compatibility: bool) -> tuple[list[str], GraphExecutionState]:state = GraphExecutionState(graph=_nested_for_graph(outer_collection=[[], ["c"]]))diff --git a/tests/test_nodes.py b/tests/test_nodes.pyindex 43d309484f..7b7d869465 100644--- a/tests/test_nodes.py+++ b/tests/test_nodes.py@@ -97,6 +97,14 @@ class AnyTypeTestInvocation(BaseInvocation):return AnyTypeTestInvocationOutput(value=self.value)+@invocation("test_marked_any", version="1.0.0")+class MarkedAnyTypeTestInvocation(AnyTypeTestInvocation):+ marker: str = InputField(default="")++ def invoke(self, context: InvocationContext) -> AnyTypeTestInvocationOutput:+ return AnyTypeTestInvocationOutput(value=f"{self.marker}{self.value}")++@invocation("test_polymorphic", version="1.0.0")class PolymorphicStringTestInvocation(BaseInvocation):value: Union[str, list[str]] = InputField(default="")