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(workflows): drop unused child policies and read legacy child rows (#10242)

Jonathan82c970df0685
diff --git a/invokeai/app/services/session_queue/session_queue_common.py b/invokeai/app/services/session_queue/session_queue_common.py
index 458f043af4..868bc4e444 100644
--- a/invokeai/app/services/session_queue/session_queue_common.py
+++ b/invokeai/app/services/session_queue/session_queue_common.py
@@ -24,6 +24,7 @@ from invokeai.app.services.shared.execution_state_migration import (
UnsupportedExecutionStateVersionError,
dump_execution_state,
load_execution_state,
+ strip_legacy_child_policy_keys,
)
from invokeai.app.services.shared.graph import Graph, GraphExecutionState, NodeNotFoundError
from invokeai.app.services.workflow_records.workflow_records_common import (
@@ -249,7 +250,13 @@ def get_session(queue_item_dict: dict) -> GraphExecutionState:
return load_execution_state(session_payload)
-def _normalize_queue_read_effects(payload: dict[str, Any], *, normalize_effects: bool) -> None:
+def _normalize_queue_read_ledgers(payload: dict[str, Any], *, normalize_effects: bool) -> None:
+ """Normalize one persisted payload for a response-shaped read, without rehydrating runtime state.
+
+ The legacy child policy keys are dropped here too: this projection validates the same `extra="forbid"`
+ child records as full rehydration, so a row written before their removal is otherwise unreadable.
+ """
+ strip_legacy_child_policy_keys(payload)
if normalize_effects and "execution_effects" in payload:
payload["execution_effects"] = normalize_persisted_execution_effects(payload["execution_effects"])
@@ -261,10 +268,10 @@ def _normalize_queue_read_effects(payload: dict[str, Any], *, normalize_effects:
child_state = child_payload.get("state")
if isinstance(child_payload.get("version"), int) and isinstance(child_state, Mapping):
child_state = dict(child_state)
- _normalize_queue_read_effects(child_state, normalize_effects=normalize_effects)
+ _normalize_queue_read_ledgers(child_state, normalize_effects=normalize_effects)
child_payload["state"] = child_state
else:
- _normalize_queue_read_effects(child_payload, normalize_effects=normalize_effects)
+ _normalize_queue_read_ledgers(child_payload, normalize_effects=normalize_effects)
payload["waiting_workflow_call_child_session"] = child_payload
@@ -294,7 +301,7 @@ def get_session_for_queue_read(queue_item_dict: dict) -> GraphExecutionState:
execution_graph_payload = session_payload.get("execution_graph")
if isinstance(execution_graph_payload, Mapping):
session_payload["execution_graph"] = Graph.model_validate(execution_graph_payload, strict=False)
- _normalize_queue_read_effects(session_payload, normalize_effects=version != 0)
+ _normalize_queue_read_ledgers(session_payload, normalize_effects=version != 0)
return GraphExecutionState.model_validate(session_payload, context={"queue_read_projection": True})
diff --git a/invokeai/app/services/shared/execution_engine/child.py b/invokeai/app/services/shared/execution_engine/child.py
index d2e0429268..c36cd1e2b8 100644
--- a/invokeai/app/services/shared/execution_engine/child.py
+++ b/invokeai/app/services/shared/execution_engine/child.py
@@ -15,8 +15,6 @@ from pydantic_core import PydanticSerializationError
ChildTerminalStatus = Literal["completed", "failed", "canceled"]
ChildState = Literal["pending", "queued", "running", "completed", "failed", "canceled"]
ChildDependencyStatus = Literal["waiting", "running", "completed", "failed", "canceled"]
-ChildFailurePolicy = Literal["fail_parent", "cancel_siblings", "continue"]
-ChildCancellationPolicy = Literal["cancel_parent", "cancel_siblings", "continue"]
_JSON_SERIALIZER = TypeAdapter(Any)
_TERMINAL_STATES = frozenset({"completed", "failed", "canceled"})
@@ -172,8 +170,6 @@ class ChildDependencyUpdate:
terminal: bool
status: ChildDependencyStatus
aggregated_outputs: dict[str, list[Any]]
- parent_action: Literal["failed", "canceled"] | None = None
- cancel_child_ids: list[str] | None = None
error_message: str | None = None
def __iter__(self):
@@ -202,8 +198,6 @@ class ChildExecutionCapability(_ChildModel):
max_depth: int = Field(default=64, ge=0)
max_children: int = Field(default=1000, ge=1)
capacity: int = Field(default=1000, ge=0)
- failure_policy: ChildFailurePolicy = "fail_parent"
- cancellation_policy: ChildCancellationPolicy = "cancel_parent"
model_config = ConfigDict(extra="forbid", frozen=True, populate_by_name=True)
@@ -322,8 +316,6 @@ class ChildExecutionCapability(_ChildModel):
parent_execution_id: str | None = None,
parent_frame: Sequence[int | str] | None = None,
parent_reference_id: str | None = None,
- failure_policy: ChildFailurePolicy | None = None,
- cancellation_policy: ChildCancellationPolicy | None = None,
) -> "ChildDependencyRecord":
self._check_parent(parent_execution_id, parent_frame, parent_reference_id)
if children is not None and child_execution_ids is not None:
@@ -409,8 +401,6 @@ class ChildExecutionCapability(_ChildModel):
parent_frame=expected_frame,
parent_reference_id=expected_reference,
children=child_records,
- failure_policy=failure_policy or self.failure_policy,
- cancellation_policy=cancellation_policy or self.cancellation_policy,
)
create_child_dependency = create_dependency
@@ -427,8 +417,6 @@ class ChildDependencyRecord(_ChildModel):
children: list[ChildExecutionRecord] = Field(default_factory=list)
completions: dict[str, ChildCompletion] = Field(default_factory=dict)
status: ChildDependencyStatus = "waiting"
- failure_policy: ChildFailurePolicy = "fail_parent"
- cancellation_policy: ChildCancellationPolicy = "cancel_parent"
error_message: str | None = None
output_keys: tuple[str, ...] | None = None
terminal_transition_count: int = Field(default=0, ge=0)
@@ -580,43 +568,12 @@ class ChildDependencyRecord(_ChildModel):
if self.output_keys is not None and tuple(sorted(outputs)) != self.output_keys:
raise ValueError("child completions returned different output keys")
- def _update_for_terminal(self, status: ChildTerminalStatus, message: str | None) -> ChildDependencyUpdate:
- parent_action: Literal["failed", "canceled"] | None = None
- cancel_child_ids: list[str] = []
- if status == "failed":
- if self.failure_policy in ("fail_parent", "cancel_siblings"):
- parent_action = "failed"
- if self.failure_policy == "cancel_siblings":
- cancel_child_ids = [
- child_id for child_id in self.child_execution_ids if child_id not in self.completions
- ]
- elif status == "canceled":
- if self.cancellation_policy in ("cancel_parent", "cancel_siblings"):
- parent_action = "canceled"
- if self.cancellation_policy == "cancel_siblings":
- cancel_child_ids = [
- child_id for child_id in self.child_execution_ids if child_id not in self.completions
- ]
- return ChildDependencyUpdate(
- changed=True,
- terminal=True,
- status=self.status,
- aggregated_outputs=self.aggregated_outputs,
- parent_action=parent_action,
- cancel_child_ids=cancel_child_ids,
- error_message=message,
- )
-
- def _result(
- self, *, changed: bool, parent_action: Literal["failed", "canceled"] | None = None
- ) -> ChildDependencyUpdate:
+ def _result(self, *, changed: bool) -> ChildDependencyUpdate:
return ChildDependencyUpdate(
changed=changed,
terminal=self.status in _TERMINAL_STATES,
status=self.status,
aggregated_outputs=self.aggregated_outputs,
- parent_action=parent_action,
- cancel_child_ids=[],
error_message=self.error_message,
)
@@ -652,37 +609,15 @@ class ChildDependencyRecord(_ChildModel):
self.output_keys = tuple(sorted(completion.outputs))
child.state = completion.status
self.status = "running"
- if completion.status == "failed" and self.failure_policy != "continue":
+ if completion.status == "failed":
self.transition_terminal("failed", completion.error_message)
- return self._update_for_terminal("failed", completion.error_message)
- if completion.status == "canceled" and self.cancellation_policy != "continue":
+ return self._result(changed=True)
+ if completion.status == "canceled":
self.transition_terminal("canceled", completion.error_message)
- return self._update_for_terminal("canceled", completion.error_message)
+ return self._result(changed=True)
if len(self.completions) == len(self.children):
- final_status: ChildTerminalStatus = "completed"
- final_message: str | None = None
- if any(item.status == "failed" for item in self.completions.values()):
- final_status = "failed"
- final_message = next(
- (
- item.error_message
- for item in self.completions.values()
- if item.status == "failed" and item.error_message
- ),
- "child failed",
- )
- elif any(item.status == "canceled" for item in self.completions.values()):
- final_status = "canceled"
- final_message = next(
- (
- item.error_message
- for item in self.completions.values()
- if item.status == "canceled" and item.error_message
- ),
- "child canceled",
- )
- self.transition_terminal(final_status, final_message)
- return self._update_for_terminal(final_status, final_message)
+ # Failed and canceled children returned above, so a full ledger holds only successes.
+ self.transition_terminal("completed", None)
return self._result(changed=True)
def record_completion(self, completion: ChildCompletion) -> ChildDependencyUpdate:
diff --git a/invokeai/app/services/shared/execution_engine/primitives.py b/invokeai/app/services/shared/execution_engine/primitives.py
index 78ca5049c6..bd08a471cd 100644
--- a/invokeai/app/services/shared/execution_engine/primitives.py
+++ b/invokeai/app/services/shared/execution_engine/primitives.py
@@ -418,7 +418,7 @@ class StreamBuffer(_InternalModel, Generic[T]):
return self.model_dump(mode="json") == other.model_dump(mode="json")
-ContinuationStatus = Literal["pending", "waiting", "running", "completed", "failed", "cancelled"]
+ContinuationStatus = Literal["pending", "waiting", "running", "completed", "failed", "canceled"]
class ContinuationRecord(_InternalModel, Generic[T]):
@@ -459,7 +459,7 @@ class ContinuationRecord(_InternalModel, Generic[T]):
@property
def terminal(self) -> bool:
- return self.status in ("completed", "failed", "cancelled")
+ return self.status in ("completed", "failed", "canceled")
def assert_scope(self, owner_id: str, frame: ExecutionFrame) -> None:
if owner_id != self.owner_id:
@@ -480,12 +480,12 @@ class ContinuationRecord(_InternalModel, Generic[T]):
_validate_name(error)
_validate_json_value(result)
allowed: dict[ContinuationStatus, frozenset[ContinuationStatus]] = {
- "pending": frozenset({"waiting", "running", "failed", "cancelled"}),
- "waiting": frozenset({"running", "failed", "cancelled"}),
- "running": frozenset({"completed", "failed", "cancelled"}),
+ "pending": frozenset({"waiting", "running", "failed", "canceled"}),
+ "waiting": frozenset({"running", "failed", "canceled"}),
+ "running": frozenset({"completed", "failed", "canceled"}),
"completed": frozenset(),
"failed": frozenset(),
- "cancelled": frozenset(),
+ "canceled": frozenset(),
}
with self._lock:
@@ -494,8 +494,8 @@ class ContinuationRecord(_InternalModel, Generic[T]):
raise ValueError("completed continuation has conflicting result")
if status == "failed" and self.error != error:
raise ValueError("failed continuation has conflicting error")
- if status == "cancelled" and self.error != error:
- raise ValueError("cancelled continuation has conflicting error")
+ if status == "canceled" and self.error != error:
+ raise ValueError("canceled continuation has conflicting error")
return False
if status not in allowed[self.status]:
if self.terminal:
@@ -531,7 +531,7 @@ class ContinuationRecord(_InternalModel, Generic[T]):
return self.transition("failed", error=error)
def cancel(self, reason: str | None = None) -> bool:
- return self.transition("cancelled", error=reason)
+ return self.transition("canceled", error=reason)
def __eq__(self, other: object) -> bool:
if not isinstance(other, ContinuationRecord):
diff --git a/invokeai/app/services/shared/execution_engine/runtime.py b/invokeai/app/services/shared/execution_engine/runtime.py
index 5de83bf10b..3853211924 100644
--- a/invokeai/app/services/shared/execution_engine/runtime.py
+++ b/invokeai/app/services/shared/execution_engine/runtime.py
@@ -77,9 +77,6 @@ class ExecutionEngineRuntime(BaseModel):
except KeyError as exc:
raise KeyError(f"stream not registered: {stream_id}") from exc
- def replace_stream(self, stream: StreamBuffer[Any]) -> None:
- self.streams[stream.stream_id] = stream
-
def remove_stream(self, stream_id: str) -> None:
self.streams.pop(stream_id, None)
diff --git a/invokeai/app/services/shared/execution_engine/scheduler.py b/invokeai/app/services/shared/execution_engine/scheduler.py
index e2b39ca81c..7eca57209e 100644
--- a/invokeai/app/services/shared/execution_engine/scheduler.py
+++ b/invokeai/app/services/shared/execution_engine/scheduler.py
@@ -310,7 +310,11 @@ class ExecutionScheduler:
ordered_classes: list[str] = []
if self._active_class in classes:
ordered_classes.append(self._active_class)
- ordered_classes.extend(class_name for class_name in self.ready_order if class_name in classes)
+ # The active class may sit anywhere in ready_order; listing it there as well would emit its
+ # queued nodes twice, so each class is listed once and the active class goes first to match pop order.
+ ordered_classes.extend(
+ class_name for class_name in self.ready_order if class_name in classes and class_name not in ordered_classes
+ )
ordered_classes.extend(sorted(classes.difference(ordered_classes)))
return tuple(
node_id
diff --git a/invokeai/app/services/shared/execution_state_migration.py b/invokeai/app/services/shared/execution_state_migration.py
index f211f34f46..b6aee7229e 100644
--- a/invokeai/app/services/shared/execution_state_migration.py
+++ b/invokeai/app/services/shared/execution_state_migration.py
@@ -1,6 +1,6 @@
"""Compatibility helpers for persisted internal execution-state snapshots."""
-from collections.abc import Mapping
+from collections.abc import Mapping, MutableMapping
from typing import Any, Final
from invokeai.app.invocations.call_saved_workflow import CallSavedWorkflowInvocation
@@ -157,15 +157,46 @@ def dump_execution_state(state: GraphExecutionState) -> dict[str, Any]:
return snapshot
-def _normalize_persisted_effects_in_snapshot(payload: Mapping[str, Any]) -> dict[str, Any]:
- """Normalize effect ledgers before GraphExecutionState rehydrates runtime state."""
+# Child dependency records used to persist per-child failure/cancellation policies. Every dependency was created
+# with the defaults and no caller consumed the policy-derived update fields, so the fields are gone. Rows written
+# before their removal still carry the keys and child records are `extra="forbid"`, so the keys are dropped on
+# load instead of rejecting the session.
+LEGACY_CHILD_POLICY_KEYS: Final[frozenset[str]] = frozenset({"failure_policy", "cancellation_policy"})
+
+
+def strip_legacy_child_policy_keys(payload: MutableMapping[str, Any]) -> None:
+ """Drop the removed per-child policy keys from one persisted payload, in place.
+
+ Rows written while the knobs existed still carry them and child records are `extra="forbid"`, so every
+ load path - full rehydration and the queue read projection - must drop them or active work reads as an
+ unreadable placeholder. A ledger that is not a mapping is malformed persisted state rather than something
+ to skip, so it raises ValueError, which queue hydration turns into a quarantined row.
+ """
+ ledger = payload.get("execution_child_dependencies")
+ if ledger is None:
+ return
+ if not isinstance(ledger, Mapping):
+ raise ValueError("Persisted execution child dependencies must be a mapping")
+ payload["execution_child_dependencies"] = {
+ dependency_id: (
+ {key: value for key, value in dependency.items() if key not in LEGACY_CHILD_POLICY_KEYS}
+ if isinstance(dependency, Mapping)
+ else dependency
+ )
+ for dependency_id, dependency in ledger.items()
+ }
+
+
+def _normalize_persisted_ledgers(payload: Mapping[str, Any]) -> dict[str, Any]:
+ """Normalize effect ledgers and drop superseded child-dependency keys before rehydration."""
normalized = dict(payload)
if "execution_effects" in normalized:
normalized["execution_effects"] = normalize_persisted_execution_effects(normalized["execution_effects"])
+ strip_legacy_child_policy_keys(normalized)
child_snapshot = normalized.get("waiting_workflow_call_child_session")
if isinstance(child_snapshot, Mapping):
- normalized["waiting_workflow_call_child_session"] = _normalize_persisted_effects_in_snapshot(child_snapshot)
+ normalized["waiting_workflow_call_child_session"] = _normalize_persisted_ledgers(child_snapshot)
return normalized
@@ -196,7 +227,7 @@ def load_execution_state(snapshot: Mapping[str, Any]) -> GraphExecutionState:
legacy_execution_snapshot = version == LEGACY_EXECUTION_STATE_VERSION
execution_effects_persisted = "execution_effects" in payload and not legacy_execution_snapshot
- normalized_payload = _normalize_persisted_effects_in_snapshot(payload)
+ normalized_payload = _normalize_persisted_ledgers(payload)
return GraphExecutionState.model_validate(
normalized_payload,
strict=False,
diff --git a/tests/app/services/session_queue/test_session_queue_dequeue.py b/tests/app/services/session_queue/test_session_queue_dequeue.py
index d68cc22bb8..79f9306622 100644
--- a/tests/app/services/session_queue/test_session_queue_dequeue.py
+++ b/tests/app/services/session_queue/test_session_queue_dequeue.py
@@ -184,6 +184,13 @@ def test_fifo_quarantines_future_snapshot_and_dequeues_later_work(
"{not valid json",
json.dumps({"execution_state_version": "invalid", "graph": {}}),
json.dumps({"execution_state_version": CURRENT_EXECUTION_STATE_VERSION, "graph": "invalid"}),
+ json.dumps(
+ {
+ "execution_state_version": CURRENT_EXECUTION_STATE_VERSION,
+ "graph": {},
+ "execution_child_dependencies": "garbage",
+ }
+ ),
],
)
def test_fifo_quarantines_unreadable_snapshot_and_dequeues_later_work(
diff --git a/tests/app/services/session_queue/test_session_queue_reads.py b/tests/app/services/session_queue/test_session_queue_reads.py
index c3e2be534f..8c4f45a028 100644
--- a/tests/app/services/session_queue/test_session_queue_reads.py
+++ b/tests/app/services/session_queue/test_session_queue_reads.py
@@ -11,11 +11,15 @@ import pytest
from pydantic_core import to_jsonable_python
from sqlalchemy import insert
+from invokeai.app.invocations.primitives import IntegerInvocation
from invokeai.app.services.session_queue.session_queue_default import SessionQueue
from invokeai.app.services.shared.database.database import Database
from invokeai.app.services.shared.database.schema.session_queue import session_queue, session_queue_enqueue_receipts
from invokeai.app.services.shared.database.schema.users import users
-from invokeai.app.services.shared.execution_state_migration import dump_execution_state
+from invokeai.app.services.shared.execution_state_migration import (
+ CURRENT_EXECUTION_STATE_VERSION,
+ dump_execution_state,
+)
from invokeai.app.services.shared.graph import Graph, GraphExecutionState
from invokeai.app.services.shared.pagination import SQLiteDirection
@@ -52,13 +56,15 @@ def _item(
destination: Optional[str] = None,
parent_item_id: Optional[int] = None,
workflow: Optional[str] = None,
+ session_payload: Optional[dict[str, Any]] = None,
) -> int:
session = GraphExecutionState(graph=Graph())
+ snapshot = session_payload if session_payload is not None else dump_execution_state(session)
values: dict[str, Any] = {
"queue_id": queue_id,
"batch_id": batch_id,
- "session_id": session.id,
- "session": json.dumps(dump_execution_state(session), default=to_jsonable_python),
+ "session_id": snapshot["id"],
+ "session": json.dumps(snapshot, default=to_jsonable_python),
"status": status,
"priority": priority,
"user_id": user_id,
@@ -356,6 +362,54 @@ class TestServiceReads:
assert (item.item_id, item.user_display_name, item.field_values[0].value) == (item_id, "Alice", 7) # type: ignore[index]
assert (for_api.status, for_api.origin, for_api.destination) == ("pending", "canvas", "gallery")
+ def test_a_row_written_with_child_policy_keys_still_reads(self, database: Database, service: SessionQueue) -> None:
+ """Rows written before the child policy knobs were removed must not read as failed synthetic items."""
+ graph = Graph()
+ graph.add_node(IntegerInvocation(id="source-call", value=1))
+ state = GraphExecutionState(graph=graph)
+ state.execution_graph.add_node(IntegerInvocation(id="prepared-call", value=1))
+ state.prepared_source_mapping["prepared-call"] = "source-call"
+ frame = state.build_workflow_call_frame(exec_node_id="prepared-call", workflow_id="saved-workflow")
+ state.begin_waiting_on_workflow_call(frame)
+ state.attach_waiting_workflow_call_child_sessions([GraphExecutionState(graph=Graph()) for _ in range(2)])
+ state.set_waiting_workflow_call_child_item_ids([20, 10])
+
+ snapshot = dump_execution_state(state)
+ dependency_id = next(iter(snapshot["execution_child_dependencies"]))
+ # Real rows written before removal carry the policies as their defaults.
+ snapshot["execution_child_dependencies"][dependency_id].update(
+ {"failure_policy": "fail_parent", "cancellation_policy": "cancel_parent"}
+ )
+ item_id = _item(database, status="in_progress", session_payload=snapshot)
+
+ item = service.get_queue_item_for_api(item_id)
+
+ assert item._snapshot_readable, item.error_message
+ assert item.status == "in_progress"
+ assert item.error_message is None
+ assert "source-call" in item.session.graph.nodes
+ assert set(item.session.execution_child_dependencies) == {dependency_id}
+
+ def test_a_row_with_a_malformed_child_ledger_reads_as_unreadable(
+ self, database: Database, service: SessionQueue
+ ) -> None:
+ """A non-mapping child ledger is malformed persisted state, not something the read projection iterates."""
+ item_id = _item(
+ database,
+ status="in_progress",
+ session_payload={
+ "id": "malformed-child-ledger-session",
+ "execution_state_version": CURRENT_EXECUTION_STATE_VERSION,
+ "graph": {},
+ "execution_child_dependencies": "garbage",
+ },
+ )
+
+ item = service.get_queue_item_for_api(item_id)
+
+ assert not item._snapshot_readable
+ assert item.status == "failed"
+
def test_summaries_follow_the_callers_order(self, database: Database, service: SessionQueue) -> None:
item_ids = [_item(database) for _ in range(3)]
child = _item(database, parent_item_id=item_ids[0])
diff --git a/tests/app/services/shared/test_execution_engine_child.py b/tests/app/services/shared/test_execution_engine_child.py
index 58027415a0..a83cf4c3e9 100644
--- a/tests/app/services/shared/test_execution_engine_child.py
+++ b/tests/app/services/shared/test_execution_engine_child.py
@@ -72,15 +72,27 @@ def test_dependency_creation_does_not_leak_capacity_on_invalid_child() -> None:
assert capability.remaining_capacity == 2
-def test_continue_policy_reports_terminal_failure_after_all_children_finish() -> None:
- dependency = _capability(failure_policy="continue").create_dependency(["first", "second"])
+ ("terminal_method", "expected_status"),
+ [("fail_child", "failed"), ("cancel_child", "canceled")],
+)
+def test_a_terminal_child_report_ends_the_dependency_before_siblings_finish(
+ terminal_method: str, expected_status: ChildTerminalStatus
+) -> None:
+ dependency = _capability().create_dependency(["first", "second", "third"], dependency_id="dependency")
+ report = getattr(dependency, terminal_method)
- dependency.fail_child("first", "first failed")
- update = dependency.complete_child("second", {"value": 2})
+ update = report("second", "child reported")
+ later = dependency.complete_child("third", {"value": 3})
+ duplicate = report("second", "child reported")
- assert update.status == "failed"
- assert update.terminal
- assert dependency.error_message == "first failed"
+ assert update.status == expected_status
+ assert update.terminal is True
+ assert dependency.error_message == "child reported"
+ assert later.changed is False
+ assert later.status == expected_status
+ assert duplicate.changed is False
+ assert duplicate.terminal is True
def test_dependency_rejects_duplicate_prebuilt_children() -> None:
@@ -134,22 +146,6 @@ def test_dependency_is_idempotent_and_rejects_conflicting_or_foreign_completion(
dependency.complete_child("other", {"value": 2})
-def test_failure_cancels_siblings_and_notifies_parent_once() -> None:
- capability = _capability(failure_policy="cancel_siblings")
- dependency = capability.create_dependency(["first", "second", "third"], dependency_id="dependency")
-
- update = dependency.fail_child("second", "child failed")
-
- assert update.status == "failed"
- assert update.parent_action == "failed"
- assert update.cancel_child_ids == ["first", "third"]
- assert update.terminal is True
-
- duplicate = dependency.fail_child("second", "child failed")
- assert duplicate.changed is False
- assert duplicate.terminal is True
-
-
def test_child_records_are_json_safe_and_round_trip() -> None:
dependency = _capability().create_dependency(["child"], dependency_id="dependency")
dependency.complete_child("child", {"value": None})
diff --git a/tests/app/services/shared/test_execution_engine_primitives.py b/tests/app/services/shared/test_execution_engine_primitives.py
index 3dbbd41eb6..800cace154 100644
--- a/tests/app/services/shared/test_execution_engine_primitives.py
+++ b/tests/app/services/shared/test_execution_engine_primitives.py
@@ -204,7 +204,7 @@ def test_continuation_record_has_atomic_idempotent_status_transitions() -> None:
[
("complete", {"output": 2}, {"output": 3}, "completed continuation has conflicting result"),
("fail", "first failure", "different failure", "failed continuation has conflicting error"),
- ("cancel", "user requested", "shutdown", "cancelled continuation has conflicting error"),
+ ("cancel", "user requested", "shutdown", "canceled continuation has conflicting error"),
],
)
def test_continuation_record_terminal_replay_rejects_conflicts_without_mutation(
diff --git a/tests/app/services/shared/test_execution_engine_scheduler.py b/tests/app/services/shared/test_execution_engine_scheduler.py
index c51fc026e1..8fae0ab8fd 100644
--- a/tests/app/services/shared/test_execution_engine_scheduler.py
+++ b/tests/app/services/shared/test_execution_engine_scheduler.py
@@ -73,6 +73,52 @@ def test_generic_scheduler_honors_opaque_readiness_predicate() -> None:
assert scheduler.pop_next() == "blocked"
+def test_ready_ids_lists_each_queued_node_once_in_pop_order() -> None:
+ plan = ExecutionPlan()
+ plan.add_node("a1", "x")
+ plan.add_node("a2", "x", dependencies=("a1",))
+ plan.add_node("b1", "y")
+ plan.add_node("q1", "w")
+ scheduler = ExecutionScheduler(plan, ready_order=("x", "y"))
+
+ assert scheduler.pop_next() == "a1"
+ assert scheduler.complete("a1") == ("a2",)
+
+ listed = scheduler.ready_ids
+
+ popped: list[str] = []
+ while (node_id := scheduler.pop_next()) is not None:
+ popped.append(node_id)
+
+ assert listed == tuple(popped) == ("a2", "b1", "q1")
+
+
+def test_ready_ids_lists_the_active_class_first_when_it_is_not_first_in_ready_order() -> None:
+ plan = ExecutionPlan()
+ plan.add_node("a1", "x")
+ plan.add_node("a3", "x")
+ plan.add_node("a2", "x", dependencies=("a1",))
+ plan.add_node("b1", "y")
+ plan.add_node("b2", "y")
+ plan.add_node("q1", "w")
+ scheduler = ExecutionScheduler(plan, ready_order=("x", "y"))
+
+ # Drain class x so the scheduler moves to class y, then make new class x work available while
+ # class y still has a queued node. The active class sits at ready_order index 1 here.
+ assert scheduler.pop_next() == "a1"
+ assert scheduler.pop_next() == "a3"
+ assert scheduler.pop_next() == "b1"
+ assert scheduler.complete("a1") == ("a2",)
+
+ listed = scheduler.ready_ids
+
+ popped: list[str] = []
+ while (node_id := scheduler.pop_next()) is not None:
+ popped.append(node_id)
+
+ assert listed == tuple(popped) == ("b2", "a2", "q1")
+
+
def test_generic_scheduler_discards_node_with_unmet_prerequisites() -> None:
plan = ExecutionPlan()
plan.add_node("prerequisite", "Prerequisite")
diff --git a/tests/app/services/shared/test_execution_state_migration.py b/tests/app/services/shared/test_execution_state_migration.py
index 5822d56b87..b37a330bd1 100644
--- a/tests/app/services/shared/test_execution_state_migration.py
+++ b/tests/app/services/shared/test_execution_state_migration.py
@@ -2,6 +2,7 @@ import json
import re
import pytest
+from pydantic import ValidationError
from invokeai.app.invocations.call_saved_workflow import CallSavedWorkflowInvocation
from invokeai.app.invocations.collections import RangeInvocation
@@ -330,6 +331,39 @@ def test_round_trips_pending_generic_child_dependency_and_partial_completion() -
assert dependency.completions["10"].outputs == {"value": "ten"}
+def test_loads_persisted_child_dependency_after_dropping_legacy_policy_keys() -> None:
+ """Session rows written while the child policy knobs existed must still hydrate after removal."""
+ graph = Graph()
+ graph.add_node(AddInvocation(id="source-call", a=1, b=2))
+ state = GraphExecutionState(graph=graph)
+ state.execution_graph.add_node(AddInvocation(id="prepared-call", a=1, b=2))
+ state.prepared_source_mapping["prepared-call"] = "source-call"
+ frame = state.build_workflow_call_frame(exec_node_id="prepared-call", workflow_id="saved-workflow")
+ state.begin_waiting_on_workflow_call(frame)
+ state.attach_waiting_workflow_call_child_sessions([GraphExecutionState(graph=Graph()) for _ in range(2)])
+ state.set_waiting_workflow_call_child_item_ids([20, 10])
+ state.record_generic_child_completion(10, {"value": "ten"})
+
+ snapshot = dump_execution_state(state)
+ dependency_id = next(iter(snapshot["execution_child_dependencies"]))
+ persisted = snapshot["execution_child_dependencies"][dependency_id]
+ # Real rows written before removal carry the policies as their defaults.
+ persisted.update({"failure_policy": "fail_parent", "cancellation_policy": "cancel_parent"})
+
+ restored = load_execution_state(snapshot)
+
+ assert restored.execution_child_dependencies[dependency_id].status == "running"
+ assert restored._generic_child_dependencies[dependency_id].completions.keys() == {"10"}
+
+ with pytest.raises(ValidationError):
+ load_execution_state(
+ {
+ **snapshot,
+ "execution_child_dependencies": {dependency_id: {**persisted, "not_a_field": 1}},
+ }
+ )
+
+
@pytest.mark.parametrize(
("terminal_method", "expected_status"),
[("fail_generic_child", "failed"), ("cancel_generic_child", "canceled")],