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): harden sibling If fallback and checkpoints

JPPhotoecde7ddd9c51
diff --git a/docs/src/content/docs/contributing/loop-nodes.md b/docs/src/content/docs/contributing/loop-nodes.md
index 53f8e9766a..495621ae1a 100644
--- a/docs/src/content/docs/contributing/loop-nodes.md
+++ b/docs/src/content/docs/contributing/loop-nodes.md
@@ -169,9 +169,11 @@ 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`, or the exact one-level nested shape with two `If` nodes where the inner value feeds one outer branch and has no
-other consumer, compile opaque, frame-local activation dependencies in graph state. Sibling, deeper, fan-out, mixed,
-loop-containing, saved-workflow, and legacy shapes use the dedicated `_IfActivationController` fallback. Legacy
+`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 independent ordinary-node sibling `If`s compile opaque, frame-local activation
+dependencies in graph state. Deeper, fan-out, mixed, loop-containing, and saved-workflow 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.
The generic and compatibility adapters consume the same decisions and append-only execution edges; no type-specific
diff --git a/invokeai/app/services/shared/README.md b/invokeai/app/services/shared/README.md
index f61f136c5b..a9cdabf602 100644
--- a/invokeai/app/services/shared/README.md
+++ b/invokeai/app/services/shared/README.md
@@ -8,10 +8,11 @@ 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`. Fresh graphs with one ordinary-node `If`, or
-the exact one-level nested shape with two `If` nodes where the inner value feeds one outer branch and has no other
-consumer, compile opaque, frame-local activation dependencies in `GraphExecutionState`; sibling, deeper, fan-out,
-mixed, loop-containing, saved-workflow, and legacy shapes use the dedicated `_IfActivationController` fallback.
+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 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.
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
@@ -254,10 +255,11 @@ 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`, or the exact one-level nested shape described above,
-`GraphExecutionState` compiles opaque, frame-local activation-dependency records privately on each branch-local plan
-node. Sibling, deeper, fan-out, mixed, loop-containing, saved-workflow, and legacy shapes use `_IfActivationController`
-for the same records. The controller
+For a fresh generic `If` graph with one ordinary-node `If`, the exact one-level nested shape described above, or exactly
+two independent sibling `If`s, `GraphExecutionState` compiles opaque, frame-local activation-dependency records privately
+on each branch-local plan node. Deeper, 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. 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
diff --git a/invokeai/app/services/shared/graph.py b/invokeai/app/services/shared/graph.py
index 0514ef6b89..c0cd108de2 100644
--- a/invokeai/app/services/shared/graph.py
+++ b/invokeai/app/services/shared/graph.py
@@ -385,6 +385,13 @@ class _ExecutionScheduler:
def get_next_node(self) -> Optional[BaseInvocation]:
"""Gets the next ready node: FIFO within class, drain class before switching."""
while True:
+ if not self._state._active_class and self._state.results:
+ last_exec_node_id = next(reversed(self._state.results))
+ last_node = self._state.execution_graph.nodes.get(last_exec_node_id)
+ if last_node is not None:
+ last_class = self._state._type_key(last_node)
+ if self._state._ready_queues.get(last_class):
+ self._state._active_class = last_class
if self._state._active_class:
q = self._state._ready_queues.get(self._state._active_class)
while q:
@@ -1411,6 +1418,10 @@ class GraphExecutionState(BaseModel):
def _can_use_generic_scheduler(self) -> bool:
"""Use generic readiness for static graphs and supported direct control flow."""
+ if any(isinstance(node, IfInvocation) for node in self.graph.nodes.values()):
+ if not self._legacy_snapshot_loaded and not self._can_use_fresh_flat_if_activation():
+ return False
+
control_nodes = (ForInvocation, ForReturnInvocation)
if any(isinstance(node, control_nodes) for node in self.graph.nodes.values()):
return self._can_use_generic_for_scheduler()
diff --git a/invokeai/app/services/shared/graph_if_dependencies.py b/invokeai/app/services/shared/graph_if_dependencies.py
index 920389b9b3..4415deb758 100644
--- a/invokeai/app/services/shared/graph_if_dependencies.py
+++ b/invokeai/app/services/shared/graph_if_dependencies.py
@@ -60,31 +60,50 @@ def _can_use_fresh_flat_if_activation(state: "GraphExecutionState") -> bool:
for edge in state.graph.edges
if edge.source.node_id in if_node_ids and edge.destination.node_id in if_node_ids
]
- if len(nested_edges) != 1:
- return False
-
- nested_edge = nested_edges[0]
- if nested_edge.source.field != "value" or nested_edge.destination.field not in {
- "true_input",
- "false_input",
- }:
- 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):
- return False
-
- outer_if_id = nested_edge.destination.node_id
- 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:
+ if not nested_edges:
+ expected_input_fields = {"condition", "true_input", "false_input"}
+ if any(
+ source_if.id != destination_if.id and nx.has_path(source_graph, source_if.id, destination_if.id)
+ for source_if in if_nodes
+ for destination_if in if_nodes
+ ):
+ return False
+ for if_node in if_nodes:
+ 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
+ ):
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):
+ if any(edge.source.node_id in if_node_ids for edge in input_edges):
+ return False
+ elif 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",
+ }:
+ 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):
+ return False
+
+ outer_if_id = nested_edge.destination.node_id
+ 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
+ else:
+ return False
return True
diff --git a/tests/app/services/shared/test_execution_engine_differential.py b/tests/app/services/shared/test_execution_engine_differential.py
index 8bbdcdd4bf..31ae4aca1b 100644
--- a/tests/app/services/shared/test_execution_engine_differential.py
+++ b/tests/app/services/shared/test_execution_engine_differential.py
@@ -157,6 +157,53 @@ def _noncanonical_flat_if_graph(*, condition: bool = True) -> Graph:
return graph
+def _sibling_if_graph(
+ *, first_condition: bool = True, second_condition: bool = True, with_shared_ancestor: bool = False
+) -> Graph:
+ graph = Graph()
+ graph.add_node(BooleanInvocation(id="first_condition", value=first_condition))
+ graph.add_node(BooleanInvocation(id="second_condition", value=second_condition))
+ graph.add_node(AddInvocation(id="first_true", b=3))
+ graph.add_node(AddInvocation(id="first_false", a=10, b=1))
+ graph.add_node(AddInvocation(id="second_true", b=4))
+ graph.add_node(AddInvocation(id="second_false", a=20, b=1))
+ graph.add_node(IfInvocation(id="first_if"))
+ graph.add_node(IfInvocation(id="second_if"))
+ graph.add_node(AddInvocation(id="first_sink", b=100))
+ graph.add_node(AddInvocation(id="second_sink", b=200))
+
+ 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),
+ )
+ )
+
+ if with_shared_ancestor:
+ graph.add_node(AddInvocation(id="shared", a=1, b=1))
+ connect("shared", "value", "first_true", "a")
+ connect("shared", "value", "second_true", "a")
+ connect("first_condition", "value", "first_if", "condition")
+ connect("first_true", "value", "first_if", "true_input")
+ connect("first_false", "value", "first_if", "false_input")
+ connect("second_condition", "value", "second_if", "condition")
+ connect("second_true", "value", "second_if", "true_input")
+ connect("second_false", "value", "second_if", "false_input")
+ connect("first_if", "value", "first_sink", "a")
+ connect("second_if", "value", "second_sink", "a")
+ return graph
+
+
+def _indirectly_connected_sibling_if_graph() -> Graph:
+ graph = _sibling_if_graph()
+ graph.delete_node("second_true")
+ graph.add_node(AddInvocation(id="bridge", b=5))
+ graph.add_edge(create_edge("first_if", "value", "bridge", "a"))
+ graph.add_edge(create_edge("bridge", "value", "second_if", "true_input"))
+ return graph
+
+
def _flat_for_graph(
*,
with_after: bool = False,
@@ -3764,6 +3811,175 @@ def test_fresh_flat_if_records_dependencies_without_author_graph_branch_analysis
assert state.is_complete()
+ ("first_condition", "second_condition"),
+ [(True, True), (True, False), (False, True), (False, False)],
+)
+def test_fresh_sibling_ifs_preserve_owner_local_selection_and_scheduler_parity(
+ first_condition: bool,
+ second_condition: bool,
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ def fail_branch_analysis(*_: object, **__: object) -> set[str]:
+ raise AssertionError("fresh sibling 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=_sibling_if_graph(first_condition=first_condition, second_condition=second_condition)
+ )
+ assert state._can_use_fresh_flat_if_activation()
+ trace, state = _run_graph(state, force_compatibility_scheduler=force_compatibility_scheduler)
+ runs.append((trace, state))
+
+ expected_sources = {
+ "first_condition",
+ "second_condition",
+ "first_if",
+ "second_if",
+ "first_sink",
+ "second_sink",
+ }
+ expected_sources.add("first_true" if first_condition else "first_false")
+ expected_sources.add("second_true" if second_condition else "second_false")
+ assert set(state.source_prepared_mapping) == expected_sources
+ assert ("first_true" in trace) is first_condition
+ assert ("first_false" in trace) is not first_condition
+ assert ("second_true" in trace) is second_condition
+ assert ("second_false" in trace) is not second_condition
+ first_sink_id = next(iter(state.source_prepared_mapping["first_sink"]))
+ second_sink_id = next(iter(state.source_prepared_mapping["second_sink"]))
+ assert state.results[first_sink_id].value == (103 if first_condition else 111)
+ assert state.results[second_sink_id].value == (204 if second_condition else 221)
+
+ selected_first = "first_true" if first_condition else "first_false"
+ selected_second = "second_true" if second_condition else "second_false"
+ dependencies_by_source = {
+ source_id: {
+ (dependency.owner_id, dependency.branch, dependency.frame)
+ for execution_id, source_id_value in state.prepared_source_mapping.items()
+ if source_id_value == source_id
+ for dependency in state._if_activation_dependencies_by_exec.get(execution_id, ())
+ }
+ for source_id in (selected_first, selected_second)
+ }
+ assert dependencies_by_source == {
+ selected_first: {("first_if", "true_input" if first_condition else "false_input", ())},
+ selected_second: {("second_if", "true_input" if second_condition else "false_input", ())},
+ }
+ assert state.is_complete()
+
+ 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])
+ ("first_condition", "second_condition"),
+ [(True, True), (True, False), (False, True), (False, False)],
+)
[email protected]("stop_after", range(1, 8))
+def test_fresh_sibling_ifs_checkpoint_resume_matches_fresh_execution(
+ force_compatibility_scheduler: bool,
+ first_condition: bool,
+ second_condition: bool,
+ stop_after: int,
+) -> None:
+ graph = _sibling_if_graph(first_condition=first_condition, second_condition=second_condition)
+ expected_trace, expected_state = _run_graph(
+ GraphExecutionState(graph=graph.model_copy(deep=True)),
+ force_compatibility_scheduler=force_compatibility_scheduler,
+ )
+ 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,
+ )
+
+ assert checkpoint_trace + resumed_trace == expected_trace
+ assert _state_projection(resumed_state) == _state_projection(expected_state)
+ assert _activation_projection(resumed_state) == _activation_projection(expected_state)
+ assert resumed_state.is_complete()
+
+
+ ("first_condition", "second_condition"),
+ [(True, True), (True, False), (False, True), (False, False)],
+)
+def test_fresh_sibling_ifs_shared_ancestor_executes_once(
+ first_condition: bool,
+ second_condition: bool,
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ def fail_branch_analysis(*_: object, **__: object) -> set[str]:
+ raise AssertionError("fresh sibling If used controller-owned branch analysis")
+
+ monkeypatch.setattr(graph_module._IfActivationController, "_branch_sources", fail_branch_analysis)
+ trace, state = _run_graph(
+ GraphExecutionState(
+ graph=_sibling_if_graph(
+ first_condition=first_condition,
+ second_condition=second_condition,
+ with_shared_ancestor=True,
+ )
+ )
+ )
+
+ assert trace.count("shared") == 1
+ assert state.is_complete()
+
+
+def test_sibling_if_unsupported_saved_workflow_keeps_controller_fallback(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ graph = _sibling_if_graph()
+ graph.add_node(CallSavedWorkflowInvocation(id="call", workflow_id="saved-workflow"))
+ 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()
+ dependencies = state._get_source_activation_dependencies("first_true", (7,))
+ assert {dependency.owner_id for dependency in dependencies} == {"first_if"}
+ assert branch_analysis_calls
+
+
+def test_indirectly_connected_sibling_ifs_match_controller_fallback() -> None:
+ expected_trace, expected_state = _run_graph(
+ GraphExecutionState(graph=_indirectly_connected_sibling_if_graph()),
+ force_compatibility_scheduler=True,
+ )
+ state = GraphExecutionState(graph=_indirectly_connected_sibling_if_graph())
+ assert not state._can_use_fresh_flat_if_activation()
+ assert not state._can_use_generic_scheduler()
+ trace, state = _run_graph(state)
+
+ assert trace == expected_trace
+ assert _state_projection(state) == _state_projection(expected_state)
+ assert state.is_complete()
+
+
@pytest.mark.parametrize("force_compatibility_scheduler", [False, True])
@pytest.mark.parametrize(
("outer_condition", "inner_condition", "expected_trace"),
diff --git a/tests/app/services/shared/test_graph_if_dependencies.py b/tests/app/services/shared/test_graph_if_dependencies.py
index 9dd8cfddc4..35b816908b 100644
--- a/tests/app/services/shared/test_graph_if_dependencies.py
+++ b/tests/app/services/shared/test_graph_if_dependencies.py
@@ -58,6 +58,56 @@ def _nested_if_graph() -> Graph:
return graph
+def _sibling_if_graph(*, first_condition: bool = True, second_condition: bool = True) -> Graph:
+ graph = Graph()
+ graph.add_node(AddInvocation(id="shared", a=1, b=1))
+ graph.add_node(BooleanInvocation(id="first_condition", value=first_condition))
+ graph.add_node(BooleanInvocation(id="second_condition", value=second_condition))
+ graph.add_node(AddInvocation(id="first_true", b=3))
+ graph.add_node(AddInvocation(id="first_false", a=10, b=1))
+ graph.add_node(AddInvocation(id="second_true", b=4))
+ graph.add_node(AddInvocation(id="second_false", a=20, b=1))
+ graph.add_node(IfInvocation(id="first_if"))
+ graph.add_node(IfInvocation(id="second_if"))
+ graph.add_node(AddInvocation(id="first_sink", b=100))
+ graph.add_node(AddInvocation(id="second_sink", b=200))
+ graph.add_edge(_edge("shared", "value", "first_true", "a"))
+ graph.add_edge(_edge("shared", "value", "second_true", "a"))
+ graph.add_edge(_edge("first_condition", "value", "first_if", "condition"))
+ graph.add_edge(_edge("first_true", "value", "first_if", "true_input"))
+ graph.add_edge(_edge("first_false", "value", "first_if", "false_input"))
+ graph.add_edge(_edge("second_condition", "value", "second_if", "condition"))
+ graph.add_edge(_edge("second_true", "value", "second_if", "true_input"))
+ graph.add_edge(_edge("second_false", "value", "second_if", "false_input"))
+ graph.add_edge(_edge("first_if", "value", "first_sink", "a"))
+ graph.add_edge(_edge("second_if", "value", "second_sink", "a"))
+ return graph
+
+
+def _indirectly_connected_if_graph() -> Graph:
+ graph = Graph()
+ graph.add_node(BooleanInvocation(id="first_condition", value=True))
+ graph.add_node(BooleanInvocation(id="second_condition", value=True))
+ graph.add_node(AddInvocation(id="first_true", a=2, b=3))
+ graph.add_node(AddInvocation(id="first_false", a=10, b=1))
+ graph.add_node(IfInvocation(id="first_if"))
+ graph.add_node(AddInvocation(id="bridge", b=4))
+ graph.add_node(AddInvocation(id="second_false", a=20, b=1))
+ graph.add_node(IfInvocation(id="second_if"))
+ graph.add_node(AddInvocation(id="first_sink", b=100))
+ graph.add_node(AddInvocation(id="second_sink", b=200))
+ graph.add_edge(_edge("first_condition", "value", "first_if", "condition"))
+ graph.add_edge(_edge("first_true", "value", "first_if", "true_input"))
+ graph.add_edge(_edge("first_false", "value", "first_if", "false_input"))
+ graph.add_edge(_edge("first_if", "value", "bridge", "a"))
+ graph.add_edge(_edge("bridge", "value", "second_if", "true_input"))
+ graph.add_edge(_edge("second_condition", "value", "second_if", "condition"))
+ graph.add_edge(_edge("second_false", "value", "second_if", "false_input"))
+ graph.add_edge(_edge("first_if", "value", "first_sink", "a"))
+ graph.add_edge(_edge("second_if", "value", "second_sink", "a"))
+ return graph
+
+
def test_leaf_import_does_not_import_graph() -> None:
script = """
import builtins
@@ -197,3 +247,48 @@ def test_branch_dependency_cache_is_frame_local_and_graph_edits_invalidate() ->
state.add_node(AddInvocation(id="true_consumer", b=1))
state.add_edge(_edge("true_branch", "value", "true_consumer", "a"))
assert state._get_source_activation_dependencies("true_branch") == ()
+
+
+def test_sibling_if_dependencies_are_owner_local_and_frame_local() -> None:
+ state = GraphExecutionState(graph=_sibling_if_graph(first_condition=True, second_condition=False))
+
+ assert state._can_use_fresh_flat_if_activation()
+ assert state._get_source_activation_dependencies("first_true", (1,)) == (
+ ActivationDependency(owner_id="first_if", branch="true_input", frame=(1,)),
+ )
+ assert state._get_source_activation_dependencies("first_false", (2,)) == (
+ ActivationDependency(owner_id="first_if", branch="false_input", frame=(2,)),
+ )
+ assert state._get_source_activation_dependencies("second_true", (3,)) == (
+ ActivationDependency(owner_id="second_if", branch="true_input", frame=(3,)),
+ )
+ assert state._get_source_activation_dependencies("second_false", (4,)) == (
+ ActivationDependency(owner_id="second_if", branch="false_input", frame=(4,)),
+ )
+ assert state._get_source_activation_dependencies("shared") == ()
+ assert state._get_source_activation_dependencies("first_true", (5,)) != state._get_source_activation_dependencies(
+ "first_true", (6,)
+ )
+
+
+def test_indirectly_connected_ifs_retain_controller_fallback(monkeypatch: pytest.MonkeyPatch) -> None:
+ state = GraphExecutionState(graph=_indirectly_connected_if_graph())
+ 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]:
+ 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("first_true", (7,)) == (
+ ActivationDependency(owner_id="first_if", branch="true_input", frame=(7,)),
+ )
+ assert ("first_if", "true_input") in calls