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.

refactor(execution): route bounded nested If chain

JPPhotofb3d966f46ab
diff --git a/docs/src/content/docs/contributing/loop-nodes.md b/docs/src/content/docs/contributing/loop-nodes.md
index 1d3ce64b1b..8bfcaec6a4 100644
--- a/docs/src/content/docs/contributing/loop-nodes.md
+++ b/docs/src/content/docs/contributing/loop-nodes.md
@@ -170,10 +170,12 @@ valid. A loaded terminal legacy state may retain its empty in-memory ledger for
`IfInvocation` now declares the same seam for branch activation: it emits one frame-scoped activation token for the
selected branch, and the graph state validates and persists it after invocation. Fresh graphs with one ordinary-node
`If`, the exact one-level nested shape with two `If` nodes where the inner value feeds one outer branch and has no
-other consumer, or exactly two or exactly three independent ordinary-node sibling `If`s compile opaque, frame-local
-activation dependencies in graph state. Four or more sibling `If`s, deeper nesting, fan-out, mixed, loop-containing,
-and saved-workflow shapes use the compatibility
-scheduler with the dedicated `_IfActivationController` fallback. Legacy snapshots retain their generic compatibility
+other consumer, the exact bounded three-`If` chain with direct inner-to-middle-to-outer branch edges, or exactly two
+or exactly three independent ordinary-node sibling `If`s compile opaque, frame-local activation dependencies in graph
+state. The three-`If` admission requires `default` edges, all branch inputs (`condition`, `true_input`, `false_input`) on
+each `If`, and no output from inner or middle `If` except its direct nested branch edge. Four-or-more nesting, fan-out,
+mixed, loop-containing, saved-workflow, legacy, and four-or-more sibling shapes use the compatibility scheduler with the
+dedicated `_IfActivationController` fallback. Legacy snapshots retain their generic compatibility
projection. Legacy
skipped-state projection remains only for old snapshots. Fresh materialization prepares the condition boundary,
resolves the activation token, and attaches only the selected branch input; unselected branch nodes remain unprepared.
diff --git a/invokeai/app/services/shared/README.md b/invokeai/app/services/shared/README.md
index e82bf2301e..c911eea855 100644
--- a/invokeai/app/services/shared/README.md
+++ b/invokeai/app/services/shared/README.md
@@ -10,12 +10,15 @@ executes nodes from class-grouped ready queues. In normal execution, runtime exp
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`. Fresh graphs with one ordinary-node `If`, the
exact one-level nested shape with two `If` nodes where the inner value feeds one outer branch and has no other
-consumer, or exactly two or exactly three independent ordinary-node sibling `If`s compile opaque, frame-local
-activation dependencies in `GraphExecutionState`; unsupported fresh shapes use the compatibility scheduler with the dedicated
+consumer, the exact bounded three-`If` chain where inner `value` feeds a middle branch and middle `value` feeds an outer
+branch, or exactly two or exactly three independent ordinary-node sibling `If`s compile opaque, frame-local activation
+dependencies in `GraphExecutionState`; unsupported fresh shapes use the compatibility scheduler with the dedicated
`_IfActivationController` fallback, while legacy snapshots retain their generic compatibility projection.
Current fresh sibling support includes exactly three independent `If`s with no nesting, fan-out, or other control-flow
-nodes. Four or more sibling `If`s, deeper nesting, fan-out, mixed, and saved-workflow shapes remain on the compatibility
-fallback. Legacy snapshots retain their generic compatibility projection and legacy skipped-state metadata.
+nodes. The bounded three-`If` chain requires direct `default` edges, all three `If`s to have `condition`, `true_input`,
+and `false_input` inputs, and inner/middle `If`s to have no output except their direct nested branch edge. Four or more
+nested `If`s, fan-out, mixed, loop-containing, saved-workflow, legacy, and four-or-more sibling shapes remain on the
+compatibility fallback. Legacy snapshots retain their generic compatibility projection and legacy skipped-state metadata.
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
@@ -258,11 +261,12 @@ port against the producing invocation's declared activation fields and persists
rehydration, every activation token is bound to a currently prepared owner and its derived execution reference; its
declared port, value, canonical token id, mapping key, and known frame fields must match. Unknown extra frame metadata
remains forward-compatible.
-For a fresh generic `If` graph with one ordinary-node `If`, the exact one-level nested shape described above, or exactly
-two or exactly three independent sibling `If`s, `GraphExecutionState` compiles opaque, frame-local activation-dependency
-records privately on each branch-local plan node. Four or more sibling `If`s, deeper nesting, fan-out, mixed,
-loop-containing, and saved-workflow shapes use the compatibility scheduler and `_IfActivationController` for the same
-records; legacy snapshots retain the generic compatibility projection and legacy skipped-state metadata. The controller
+For a fresh generic `If` graph with one ordinary-node `If`, the exact one-level nested shape described above, the exact
+bounded three-`If` inner/middle/outer chain, or exactly two or exactly three independent sibling `If`s,
+`GraphExecutionState` compiles opaque, frame-local activation-dependency records privately on each branch-local plan
+node. Four-or-more nesting, four-or-more sibling `If`s, fan-out, mixed, loop-containing, and saved-workflow shapes use
+the compatibility scheduler and `_IfActivationController` for the same records; legacy snapshots retain the generic
+compatibility projection and legacy skipped-state metadata. The controller
remains the fallback runtime dependency owner, and the schedulers no longer call a legacy compiler. Fresh materialization prepares the condition boundary, resolves the activation token,
and attaches only the selected branch input; rejected branch sources remain unprepared. `_GenericGraphSchedulerAdapter`
consumes those records through the opaque plan: its readiness
@@ -444,7 +448,8 @@ Workflow-call note:
points. The planner continues to use the graph state's journal, mappings, caches, and scheduler.
- `_IfActivationController` Owns fallback runtime `If` admission and compiles opaque, frame-local activation dependency
records for unsupported fresh shapes and legacy prepared nodes. Fresh ordinary-node single-`If` graphs, the bounded
- nested pair, and exactly two or three independent sibling `If`s compile those dependencies in graph state. Fresh admission leaves rejected
+ nested pair, the exact bounded three-`If` inner/middle/outer chain, and exactly two or three independent sibling `If`s
+ compile those dependencies in graph state. Fresh admission leaves rejected
branch sources unprepared; legacy skipped-state projections remain loadable.
- Private `graph_if_dependencies.py` compiles fresh activation dependencies, and
`graph_if_runtime.py` records dependencies and evaluates admission against gates and tokens.
diff --git a/invokeai/app/services/shared/graph.py b/invokeai/app/services/shared/graph.py
index c0cd108de2..dfb93c9b66 100644
--- a/invokeai/app/services/shared/graph.py
+++ b/invokeai/app/services/shared/graph.py
@@ -505,11 +505,7 @@ class _GenericGraphSchedulerAdapter:
last_plan_node = self._scheduler.plan.nodes.get(last_exec_node_id)
if last_plan_node is None:
return
- if any(
- self._scheduler.plan.nodes[ready_node_id].class_name == last_plan_node.class_name
- for ready_node_id in self._scheduler.ready_ids
- ):
- self._scheduler._active_class = last_plan_node.class_name
+ self._scheduler._active_class = last_plan_node.class_name
def _is_node_activation_ready(self, exec_node_id: str) -> bool:
"""Require every frame-local activation dependency to be satisfied."""
diff --git a/invokeai/app/services/shared/graph_if_dependencies.py b/invokeai/app/services/shared/graph_if_dependencies.py
index a717297dbe..bb3ffc3d23 100644
--- a/invokeai/app/services/shared/graph_if_dependencies.py
+++ b/invokeai/app/services/shared/graph_if_dependencies.py
@@ -77,31 +77,43 @@ def _can_use_fresh_flat_if_activation(state: "GraphExecutionState") -> bool:
return False
if any(edge.source.node_id in if_node_ids for edge in input_edges):
return False
- elif len(if_nodes) == 2 and len(nested_edges) == 1:
- nested_edge = nested_edges[0]
- if nested_edge.source.field != "value" or nested_edge.destination.field not in {
- "true_input",
- "false_input",
- }:
+ elif len(nested_edges) == len(if_nodes) - 1:
+ if any(
+ edge.source.field != "value" or edge.destination.field not in {"true_input", "false_input"}
+ for edge in nested_edges
+ ):
+ return False
+
+ nested_edge_by_source = {edge.source.node_id: edge for edge in nested_edges}
+ nested_destinations = {edge.destination.node_id for edge in nested_edges}
+ if len(nested_edge_by_source) != len(nested_edges) or len(nested_destinations) != len(nested_edges):
return False
- inner_if_id = nested_edge.source.node_id
- if any(edge.source.node_id == inner_if_id and edge != nested_edge for edge in state.graph.edges):
+ chain_start_ids = if_node_ids - nested_destinations
+ chain_end_ids = if_node_ids - set(nested_edge_by_source)
+ if len(chain_start_ids) != 1 or len(chain_end_ids) != 1:
+ return False
+
+ current_if_id = next(iter(chain_start_ids))
+ for _ in range(len(nested_edges)):
+ nested_edge = nested_edge_by_source.get(current_if_id)
+ if nested_edge is None:
+ return False
+ if any(edge.source.node_id == current_if_id and edge != nested_edge for edge in state.graph.edges):
+ return False
+ current_if_id = nested_edge.destination.node_id
+ if current_if_id not in chain_end_ids:
return False
- outer_if_id = nested_edge.destination.node_id
+ expected_input_fields = {"condition", "true_input", "false_input"}
for if_node in if_nodes:
- for field in ("condition", "true_input", "false_input"):
- input_edges = state.graph._get_input_edges(if_node.id, field)
- if len(input_edges) != 1:
- return False
- for edge in input_edges:
- if edge.source.node_id in if_node_ids and edge != nested_edge:
- return False
- if edge == nested_edge and (
- if_node.id != outer_if_id or field != nested_edge.destination.field
- ):
- return False
+ input_edges = state.graph._get_input_edges(if_node.id)
+ if (
+ len(input_edges) != len(expected_input_fields)
+ or {edge.destination.field for edge in input_edges} != expected_input_fields
+ or any(edge.source.node_id in if_node_ids and edge not in nested_edges for edge in input_edges)
+ ):
+ return False
else:
return False
diff --git a/tests/app/services/shared/test_execution_engine_differential.py b/tests/app/services/shared/test_execution_engine_differential.py
index 1698e54cb4..fce9eee064 100644
--- a/tests/app/services/shared/test_execution_engine_differential.py
+++ b/tests/app/services/shared/test_execution_engine_differential.py
@@ -124,6 +124,62 @@ def _nested_if_graph_with_shared_ancestor() -> Graph:
return graph
+def _three_nested_if_graph(
+ *,
+ outer_condition: bool = True,
+ middle_condition: bool = True,
+ inner_condition: bool = True,
+ middle_branch: str = "true_input",
+ outer_branch: str = "true_input",
+) -> Graph:
+ assert middle_branch in {"true_input", "false_input"}
+ assert outer_branch in {"true_input", "false_input"}
+ middle_other_branch = "false_input" if middle_branch == "true_input" else "true_input"
+ outer_other_branch = "false_input" if outer_branch == "true_input" else "true_input"
+ middle_other_id = "middle_false" if middle_branch == "true_input" else "middle_true"
+ outer_other_id = "outer_false" if outer_branch == "true_input" else "outer_true"
+ graph = Graph()
+ graph.add_node(BooleanInvocation(id="outer_condition", value=outer_condition))
+ graph.add_node(BooleanInvocation(id="middle_condition", value=middle_condition))
+ graph.add_node(BooleanInvocation(id="inner_condition", value=inner_condition))
+ graph.add_node(AddInvocation(id="inner_true", a=2, b=2))
+ graph.add_node(AddInvocation(id="inner_false", a=3, b=3))
+ graph.add_node(AddInvocation(id=middle_other_id, a=10, b=0))
+ graph.add_node(AddInvocation(id=outer_other_id, a=20, b=0))
+ graph.add_node(IfInvocation(id="inner_if"))
+ graph.add_node(IfInvocation(id="middle_if"))
+ graph.add_node(IfInvocation(id="outer_if"))
+ graph.add_node(AddInvocation(id="sink", b=1))
+
+ def connect(source: str, source_field: str, destination: str, destination_field: str) -> None:
+ graph.add_edge(
+ Edge(
+ source=EdgeConnection(node_id=source, field=source_field),
+ destination=EdgeConnection(node_id=destination, field=destination_field),
+ )
+ )
+
+ connect("inner_condition", "value", "inner_if", "condition")
+ connect("inner_true", "value", "inner_if", "true_input")
+ connect("inner_false", "value", "inner_if", "false_input")
+ connect("middle_condition", "value", "middle_if", "condition")
+ connect("inner_if", "value", "middle_if", middle_branch)
+ connect(middle_other_id, "value", "middle_if", middle_other_branch)
+ connect("outer_condition", "value", "outer_if", "condition")
+ connect("middle_if", "value", "outer_if", outer_branch)
+ connect(outer_other_id, "value", "outer_if", outer_other_branch)
+ connect("outer_if", "value", "sink", "a")
+ return graph
+
+
+def _three_nested_if_graph_with_shared_ancestor(**kwargs: bool) -> Graph:
+ graph = _three_nested_if_graph(**kwargs)
+ graph.add_node(AddInvocation(id="shared", a=1, b=1))
+ graph.add_edge(create_edge("shared", "value", "inner_true", "a"))
+ graph.add_edge(create_edge("shared", "value", "inner_false", "a"))
+ return graph
+
+
def _flat_if_graph(*, condition: bool = True) -> Graph:
graph = Graph()
graph.add_node(BooleanInvocation(id="condition", value=condition))
@@ -4262,6 +4318,184 @@ def test_fresh_nested_if_records_graph_state_dependencies_without_controller_ana
assert state.is_complete()
+ ("outer_condition", "middle_condition", "inner_condition", "selected", "expected_value", "expected_trace"),
+ [
+ (
+ True,
+ True,
+ True,
+ "inner_true",
+ 5,
+ [
+ "outer_condition",
+ "middle_condition",
+ "inner_condition",
+ "inner_true",
+ "inner_if",
+ "middle_if",
+ "outer_if",
+ "sink",
+ ],
+ ),
+ (
+ True,
+ True,
+ False,
+ "inner_false",
+ 7,
+ [
+ "outer_condition",
+ "middle_condition",
+ "inner_condition",
+ "inner_false",
+ "inner_if",
+ "middle_if",
+ "outer_if",
+ "sink",
+ ],
+ ),
+ (
+ True,
+ False,
+ True,
+ "middle_false",
+ 11,
+ ["outer_condition", "middle_condition", "middle_false", "middle_if", "outer_if", "sink"],
+ ),
+ (
+ True,
+ False,
+ False,
+ "middle_false",
+ 11,
+ ["outer_condition", "middle_condition", "middle_false", "middle_if", "outer_if", "sink"],
+ ),
+ (False, True, True, "outer_false", 21, ["outer_condition", "outer_false", "outer_if", "sink"]),
+ (False, True, False, "outer_false", 21, ["outer_condition", "outer_false", "outer_if", "sink"]),
+ (False, False, True, "outer_false", 21, ["outer_condition", "outer_false", "outer_if", "sink"]),
+ (False, False, False, "outer_false", 21, ["outer_condition", "outer_false", "outer_if", "sink"]),
+ ],
+)
+def test_fresh_three_nested_ifs_select_only_branches_and_match_compatibility(
+ outer_condition: bool,
+ middle_condition: bool,
+ inner_condition: bool,
+ selected: str,
+ expected_value: int,
+ expected_trace: list[str],
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ def fail_branch_analysis(*_: object, **__: object) -> set[str]:
+ raise AssertionError("fresh three-nested If used controller-owned branch analysis")
+
+ monkeypatch.setattr(graph_module._IfActivationController, "_branch_sources", fail_branch_analysis)
+ runs: list[tuple[list[str], GraphExecutionState]] = []
+ for force_compatibility_scheduler in (False, True):
+ state = GraphExecutionState(
+ graph=_three_nested_if_graph(
+ outer_condition=outer_condition,
+ middle_condition=middle_condition,
+ inner_condition=inner_condition,
+ )
+ )
+ assert state._can_use_fresh_flat_if_activation()
+ trace, state = _run_graph(state, force_compatibility_scheduler=force_compatibility_scheduler)
+ runs.append((trace, state))
+
+ assert trace == expected_trace
+ assert set(state.source_prepared_mapping) == set(expected_trace)
+ assert selected in trace
+ sink_id = next(iter(state.source_prepared_mapping["sink"]))
+ assert state.results[sink_id].value == expected_value
+ assert state.is_complete()
+
+ _assert_generic_and_compatibility_schedulers(runs[0][1], runs[1][1])
+ assert runs[0][0] == runs[1][0]
+ assert _state_projection(runs[0][1]) == _state_projection(runs[1][1])
+ assert _activation_projection(runs[0][1]) == _activation_projection(runs[1][1])
+
+
[email protected]("middle_branch", ["true_input", "false_input"])
[email protected]("outer_branch", ["true_input", "false_input"])
+def test_fresh_three_nested_ifs_support_direct_false_parent_branch_edges(
+ middle_branch: str,
+ outer_branch: str,
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ def fail_branch_analysis(*_: object, **__: object) -> set[str]:
+ raise AssertionError("fresh three-nested If used controller-owned branch analysis")
+
+ monkeypatch.setattr(graph_module._IfActivationController, "_branch_sources", fail_branch_analysis)
+ graph = _three_nested_if_graph(
+ outer_condition=outer_branch == "true_input",
+ middle_condition=middle_branch == "true_input",
+ middle_branch=middle_branch,
+ outer_branch=outer_branch,
+ )
+
+ runs: list[tuple[list[str], GraphExecutionState]] = []
+ for force_compatibility_scheduler in (False, True):
+ trace, state = _run_graph(
+ GraphExecutionState(graph=graph.model_copy(deep=True)),
+ force_compatibility_scheduler=force_compatibility_scheduler,
+ )
+ runs.append((trace, state))
+
+ assert trace == [
+ "outer_condition",
+ "middle_condition",
+ "inner_condition",
+ "inner_true",
+ "inner_if",
+ "middle_if",
+ "outer_if",
+ "sink",
+ ]
+ assert set(state.source_prepared_mapping) == set(trace)
+ assert state.results[next(iter(state.source_prepared_mapping["sink"]))].value == 5
+ assert state.is_complete()
+
+ _assert_generic_and_compatibility_schedulers(runs[0][1], runs[1][1])
+ assert runs[0][0] == runs[1][0]
+ assert _state_projection(runs[0][1]) == _state_projection(runs[1][1])
+
+
[email protected]("force_compatibility_scheduler", [False, True])
[email protected]("stop_after", range(1, 10))
+def test_fresh_three_nested_ifs_shared_ancestor_isolated_and_checkpoint_resumes(
+ force_compatibility_scheduler: bool,
+ stop_after: int,
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ def fail_branch_analysis(*_: object, **__: object) -> set[str]:
+ raise AssertionError("fresh three-nested If used controller-owned branch analysis")
+
+ monkeypatch.setattr(graph_module._IfActivationController, "_branch_sources", fail_branch_analysis)
+ graph = _three_nested_if_graph_with_shared_ancestor(
+ outer_condition=True, middle_condition=True, inner_condition=False
+ )
+ expected_trace, expected_state = _run_graph(GraphExecutionState(graph=graph.model_copy(deep=True)))
+ checkpoint_trace, checkpoint_state = _run_graph(
+ GraphExecutionState(graph=graph.model_copy(deep=True)),
+ force_compatibility_scheduler=force_compatibility_scheduler,
+ stop_after=stop_after,
+ )
+ restored = load_execution_state(dump_execution_state(checkpoint_state))
+ if force_compatibility_scheduler:
+ _restore_compatibility_scheduler(restored)
+ resumed_trace, resumed_state = _run_graph(restored, force_compatibility_scheduler=force_compatibility_scheduler)
+
+ combined_trace = checkpoint_trace + resumed_trace
+ assert combined_trace == expected_trace
+ assert resumed_state.executed_history == expected_state.executed_history
+ assert resumed_state.results[next(iter(resumed_state.source_prepared_mapping["sink"]))].value == 6
+ assert resumed_state.is_complete()
+ assert resumed_state.executed_history.count("shared") == 1
+ assert _state_projection(resumed_state) == _state_projection(expected_state)
+ assert _activation_projection(resumed_state) == _activation_projection(expected_state)
+
+
@pytest.mark.parametrize(
("outer_condition", "inner_condition", "expected_value"),
[(True, True, 5), (True, False, 6), (False, True, 11), (False, False, 11)],
diff --git a/tests/app/services/shared/test_graph_if_dependencies.py b/tests/app/services/shared/test_graph_if_dependencies.py
index 18f86a32ff..7ea5baf7c8 100644
--- a/tests/app/services/shared/test_graph_if_dependencies.py
+++ b/tests/app/services/shared/test_graph_if_dependencies.py
@@ -129,6 +129,27 @@ def _three_nested_if_graph() -> Graph:
return graph
+def _four_nested_if_graph() -> Graph:
+ graph = _three_nested_if_graph()
+ graph.delete_node("sink")
+ graph.add_node(BooleanInvocation(id="deepest_condition", value=True))
+ graph.add_node(AddInvocation(id="deepest_false", a=30, b=0))
+ graph.add_node(IfInvocation(id="deepest_if"))
+ graph.add_node(AddInvocation(id="sink", b=1))
+ graph.add_edge(_edge("deepest_condition", "value", "deepest_if", "condition"))
+ graph.add_edge(_edge("outer_if", "value", "deepest_if", "true_input"))
+ graph.add_edge(_edge("deepest_false", "value", "deepest_if", "false_input"))
+ graph.add_edge(_edge("deepest_if", "value", "sink", "a"))
+ return graph
+
+
+def _three_nested_if_fanout_graph() -> Graph:
+ graph = _three_nested_if_graph()
+ graph.add_node(AddInvocation(id="middle_side_consumer", b=1))
+ graph.add_edge(_edge("middle_if", "value", "middle_side_consumer", "a"))
+ return graph
+
+
def _indirectly_connected_if_graph() -> Graph:
graph = Graph()
graph.add_node(BooleanInvocation(id="first_condition", value=True))
@@ -335,7 +356,9 @@ def test_three_independent_sibling_ifs_admit_owner_local_frame_local_dependencie
("graph_factory", "source_node_id"),
[
pytest.param(lambda: _sibling_if_graph_with_count(4), "first_true", id="four-sibling-ifs"),
- pytest.param(_three_nested_if_graph, "inner_true", id="three-nested-ifs"),
+ pytest.param(_indirectly_connected_if_graph, "first_true", id="indirect-chain"),
+ pytest.param(_four_nested_if_graph, "inner_true", id="four-nested-ifs"),
+ pytest.param(_three_nested_if_fanout_graph, "inner_true", id="three-nested-if-fanout"),
],
)
def test_unsupported_if_shapes_use_controller_fallback(
@@ -360,6 +383,38 @@ def test_unsupported_if_shapes_use_controller_fallback(
assert calls == [(source_node_id, (9,))]
[email protected]("outer_condition", [False, True])
[email protected]("middle_condition", [False, True])
[email protected]("inner_condition", [False, True])
+def test_three_nested_ifs_admit_owner_and_frame_dependencies(
+ outer_condition: bool, middle_condition: bool, inner_condition: bool
+) -> None:
+ graph = _three_nested_if_graph()
+ graph.get_node("outer_condition").value = outer_condition
+ graph.get_node("middle_condition").value = middle_condition
+ graph.get_node("inner_condition").value = inner_condition
+ state = GraphExecutionState(graph=graph)
+
+ assert state._can_use_fresh_flat_if_activation()
+ assert state._get_source_activation_dependencies("inner_true", (1,)) == (
+ ActivationDependency(owner_id="inner_if", branch="true_input", frame=(1,)),
+ ActivationDependency(owner_id="middle_if", branch="true_input", frame=(1,)),
+ ActivationDependency(owner_id="outer_if", branch="true_input", frame=(1,)),
+ )
+ assert state._get_source_activation_dependencies("inner_false", (2,)) == (
+ ActivationDependency(owner_id="inner_if", branch="false_input", frame=(2,)),
+ ActivationDependency(owner_id="middle_if", branch="true_input", frame=(2,)),
+ ActivationDependency(owner_id="outer_if", branch="true_input", frame=(2,)),
+ )
+ assert state._get_source_activation_dependencies("middle_false", (3,)) == (
+ ActivationDependency(owner_id="middle_if", branch="false_input", frame=(3,)),
+ ActivationDependency(owner_id="outer_if", branch="true_input", frame=(3,)),
+ )
+ assert state._get_source_activation_dependencies("outer_false", (4,)) == (
+ ActivationDependency(owner_id="outer_if", branch="false_input", frame=(4,)),
+ )
+
+
def test_indirectly_connected_ifs_retain_controller_fallback(monkeypatch: pytest.MonkeyPatch) -> None:
state = GraphExecutionState(graph=_indirectly_connected_if_graph())
calls: list[tuple[str, str]] = []