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): normalize nested token snapshots

JPPhoto9dfa04e1c42e
diff --git a/invokeai/app/services/shared/execution_state_migration.py b/invokeai/app/services/shared/execution_state_migration.py
index 9959d984b3..4b54688903 100644
--- a/invokeai/app/services/shared/execution_state_migration.py
+++ b/invokeai/app/services/shared/execution_state_migration.py
@@ -9,6 +9,16 @@ CURRENT_EXECUTION_STATE_VERSION: Final[int] = 1
LEGACY_EXECUTION_STATE_VERSION: Final[int] = 0
+def _retain_nullable_execution_token_values(snapshot: dict[str, Any]) -> None:
+ """Retain omitted null token values in this state and any embedded child state."""
+ for token in snapshot.get("execution_tokens", {}).values():
+ token.setdefault("value", None)
+
+ child_snapshot = snapshot.get("waiting_workflow_call_child_session")
+ if isinstance(child_snapshot, dict):
+ _retain_nullable_execution_token_values(child_snapshot)
+
+
class UnsupportedExecutionStateVersionError(ValueError):
"""Raised when an execution-state snapshot cannot be read by this runtime."""
@@ -25,8 +35,7 @@ def dump_execution_state(state: GraphExecutionState) -> dict[str, Any]:
# Persist nullable output tokens explicitly. `ExecutionToken.value` remains required in the
# public model/schema, but an output port may legitimately carry None and the general
# exclude_none policy would otherwise make the snapshot impossible to hydrate.
- for token in snapshot.get("execution_tokens", {}).values():
- token.setdefault("value", None)
+ _retain_nullable_execution_token_values(snapshot)
snapshot["execution_state_version"] = CURRENT_EXECUTION_STATE_VERSION
return snapshot
diff --git a/tests/app/services/shared/test_execution_state_migration.py b/tests/app/services/shared/test_execution_state_migration.py
index e99c8b568b..1827d12e0e 100644
--- a/tests/app/services/shared/test_execution_state_migration.py
+++ b/tests/app/services/shared/test_execution_state_migration.py
@@ -81,7 +81,7 @@ def test_rejects_future_execution_state_versions() -> None:
def test_round_trips_nullable_execution_token_value() -> None:
state = _make_state()
- state.execution_tokens["token-id"] = ExecutionToken(
+ token = ExecutionToken(
token_id="token-id",
reference_id="state-id:exec-node",
owner_node_id="exec-node",
@@ -89,9 +89,32 @@ def test_round_trips_nullable_execution_token_value() -> None:
frame=ExecutionFrame(),
value=None,
)
+ state.execution_tokens["token-id"] = token
snapshot = dump_execution_state(state)
assert snapshot["execution_tokens"]["token-id"]["value"] is None
restored = load_execution_state(snapshot)
assert restored.execution_tokens["token-id"].value is None
+
+
+def test_round_trips_nullable_execution_token_value_in_child_state() -> None:
+ state = _make_state()
+ child = _make_state()
+ child.execution_tokens["token-id"] = ExecutionToken(
+ token_id="token-id",
+ reference_id="state-id:exec-node",
+ owner_node_id="exec-node",
+ port="value",
+ frame=ExecutionFrame(),
+ value=None,
+ )
+ state.waiting_workflow_call_child_session = child
+
+ snapshot = dump_execution_state(state)
+ child_snapshot = snapshot["waiting_workflow_call_child_session"]
+ assert child_snapshot["execution_tokens"]["token-id"]["value"] is None
+ restored = load_execution_state(snapshot)
+
+ assert restored.waiting_workflow_call_child_session is not None
+ assert restored.waiting_workflow_call_child_session.execution_tokens["token-id"].value is None