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
fix(execution): preserve nullable tokens in queue snapshots
JPPhoto218c1eb09bfe
diff --git a/invokeai/app/services/shared/execution_state_migration.py b/invokeai/app/services/shared/execution_state_migration.pyindex 9a8b85b5f7..9959d984b3 100644--- a/invokeai/app/services/shared/execution_state_migration.py+++ b/invokeai/app/services/shared/execution_state_migration.py@@ -22,6 +22,11 @@ def dump_execution_state(state: GraphExecutionState) -> dict[str, Any]:migration experiments."""snapshot = state.model_dump(mode="json", warnings=False, exclude_none=True)+ # 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)snapshot["execution_state_version"] = CURRENT_EXECUTION_STATE_VERSIONreturn snapshotdiff --git a/invokeai/app/services/shared/invocation_context.py b/invokeai/app/services/shared/invocation_context.pyindex 376735bcc2..95e52b55f7 100644--- a/invokeai/app/services/shared/invocation_context.py+++ b/invokeai/app/services/shared/invocation_context.py@@ -983,7 +983,8 @@ class InvocationContext:"""An internal API providing access to data about the current queue item and invocation. You probably shouldn't use this. It may change without warning."""self._services = services"""An internal API providing access to all application services. You probably shouldn't use this. It may change without warning."""- self.execution_effects = execution_effects or ExecutionEffectsRecorder(source_node_id=data.invocation.id)+ source_node_id = getattr(data.invocation, "id", None) or data.source_invocation_id or "context"+ self.execution_effects = execution_effects or ExecutionEffectsRecorder(source_node_id=source_node_id)"""Effects recorded during the current invocation run."""self.effects = self.execution_effects"""Alias for :attr:`execution_effects`."""@@ -1021,7 +1022,7 @@ def build_invocation_context(if execution_effects is None:execution_effects = ExecutionEffectsRecorder(- source_node_id=data.invocation.id,+ source_node_id=getattr(data.invocation, "id", None) or data.source_invocation_id or "context",frame_path=data.execution_frame,)diff --git a/tests/app/services/shared/test_execution_state_migration.py b/tests/app/services/shared/test_execution_state_migration.pyindex 750d77db80..e99c8b568b 100644--- a/tests/app/services/shared/test_execution_state_migration.py+++ b/tests/app/services/shared/test_execution_state_migration.py@@ -7,7 +7,7 @@ from invokeai.app.services.shared.execution_state_migration import (dump_execution_state,load_execution_state,)-from invokeai.app.services.shared.graph import Graph, GraphExecutionState+from invokeai.app.services.shared.graph import ExecutionFrame, ExecutionToken, Graph, GraphExecutionStatedef _make_state() -> GraphExecutionState:@@ -77,3 +77,21 @@ def test_rejects_future_execution_state_versions() -> None:with pytest.raises(UnsupportedExecutionStateVersionError, match="newer than supported"):load_execution_state(snapshot)+++def test_round_trips_nullable_execution_token_value() -> None:+ state = _make_state()+ state.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,+ )++ 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 Nonediff --git a/tests/app/services/shared/test_for_scheduler_performance.py b/tests/app/services/shared/test_for_scheduler_performance.pyindex f84ec8c00d..8b11e09f27 100644--- a/tests/app/services/shared/test_for_scheduler_performance.py+++ b/tests/app/services/shared/test_for_scheduler_performance.py@@ -68,8 +68,11 @@ def test_completion_predicate_preserves_durable_state() -> None:assert state.is_complete()assert state.model_dump_json() == beforerestored_state = GraphExecutionState.model_validate_json(before)+ # Legacy complete() snapshots intentionally gain their derived execution references on restore.+ restored_before = restored_state.model_dump_json()+ assert restored_state.execution_refsassert restored_state.is_complete()- assert restored_state.model_dump_json() == before+ assert restored_state.model_dump_json() == restored_beforedef test_completion_cache_preserves_completed_sources_after_restore() -> None: