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): preserve internal runtime state boundary

JPPhotof3932a036951
diff --git a/invokeai/app/services/session_queue/session_queue_common.py b/invokeai/app/services/session_queue/session_queue_common.py
index e6748219b0..383a94a5aa 100644
--- a/invokeai/app/services/session_queue/session_queue_common.py
+++ b/invokeai/app/services/session_queue/session_queue_common.py
@@ -18,7 +18,7 @@ from pydantic_core import to_jsonable_python
from invokeai.app.invocations.fields import ImageField, VideoField
from invokeai.app.services.shared.execution_state_migration import (
- CURRENT_EXECUTION_STATE_VERSION,
+ dump_execution_state,
load_execution_state,
)
from invokeai.app.services.shared.graph import Graph, GraphExecutionState, NodeNotFoundError
@@ -618,8 +618,7 @@ def create_session_nfv_tuples(batch: Batch, maximum: int) -> Generator[tuple[str
# We must provide a Graph object when creating the "dummy" session dict, but we don't actually use it. It will be
# overwritten for each session by the mutated graph_as_dict.
- session_dict = GraphExecutionState(graph=Graph()).model_dump(warnings=False, exclude_none=True)
- session_dict["execution_state_version"] = CURRENT_EXECUTION_STATE_VERSION
+ session_dict = dump_execution_state(GraphExecutionState(graph=Graph()))
# Now we can create a generator that yields the session_id, session_json, and field_values_json for each session.
count = 0
diff --git a/invokeai/app/services/shared/graph.py b/invokeai/app/services/shared/graph.py
index 31b55085a1..f064745e5d 100644
--- a/invokeai/app/services/shared/graph.py
+++ b/invokeai/app/services/shared/graph.py
@@ -291,14 +291,17 @@ class GraphExecutionState(BaseModel):
execution_refs: dict[str, ExecutionReference] = Field(
default_factory=dict,
description="Stable frame-aware references for prepared execution nodes",
+ exclude=True,
)
execution_tokens: dict[str, ExecutionToken] = Field(
default_factory=dict,
description="Data tokens produced by prepared execution output ports",
+ exclude=True,
)
execution_effects: dict[str, list[Any]] = Field(
default_factory=dict,
description="Effects accepted for each execution reference",
+ exclude=True,
)
execution_child_dependencies: dict[str, ChildDependencyRecord] = Field(
default_factory=dict,
@@ -3341,6 +3344,7 @@ class GraphExecutionState(BaseModel):
if effects
and self._is_pending_lifecycle_effects(effects)
and (reference := references_by_id.get(reference_id)) is not None
+ and reference.exec_node_id not in self.errors
}
self._rehydrate_runtime_state()
@@ -3432,10 +3436,13 @@ class GraphExecutionState(BaseModel):
def set_node_error(self, node_id: str, error: str):
"""Marks a node as errored"""
self.errors[node_id] = error
+ self._pending_lifecycle_execution_nodes.discard(node_id)
self._clear_transient_runtime()
def is_complete(self) -> bool:
"""Returns true if the graph is complete"""
+ if self.has_error():
+ return self._is_complete_with_completed_sources()
if self.is_waiting_on_workflow_call() or self._has_pending_lifecycle_execution():
return False
return self._is_complete_with_completed_sources()
diff --git a/invokeai/frontend/web/openapi.json b/invokeai/frontend/web/openapi.json
index 0a11bc2927..a182e7c603 100644
--- a/invokeai/frontend/web/openapi.json
+++ b/invokeai/frontend/web/openapi.json
@@ -21486,302 +21486,6 @@
"$ref": "#/components/schemas/ImageOutput"
}
},
- "ChildCompletion": {
- "properties": {
- "child_execution_id": {
- "type": "string",
- "minLength": 1,
- "title": "Child Execution Id"
- },
- "parent_execution_id": {
- "type": "string",
- "minLength": 1,
- "title": "Parent Execution Id"
- },
- "parent_frame": {
- "items": {
- "anyOf": [
- {
- "type": "integer"
- },
- {
- "type": "string"
- }
- ]
- },
- "type": "array",
- "title": "Parent Frame"
- },
- "parent_reference_id": {
- "anyOf": [
- {
- "type": "string",
- "minLength": 1
- },
- {
- "type": "null"
- }
- ],
- "title": "Parent Reference Id"
- },
- "child_frame": {
- "items": {
- "anyOf": [
- {
- "type": "integer"
- },
- {
- "type": "string"
- }
- ]
- },
- "type": "array",
- "title": "Child Frame"
- },
- "status": {
- "type": "string",
- "enum": ["completed", "failed", "canceled"],
- "title": "Status"
- },
- "outputs": {
- "additionalProperties": true,
- "type": "object",
- "title": "Outputs"
- },
- "error_message": {
- "anyOf": [
- {
- "type": "string"
- },
- {
- "type": "null"
- }
- ],
- "title": "Error Message"
- }
- },
- "additionalProperties": false,
- "type": "object",
- "required": ["child_execution_id", "parent_execution_id", "status"],
- "title": "ChildCompletion",
- "description": "One terminal child result, including its ownership proof."
- },
- "ChildDependencyRecord": {
- "properties": {
- "dependency_id": {
- "type": "string",
- "minLength": 1,
- "title": "Dependency Id"
- },
- "parent_execution_id": {
- "type": "string",
- "minLength": 1,
- "title": "Parent Execution Id"
- },
- "parent_frame": {
- "items": {
- "anyOf": [
- {
- "type": "integer"
- },
- {
- "type": "string"
- }
- ]
- },
- "type": "array",
- "title": "Parent Frame"
- },
- "parent_reference_id": {
- "anyOf": [
- {
- "type": "string",
- "minLength": 1
- },
- {
- "type": "null"
- }
- ],
- "title": "Parent Reference Id"
- },
- "children": {
- "items": {
- "$ref": "#/components/schemas/ChildExecutionRecord"
- },
- "type": "array",
- "title": "Children"
- },
- "completions": {
- "additionalProperties": {
- "$ref": "#/components/schemas/ChildCompletion"
- },
- "type": "object",
- "title": "Completions"
- },
- "status": {
- "type": "string",
- "enum": ["waiting", "running", "completed", "failed", "canceled"],
- "title": "Status",
- "default": "waiting"
- },
- "failure_policy": {
- "type": "string",
- "enum": ["fail_parent", "cancel_siblings", "continue"],
- "title": "Failure Policy",
- "default": "fail_parent"
- },
- "cancellation_policy": {
- "type": "string",
- "enum": ["cancel_parent", "cancel_siblings", "continue"],
- "title": "Cancellation Policy",
- "default": "cancel_parent"
- },
- "error_message": {
- "anyOf": [
- {
- "type": "string"
- },
- {
- "type": "null"
- }
- ],
- "title": "Error Message"
- },
- "output_keys": {
- "anyOf": [
- {
- "items": {
- "type": "string"
- },
- "type": "array"
- },
- {
- "type": "null"
- }
- ],
- "title": "Output Keys"
- },
- "terminal_transition_count": {
- "type": "integer",
- "minimum": 0.0,
- "title": "Terminal Transition Count",
- "default": 0
- },
- "sealed": {
- "type": "boolean",
- "title": "Sealed",
- "default": true
- }
- },
- "additionalProperties": false,
- "type": "object",
- "required": ["dependency_id", "parent_execution_id"],
- "title": "ChildDependencyRecord",
- "description": "All-of parent dependency with durable enqueue and terminal state."
- },
- "ChildExecutionRecord": {
- "properties": {
- "child_execution_id": {
- "type": "string",
- "minLength": 1,
- "title": "Child Execution Id"
- },
- "parent_execution_id": {
- "type": "string",
- "minLength": 1,
- "title": "Parent Execution Id"
- },
- "parent_frame": {
- "items": {
- "anyOf": [
- {
- "type": "integer"
- },
- {
- "type": "string"
- }
- ]
- },
- "type": "array",
- "title": "Parent Frame"
- },
- "parent_reference_id": {
- "anyOf": [
- {
- "type": "string",
- "minLength": 1
- },
- {
- "type": "null"
- }
- ],
- "title": "Parent Reference Id"
- },
- "child_frame": {
- "items": {
- "anyOf": [
- {
- "type": "integer"
- },
- {
- "type": "string"
- }
- ]
- },
- "type": "array",
- "title": "Child Frame"
- },
- "depth": {
- "type": "integer",
- "minimum": 0.0,
- "title": "Depth",
- "default": 0
- },
- "enqueue_index": {
- "type": "integer",
- "minimum": 0.0,
- "title": "Enqueue Index",
- "default": 0
- },
- "capability_id": {
- "anyOf": [
- {
- "type": "string",
- "minLength": 1
- },
- {
- "type": "null"
- }
- ],
- "title": "Capability Id"
- },
- "graph": {
- "anyOf": [
- {},
- {
- "type": "null"
- }
- ],
- "title": "Graph"
- },
- "inputs": {
- "additionalProperties": true,
- "type": "object",
- "title": "Inputs"
- },
- "state": {
- "type": "string",
- "enum": ["pending", "queued", "running", "completed", "failed", "canceled"],
- "title": "State",
- "default": "pending"
- }
- },
- "additionalProperties": false,
- "type": "object",
- "required": ["child_execution_id", "parent_execution_id"],
- "title": "ChildExecutionRecord",
- "description": "Durable identity and payload for one child execution."
- },
"Classification": {
"description": "The classification of an Invocation.\n- `Stable`: The invocation, including its inputs/outputs and internal logic, is stable. You may build workflows with it, having confidence that they will not break because of a change in this invocation.\n- `Beta`: The invocation is not yet stable, but is planned to be stable in the future. Workflows built around this invocation may break, but we are committed to supporting this invocation long-term.\n- `Prototype`: The invocation is not yet stable and may be removed from the application at any time. Workflows built around this invocation may break, and we are *not* committed to supporting this invocation.\n- `Deprecated`: The invocation is deprecated and may be removed in a future version.\n- `Internal`: The invocation is not intended for use by end-users. It may be changed or removed at any time, but is exposed for users to play with.\n- `Special`: The invocation is a special case and does not fit into any of the other classifications.",
"enum": ["stable", "beta", "prototype", "deprecated", "internal", "special"],
@@ -30125,145 +29829,6 @@
"$ref": "#/components/schemas/ImageOutput"
}
},
- "ExecutionFrame": {
- "properties": {
- "frame_id": {
- "type": "string",
- "title": "Frame Id",
- "description": "Stable frame identifier",
- "default": ""
- },
- "state_id": {
- "type": "string",
- "title": "State Id",
- "description": "Owning graph execution state id",
- "default": ""
- },
- "iteration_path": {
- "items": {
- "type": "integer"
- },
- "type": "array",
- "title": "Iteration Path",
- "description": "Loop iteration coordinates"
- },
- "workflow_call_depth": {
- "type": "integer",
- "minimum": 0.0,
- "title": "Workflow Call Depth",
- "description": "Nested workflow-call depth",
- "default": 0
- }
- },
- "additionalProperties": true,
- "type": "object",
- "title": "ExecutionFrame",
- "description": "Stable execution location for a prepared node."
- },
- "ExecutionReference": {
- "properties": {
- "reference_id": {
- "type": "string",
- "title": "Reference Id",
- "description": "Stable reference identifier",
- "default": ""
- },
- "state_id": {
- "type": "string",
- "title": "State Id",
- "description": "Owning graph execution state id",
- "default": ""
- },
- "exec_node_id": {
- "type": "string",
- "title": "Exec Node Id",
- "description": "Prepared execution node id",
- "default": ""
- },
- "source_node_id": {
- "type": "string",
- "title": "Source Node Id",
- "description": "Authoring graph node id",
- "default": ""
- },
- "frame": {
- "$ref": "#/components/schemas/ExecutionFrame",
- "description": "Execution frame"
- },
- "effect_count": {
- "anyOf": [
- {
- "type": "integer",
- "minimum": 0.0
- },
- {
- "type": "null"
- }
- ],
- "title": "Effect Count",
- "description": "Expected effect count, if declared"
- }
- },
- "additionalProperties": true,
- "type": "object",
- "title": "ExecutionReference",
- "description": "Stable, frame-aware reference to one prepared execution node.\n\nThis intentionally stays independent from invocation-context/effect models. The execution engine can reconcile\nthis small compatibility type with a richer protocol later without changing persisted graph state."
- },
- "ExecutionToken": {
- "properties": {
- "token_id": {
- "type": "string",
- "title": "Token Id",
- "description": "Stable token identifier"
- },
- "reference_id": {
- "type": "string",
- "title": "Reference Id",
- "description": "Owning execution reference id"
- },
- "owner_node_id": {
- "type": "string",
- "title": "Owner Node Id",
- "description": "Prepared node that produced the token"
- },
- "port": {
- "type": "string",
- "title": "Port",
- "description": "Output port name"
- },
- "frame": {
- "$ref": "#/components/schemas/ExecutionFrame",
- "description": "Frame that produced the token"
- },
- "value": {
- "title": "Value",
- "description": "Output port value"
- },
- "token_kind": {
- "type": "string",
- "enum": ["data", "activation", "stream_end"],
- "title": "Token Kind",
- "default": "data"
- },
- "sequence": {
- "anyOf": [
- {
- "type": "integer",
- "minimum": 0.0
- },
- {
- "type": "null"
- }
- ],
- "title": "Sequence"
- }
- },
- "additionalProperties": true,
- "type": "object",
- "required": ["token_id", "reference_id", "owner_node_id", "port", "frame", "value"],
- "title": "ExecutionToken",
- "description": "Data token owned by one prepared output port.\n\nTokens contain no graph edge or association metadata. In particular, loop-linkage edges never become data\ntokens."
- },
"ExpandMaskWithFadeInvocation": {
"category": "mask",
"class": "invocation",
diff --git a/invokeai/frontend/web/src/services/api/schema.ts b/invokeai/frontend/web/src/services/api/schema.ts
index 0ad9807992..862ea6ef8d 100644
--- a/invokeai/frontend/web/src/services/api/schema.ts
+++ b/invokeai/frontend/web/src/services/api/schema.ts
@@ -7269,125 +7269,6 @@ export type components = {
*/
type: "img_pad_crop";
};
- /**
- * ChildCompletion
- * @description One terminal child result, including its ownership proof.
- */
- ChildCompletion: {
- /** Child Execution Id */
- child_execution_id: string;
- /** Parent Execution Id */
- parent_execution_id: string;
- /** Parent Frame */
- parent_frame?: (number | string)[];
- /** Parent Reference Id */
- parent_reference_id?: string | null;
- /** Child Frame */
- child_frame?: (number | string)[];
- /**
- * Status
- * @enum {string}
- */
- status: "completed" | "failed" | "canceled";
- /** Outputs */
- outputs?: {
- [key: string]: unknown;
- };
- /** Error Message */
- error_message?: string | null;
- };
- /**
- * ChildDependencyRecord
- * @description All-of parent dependency with durable enqueue and terminal state.
- */
- ChildDependencyRecord: {
- /** Dependency Id */
- dependency_id: string;
- /** Parent Execution Id */
- parent_execution_id: string;
- /** Parent Frame */
- parent_frame?: (number | string)[];
- /** Parent Reference Id */
- parent_reference_id?: string | null;
- /** Children */
- children?: components["schemas"]["ChildExecutionRecord"][];
- /** Completions */
- completions?: {
- [key: string]: components["schemas"]["ChildCompletion"];
- };
- /**
- * Status
- * @default waiting
- * @enum {string}
- */
- status?: "waiting" | "running" | "completed" | "failed" | "canceled";
- /**
- * Failure Policy
- * @default fail_parent
- * @enum {string}
- */
- failure_policy?: "fail_parent" | "cancel_siblings" | "continue";
- /**
- * Cancellation Policy
- * @default cancel_parent
- * @enum {string}
- */
- cancellation_policy?: "cancel_parent" | "cancel_siblings" | "continue";
- /** Error Message */
- error_message?: string | null;
- /** Output Keys */
- output_keys?: string[] | null;
- /**
- * Terminal Transition Count
- * @default 0
- */
- terminal_transition_count?: number;
- /**
- * Sealed
- * @default true
- */
- sealed?: boolean;
- };
- /**
- * ChildExecutionRecord
- * @description Durable identity and payload for one child execution.
- */
- ChildExecutionRecord: {
- /** Child Execution Id */
- child_execution_id: string;
- /** Parent Execution Id */
- parent_execution_id: string;
- /** Parent Frame */
- parent_frame?: (number | string)[];
- /** Parent Reference Id */
- parent_reference_id?: string | null;
- /** Child Frame */
- child_frame?: (number | string)[];
- /**
- * Depth
- * @default 0
- */
- depth?: number;
- /**
- * Enqueue Index
- * @default 0
- */
- enqueue_index?: number;
- /** Capability Id */
- capability_id?: string | null;
- /** Graph */
- graph?: unknown | null;
- /** Inputs */
- inputs?: {
- [key: string]: unknown;
- };
- /**
- * State
- * @default pending
- * @enum {string}
- */
- state?: "pending" | "queued" | "running" | "completed" | "failed" | "canceled";
- };
/**
* Classification
* @description The classification of an Invocation.
@@ -11609,125 +11490,6 @@ export type components = {
*/
type: "ernie_image_vae_decode";
};
- /**
- * ExecutionFrame
- * @description Stable execution location for a prepared node.
- */
- ExecutionFrame: {
- /**
- * Frame Id
- * @description Stable frame identifier
- * @default
- */
- frame_id?: string;
- /**
- * State Id
- * @description Owning graph execution state id
- * @default
- */
- state_id?: string;
- /**
- * Iteration Path
- * @description Loop iteration coordinates
- */
- iteration_path?: number[];
- /**
- * Workflow Call Depth
- * @description Nested workflow-call depth
- * @default 0
- */
- workflow_call_depth?: number;
- } & {
- [key: string]: unknown;
- };
- /**
- * ExecutionReference
- * @description Stable, frame-aware reference to one prepared execution node.
- *
- * This intentionally stays independent from invocation-context/effect models. The execution engine can reconcile
- * this small compatibility type with a richer protocol later without changing persisted graph state.
- */
- ExecutionReference: {
- /**
- * Reference Id
- * @description Stable reference identifier
- * @default
- */
- reference_id?: string;
- /**
- * State Id
- * @description Owning graph execution state id
- * @default
- */
- state_id?: string;
- /**
- * Exec Node Id
- * @description Prepared execution node id
- * @default
- */
- exec_node_id?: string;
- /**
- * Source Node Id
- * @description Authoring graph node id
- * @default
- */
- source_node_id?: string;
- /** @description Execution frame */
- frame?: components["schemas"]["ExecutionFrame"];
- /**
- * Effect Count
- * @description Expected effect count, if declared
- */
- effect_count?: number | null;
- } & {
- [key: string]: unknown;
- };
- /**
- * ExecutionToken
- * @description Data token owned by one prepared output port.
- *
- * Tokens contain no graph edge or association metadata. In particular, loop-linkage edges never become data
- * tokens.
- */
- ExecutionToken: {
- /**
- * Token Id
- * @description Stable token identifier
- */
- token_id: string;
- /**
- * Reference Id
- * @description Owning execution reference id
- */
- reference_id: string;
- /**
- * Owner Node Id
- * @description Prepared node that produced the token
- */
- owner_node_id: string;
- /**
- * Port
- * @description Output port name
- */
- port: string;
- /** @description Frame that produced the token */
- frame: components["schemas"]["ExecutionFrame"];
- /**
- * Value
- * @description Output port value
- */
- value: unknown;
- /**
- * Token Kind
- * @default data
- * @enum {string}
- */
- token_kind?: "data" | "activation" | "stream_end";
- /** Sequence */
- sequence?: number | null;
- } & {
- [key: string]: unknown;
- };
/**
* Expand Mask with Fade
* @description Expands a mask with a fade effect. The mask uses black to indicate areas to keep from the generated image and white for areas to discard.
diff --git a/tests/app/services/shared/test_execution_effects.py b/tests/app/services/shared/test_execution_effects.py
index 0d669b5564..44191b61ea 100644
--- a/tests/app/services/shared/test_execution_effects.py
+++ b/tests/app/services/shared/test_execution_effects.py
@@ -1275,6 +1275,34 @@ def test_saved_workflow_lifecycle_effects_survive_json_round_trip() -> None:
assert dump_execution_state(restored)["execution_effects"] == snapshot["execution_effects"]
+def test_failed_pending_workflow_call_is_terminal_after_json_round_trip() -> None:
+ graph = Graph()
+ graph.add_node(CallSavedWorkflowInvocation(id="saved-workflow", workflow_id="workflow"))
+ state = GraphExecutionState(graph=graph)
+ node = state.next()
+ assert node is not None
+ parent = ExecutionRef(execution_node_id=node.id)
+ effects = [
+ SpawnExecutionEffect(
+ execution_ref=parent,
+ parent=parent,
+ graph={"nodes": {}},
+ inputs={},
+ child_execution_id="child",
+ ),
+ AwaitEffect(execution_ref=parent, dependency=ExecutionRef(execution_node_id="child")),
+ ]
+ ref = state.get_execution_ref(node.id, effect_count=len(effects))
+ state.execution_refs[node.id] = ref
+ state.execution_effects[ref.reference_id] = effects
+ state.errors[node.id] = "child failed"
+
+ restored = load_execution_state(dump_execution_state(state))
+
+ assert restored.is_complete()
+ assert restored.next() is None
+
+
def test_set_value_effect_requires_a_value() -> None:
with pytest.raises(ValidationError):
SetValueEffect(target=ExecutionRef(node_id="node", field="value"))
diff --git a/tests/app/services/shared/test_execution_state_migration.py b/tests/app/services/shared/test_execution_state_migration.py
index 22c88ad75d..8aded3980b 100644
--- a/tests/app/services/shared/test_execution_state_migration.py
+++ b/tests/app/services/shared/test_execution_state_migration.py
@@ -80,6 +80,27 @@ def test_migrates_explicit_legacy_version() -> None:
assert restored.model_dump(mode="json", warnings=False, exclude_none=True) == raw
+def test_loads_frozen_legacy_snapshot_without_runtime_ledgers() -> None:
+ legacy_payload = {
+ "id": "legacy-state",
+ "graph": {"id": "legacy-graph", "nodes": {}, "edges": []},
+ "execution_graph": {"id": "legacy-execution-graph", "nodes": {}, "edges": []},
+ "executed": [],
+ "executed_history": [],
+ "results": {},
+ "errors": {},
+ "workflow_call_stack": [],
+ "workflow_call_history": [],
+ "prepared_source_mapping": {},
+ "source_prepared_mapping": {},
+ }
+
+ restored = load_execution_state(legacy_payload)
+
+ assert restored.id == "legacy-state"
+ assert dump_execution_state(restored)["execution_state_version"] == CURRENT_EXECUTION_STATE_VERSION
+
+
def test_rejects_future_execution_state_versions() -> None:
snapshot = dump_execution_state(_make_state())
snapshot["execution_state_version"] = CURRENT_EXECUTION_STATE_VERSION + 1
@@ -172,7 +193,13 @@ def test_internal_execution_fields_are_persisted_but_not_publicly_serialized() -
assert "execution_effects" not in public_payload["properties"]
assert "execution_child_dependencies" not in public_payload["properties"]
- assert "execution_child_dependencies" not in state.model_dump(mode="json", warnings=False)
+ public_model_dump = state.model_dump(mode="json", warnings=False)
+ assert {
+ "execution_refs",
+ "execution_tokens",
+ "execution_effects",
+ "execution_child_dependencies",
+ }.isdisjoint(public_model_dump)
persisted_payload = dump_execution_state(state)
assert persisted_payload["execution_refs"]["exec-node"]["reference_id"] == execution_ref.reference_id