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(queue): preserve called-workflow previews and metadata

JPPhotod7c62b459eaa
diff --git a/invokeai/app/services/events/events_common.py b/invokeai/app/services/events/events_common.py
index a604ef4d77..dd79a1a71f 100644
--- a/invokeai/app/services/events/events_common.py
+++ b/invokeai/app/services/events/events_common.py
@@ -112,6 +112,23 @@ class InvocationEventBase(QueueItemEventBase):
session_id: str = Field(description="The ID of the session (aka graph execution state)")
invocation: AnyInvocation = Field(description="The ID of the invocation")
invocation_source_id: str = Field(description="The ID of the prepared invocation's source node")
+ parent_item_id: int | None = Field(
+ default=None, description="The parent queue item id when this item is a called-workflow child"
+ )
+ root_item_id: int | None = Field(
+ default=None, description="The root queue item id for this called-workflow chain, if any"
+ )
+ workflow_call_parent_source_id: str | None = Field(
+ default=None,
+ description="The visible parent Call Saved Workflow source node for a called-workflow child event",
+ )
+
+
+def _get_workflow_call_parent_source_id(queue_item: SessionQueueItem) -> str | None:
+ """Return the root visible call node for a nested workflow-call event."""
+ if queue_item.session.workflow_call_stack:
+ return queue_item.session.workflow_call_stack[0].source_call_node_id
+ return None
@payload_schema.register
@@ -129,9 +146,12 @@ class InvocationStartedEvent(InvocationEventBase):
origin=queue_item.origin,
destination=queue_item.destination,
user_id=queue_item.user_id,
+ parent_item_id=queue_item.parent_item_id,
+ root_item_id=queue_item.root_item_id,
session_id=queue_item.session_id,
invocation=invocation,
invocation_source_id=queue_item.session.prepared_source_mapping[invocation.id],
+ workflow_call_parent_source_id=_get_workflow_call_parent_source_id(queue_item),
)
@@ -195,9 +215,12 @@ class InvocationProgressEvent(InvocationEventBase):
origin=queue_item.origin,
destination=queue_item.destination,
user_id=queue_item.user_id,
+ parent_item_id=queue_item.parent_item_id,
+ root_item_id=queue_item.root_item_id,
session_id=queue_item.session_id,
invocation=invocation,
invocation_source_id=queue_item.session.prepared_source_mapping[invocation.id],
+ workflow_call_parent_source_id=_get_workflow_call_parent_source_id(queue_item),
percentage=percentage,
image=image,
message=message,
@@ -225,9 +248,12 @@ class InvocationCompleteEvent(InvocationEventBase):
origin=queue_item.origin,
destination=queue_item.destination,
user_id=queue_item.user_id,
+ parent_item_id=queue_item.parent_item_id,
+ root_item_id=queue_item.root_item_id,
session_id=queue_item.session_id,
invocation=invocation,
invocation_source_id=queue_item.session.prepared_source_mapping[invocation.id],
+ workflow_call_parent_source_id=_get_workflow_call_parent_source_id(queue_item),
result=result,
)
@@ -258,9 +284,12 @@ class InvocationErrorEvent(InvocationEventBase):
origin=queue_item.origin,
destination=queue_item.destination,
user_id=queue_item.user_id,
+ parent_item_id=queue_item.parent_item_id,
+ root_item_id=queue_item.root_item_id,
session_id=queue_item.session_id,
invocation=invocation,
invocation_source_id=queue_item.session.prepared_source_mapping[invocation.id],
+ workflow_call_parent_source_id=_get_workflow_call_parent_source_id(queue_item),
error_type=error_type,
error_message=error_message,
error_traceback=error_traceback,
diff --git a/invokeai/app/services/progress_previews/progress_previews_common.py b/invokeai/app/services/progress_previews/progress_previews_common.py
index 039978cae1..1ed49c67a4 100644
--- a/invokeai/app/services/progress_previews/progress_previews_common.py
+++ b/invokeai/app/services/progress_previews/progress_previews_common.py
@@ -17,6 +17,16 @@ class ProgressPreviewDTO(BaseModel):
item_id: int = Field(description="The ID of the queue item")
session_id: str = Field(description="The ID of the session (aka graph execution state)")
invocation_source_id: str = Field(description="The ID of the prepared invocation's source node")
+ parent_item_id: int | None = Field(
+ default=None, description="The parent queue item id when this item is a called-workflow child"
+ )
+ root_item_id: int | None = Field(
+ default=None, description="The root queue item id for this called-workflow chain, if any"
+ )
+ workflow_call_parent_source_id: str | None = Field(
+ default=None,
+ description="The visible parent Call Saved Workflow source node for a called-workflow child event",
+ )
revision: int | None = Field(description="Monotonic per queue item and session; see InvocationProgressEvent")
message: str = Field(description="A message to display")
percentage: float | None = Field(description="The percentage of the progress, or null if indeterminate")
@@ -29,6 +39,9 @@ class ProgressPreviewDTO(BaseModel):
item_id=event.item_id,
session_id=event.session_id,
invocation_source_id=event.invocation_source_id,
+ parent_item_id=event.parent_item_id,
+ root_item_id=event.root_item_id,
+ workflow_call_parent_source_id=event.workflow_call_parent_source_id,
revision=event.revision,
message=event.message,
percentage=event.percentage,
diff --git a/invokeai/app/services/session_queue/session_queue_sqlite.py b/invokeai/app/services/session_queue/session_queue_sqlite.py
index 0f65a57846..be167517fd 100644
--- a/invokeai/app/services/session_queue/session_queue_sqlite.py
+++ b/invokeai/app/services/session_queue/session_queue_sqlite.py
@@ -1496,7 +1496,7 @@ class SqliteSessionQueue(SessionQueueBase):
parent_queue_item.batch_id,
field_values_json,
parent_queue_item.priority,
- None,
+ parent_queue_item.workflow.model_dump_json() if parent_queue_item.workflow else None,
parent_queue_item.origin,
parent_queue_item.destination,
None,
diff --git a/invokeai/frontend/web/openapi.json b/invokeai/frontend/web/openapi.json
index 63fa48f4f3..f15addc9fb 100644
--- a/invokeai/frontend/web/openapi.json
+++ b/invokeai/frontend/web/openapi.json
@@ -49550,6 +49550,45 @@
"title": "Invocation Source Id",
"type": "string"
},
+ "parent_item_id": {
+ "anyOf": [
+ {
+ "type": "integer"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "The parent queue item id when this item is a called-workflow child",
+ "title": "Parent Item Id"
+ },
+ "root_item_id": {
+ "anyOf": [
+ {
+ "type": "integer"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "The root queue item id for this called-workflow chain, if any",
+ "title": "Root Item Id"
+ },
+ "workflow_call_parent_source_id": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "The visible parent Call Saved Workflow source node for a called-workflow child event",
+ "title": "Workflow Call Parent Source Id"
+ },
"result": {
"description": "The result of the invocation",
"oneOf": [
@@ -49949,6 +49988,9 @@
"session_id",
"invocation",
"invocation_source_id",
+ "parent_item_id",
+ "root_item_id",
+ "workflow_call_parent_source_id",
"result"
],
"title": "InvocationCompleteEvent",
@@ -51015,6 +51057,45 @@
"title": "Invocation Source Id",
"type": "string"
},
+ "parent_item_id": {
+ "anyOf": [
+ {
+ "type": "integer"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "The parent queue item id when this item is a called-workflow child",
+ "title": "Parent Item Id"
+ },
+ "root_item_id": {
+ "anyOf": [
+ {
+ "type": "integer"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "The root queue item id for this called-workflow chain, if any",
+ "title": "Root Item Id"
+ },
+ "workflow_call_parent_source_id": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "The visible parent Call Saved Workflow source node for a called-workflow child event",
+ "title": "Workflow Call Parent Source Id"
+ },
"error_type": {
"description": "The error type",
"title": "Error Type",
@@ -51042,6 +51123,9 @@
"session_id",
"invocation",
"invocation_source_id",
+ "parent_item_id",
+ "root_item_id",
+ "workflow_call_parent_source_id",
"error_type",
"error_message",
"error_traceback"
@@ -53437,6 +53521,45 @@
"title": "Invocation Source Id",
"type": "string"
},
+ "parent_item_id": {
+ "anyOf": [
+ {
+ "type": "integer"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "The parent queue item id when this item is a called-workflow child",
+ "title": "Parent Item Id"
+ },
+ "root_item_id": {
+ "anyOf": [
+ {
+ "type": "integer"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "The root queue item id for this called-workflow chain, if any",
+ "title": "Root Item Id"
+ },
+ "workflow_call_parent_source_id": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "The visible parent Call Saved Workflow source node for a called-workflow child event",
+ "title": "Workflow Call Parent Source Id"
+ },
"message": {
"description": "A message to display",
"title": "Message",
@@ -53507,6 +53630,9 @@
"session_id",
"invocation",
"invocation_source_id",
+ "parent_item_id",
+ "root_item_id",
+ "workflow_call_parent_source_id",
"message",
"percentage",
"image",
@@ -54576,6 +54702,45 @@
"description": "The ID of the prepared invocation's source node",
"title": "Invocation Source Id",
"type": "string"
+ },
+ "parent_item_id": {
+ "anyOf": [
+ {
+ "type": "integer"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "The parent queue item id when this item is a called-workflow child",
+ "title": "Parent Item Id"
+ },
+ "root_item_id": {
+ "anyOf": [
+ {
+ "type": "integer"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "The root queue item id for this called-workflow chain, if any",
+ "title": "Root Item Id"
+ },
+ "workflow_call_parent_source_id": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "default": null,
+ "description": "The visible parent Call Saved Workflow source node for a called-workflow child event",
+ "title": "Workflow Call Parent Source Id"
}
},
"required": [
@@ -54588,7 +54753,10 @@
"user_id",
"session_id",
"invocation",
- "invocation_source_id"
+ "invocation_source_id",
+ "parent_item_id",
+ "root_item_id",
+ "workflow_call_parent_source_id"
],
"title": "InvocationStartedEvent",
"type": "object"
@@ -82124,6 +82292,42 @@
"title": "Invocation Source Id",
"description": "The ID of the prepared invocation's source node"
},
+ "parent_item_id": {
+ "anyOf": [
+ {
+ "type": "integer"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "title": "Parent Item Id",
+ "description": "The parent queue item id when this item is a called-workflow child"
+ },
+ "root_item_id": {
+ "anyOf": [
+ {
+ "type": "integer"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "title": "Root Item Id",
+ "description": "The root queue item id for this called-workflow chain, if any"
+ },
+ "workflow_call_parent_source_id": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "title": "Workflow Call Parent Source Id",
+ "description": "The visible parent Call Saved Workflow source node for a called-workflow child event"
+ },
"revision": {
"anyOf": [
{
diff --git a/invokeai/frontend/web/src/services/api/schema.ts b/invokeai/frontend/web/src/services/api/schema.ts
index af0650ccda..8e1c6ce03e 100644
--- a/invokeai/frontend/web/src/services/api/schema.ts
+++ b/invokeai/frontend/web/src/services/api/schema.ts
@@ -20512,6 +20512,24 @@ export type components = {
* @description The ID of the prepared invocation's source node
*/
invocation_source_id: string;
+ /**
+ * Parent Item Id
+ * @description The parent queue item id when this item is a called-workflow child
+ * @default null
+ */
+ parent_item_id: number | null;
+ /**
+ * Root Item Id
+ * @description The root queue item id for this called-workflow chain, if any
+ * @default null
+ */
+ root_item_id: number | null;
+ /**
+ * Workflow Call Parent Source Id
+ * @description The visible parent Call Saved Workflow source node for a called-workflow child event
+ * @default null
+ */
+ workflow_call_parent_source_id: string | null;
/**
* Result
* @description The result of the invocation
@@ -20576,6 +20594,24 @@ export type components = {
* @description The ID of the prepared invocation's source node
*/
invocation_source_id: string;
+ /**
+ * Parent Item Id
+ * @description The parent queue item id when this item is a called-workflow child
+ * @default null
+ */
+ parent_item_id: number | null;
+ /**
+ * Root Item Id
+ * @description The root queue item id for this called-workflow chain, if any
+ * @default null
+ */
+ root_item_id: number | null;
+ /**
+ * Workflow Call Parent Source Id
+ * @description The visible parent Call Saved Workflow source node for a called-workflow child event
+ * @default null
+ */
+ workflow_call_parent_source_id: string | null;
/**
* Error Type
* @description The error type
@@ -20982,6 +21018,24 @@ export type components = {
* @description The ID of the prepared invocation's source node
*/
invocation_source_id: string;
+ /**
+ * Parent Item Id
+ * @description The parent queue item id when this item is a called-workflow child
+ * @default null
+ */
+ parent_item_id: number | null;
+ /**
+ * Root Item Id
+ * @description The root queue item id for this called-workflow chain, if any
+ * @default null
+ */
+ root_item_id: number | null;
+ /**
+ * Workflow Call Parent Source Id
+ * @description The visible parent Call Saved Workflow source node for a called-workflow child event
+ * @default null
+ */
+ workflow_call_parent_source_id: string | null;
/**
* Message
* @description A message to display
@@ -21069,6 +21123,24 @@ export type components = {
* @description The ID of the prepared invocation's source node
*/
invocation_source_id: string;
+ /**
+ * Parent Item Id
+ * @description The parent queue item id when this item is a called-workflow child
+ * @default null
+ */
+ parent_item_id: number | null;
+ /**
+ * Root Item Id
+ * @description The root queue item id for this called-workflow chain, if any
+ * @default null
+ */
+ root_item_id: number | null;
+ /**
+ * Workflow Call Parent Source Id
+ * @description The visible parent Call Saved Workflow source node for a called-workflow child event
+ * @default null
+ */
+ workflow_call_parent_source_id: string | null;
};
/**
* InvokeAIAppConfig
@@ -34817,6 +34889,21 @@ export type components = {
* @description The ID of the prepared invocation's source node
*/
invocation_source_id: string;
+ /**
+ * Parent Item Id
+ * @description The parent queue item id when this item is a called-workflow child
+ */
+ parent_item_id?: number | null;
+ /**
+ * Root Item Id
+ * @description The root queue item id for this called-workflow chain, if any
+ */
+ root_item_id?: number | null;
+ /**
+ * Workflow Call Parent Source Id
+ * @description The visible parent Call Saved Workflow source node for a called-workflow child event
+ */
+ workflow_call_parent_source_id?: string | null;
/**
* Revision
* @description Monotonic per queue item and session; see InvocationProgressEvent
diff --git a/invokeai/frontend/webv2/src/features/nodes/data/nodeExecutionStore.test.ts b/invokeai/frontend/webv2/src/features/nodes/data/nodeExecutionStore.test.ts
index 5e3d47e26f..cab8999b48 100644
--- a/invokeai/frontend/webv2/src/features/nodes/data/nodeExecutionStore.test.ts
+++ b/invokeai/frontend/webv2/src/features/nodes/data/nodeExecutionStore.test.ts
@@ -42,6 +42,20 @@ describe('node execution lifecycle', () => {
expect(nodeExecutionStore.get('node-1')?.latestOutput).toEqual({ type: 'integer_output', value: 2 });
});
+ it('shows an image returned through workflow return values', () => {
+ nodeExecutionStore.completed({
+ invocation_source_id: 'call-node',
+ result: {
+ type: 'workflow_return_output',
+ values: { Image: { image_name: 'returned image.png' } },
+ },
+ });
+
+ expect(nodeExecutionStore.get('call-node')?.outputImageUrl).toBe(
+ 'https://api.test/api/v1/images/i/returned%20image.png/thumbnail'
+ );
+ });
+
it('settles the named running nodes to the run outcome without disturbing terminal or other nodes', () => {
nodeExecutionStore.started({ invocation_source_id: 'running' });
nodeExecutionStore.started({ invocation_source_id: 'other-run' });
diff --git a/invokeai/frontend/webv2/src/features/nodes/data/nodeExecutionStore.ts b/invokeai/frontend/webv2/src/features/nodes/data/nodeExecutionStore.ts
index c41f036f2e..53e0e3047f 100644
--- a/invokeai/frontend/webv2/src/features/nodes/data/nodeExecutionStore.ts
+++ b/invokeai/frontend/webv2/src/features/nodes/data/nodeExecutionStore.ts
@@ -4,6 +4,7 @@ import type {
NodeInvocationStartedEvent,
} from '@features/nodes/core/executionContracts';
+import { getOutputImageNames } from '@platform/core/outputImages';
import { registerAccountOwnedResource } from '@platform/state/accountLifecycle';
import { createKeyedTransientStore } from '@platform/state/externalStore';
@@ -36,13 +37,6 @@ export interface NodeExecutionState {
const stateByNodeId = createKeyedTransientStore<string, NodeExecutionState>();
-/** Pull the produced image out of an invocation output, whatever the node type. */
-const getResultImageName = (result: unknown): string | null => {
- const image = (result as { image?: { image_name?: unknown } }).image;
-
- return typeof image?.image_name === 'string' ? image.image_name : null;
-};
-
export const nodeExecutionStore = {
clearAll(): void {
stateByNodeId.clear();
@@ -54,7 +48,7 @@ export const nodeExecutionStore = {
return stateByNodeId.subscribeKey(nodeId, listener);
},
completed(event: NodeInvocationCompleteEvent): void {
- const imageName = getResultImageName(event.result);
+ const imageName = getOutputImageNames(event.result)[0];
const previous = stateByNodeId.get(event.invocation_source_id);
stateByNodeId.set(event.invocation_source_id, {
diff --git a/invokeai/frontend/webv2/src/features/queue/core/types.ts b/invokeai/frontend/webv2/src/features/queue/core/types.ts
index e4a9a0c7eb..f604ac064b 100644
--- a/invokeai/frontend/webv2/src/features/queue/core/types.ts
+++ b/invokeai/frontend/webv2/src/features/queue/core/types.ts
@@ -294,6 +294,9 @@ export interface QueueProgressPreviewPayload {
item_id: number;
session_id: string;
invocation_source_id: string;
+ parent_item_id?: number | null;
+ root_item_id?: number | null;
+ workflow_call_parent_source_id?: string | null;
revision: number | null;
message: string;
percentage: number | null;
diff --git a/invokeai/frontend/webv2/src/features/queue/data/events.ts b/invokeai/frontend/webv2/src/features/queue/data/events.ts
index cc81a6f9e4..82ed552b76 100644
--- a/invokeai/frontend/webv2/src/features/queue/data/events.ts
+++ b/invokeai/frontend/webv2/src/features/queue/data/events.ts
@@ -84,6 +84,10 @@ export interface InvocationEventBase extends QueueItemEventBase {
session_id: string;
/** The id of the executing invocation's source node — the editor's node id. */
invocation_source_id: string;
+ parent_item_id?: number | null;
+ root_item_id?: number | null;
+ /** The visible parent Call Saved Workflow node for child execution events. */
+ workflow_call_parent_source_id?: string | null;
}
export interface InvocationStartedEvent extends InvocationEventBase {}
diff --git a/invokeai/frontend/webv2/src/features/queue/data/submissionApi.test.ts b/invokeai/frontend/webv2/src/features/queue/data/submissionApi.test.ts
index de2f62152c..b37bf3d093 100644
--- a/invokeai/frontend/webv2/src/features/queue/data/submissionApi.test.ts
+++ b/invokeai/frontend/webv2/src/features/queue/data/submissionApi.test.ts
@@ -525,6 +525,88 @@ describe('getResultImages', () => {
expect(images.map((image) => image.imageName)).toEqual(['external-a.png', 'external-b.png']);
});
+ it('extracts all image names from named workflow return values', async () => {
+ mocks.apiFetchJson.mockImplementation((url: string) => {
+ if (url === '/api/v1/queue/default/i/1') {
+ return Promise.resolve({
+ item_id: 1,
+ session: {
+ results: {
+ call: {
+ type: 'workflow_return_output',
+ values: {
+ Image: { image_name: 'returned-a.png' },
+ Images: { collection: [{ image_name: 'returned-b.png' }, { image_name: 'returned-c.png' }] },
+ },
+ },
+ },
+ },
+ status: 'completed',
+ });
+ }
+
+ const imageName = decodeURIComponent(url.replace('/api/v1/images/i/', ''));
+ return Promise.resolve({
+ height: 768,
+ image_name: imageName,
+ image_url: `/images/${imageName}`,
+ is_intermediate: false,
+ thumbnail_url: `/thumbs/${imageName}`,
+ width: 1024,
+ });
+ });
+
+ const { getResultImages } = await import('./submissionApi');
+
+ const images = await getResultImages(1, 'source-1', '2026-06-15T00:00:00.000Z');
+
+ expect(images.map((image) => image.imageName)).toEqual(['returned-a.png', 'returned-b.png', 'returned-c.png']);
+ });
+
+ it('ignores metadata and unused workflow return value images', async () => {
+ mocks.apiFetchJson.mockImplementation((url: string) => {
+ if (url === '/api/v1/queue/default/i/1') {
+ return Promise.resolve({
+ item_id: 1,
+ session: {
+ results: {
+ output: {
+ image: { image_name: 'actual.png' },
+ output_meta: { image_name: 'metadata.png' },
+ type: 'image_output',
+ },
+ unused: {
+ type: 'workflow_return_value_output',
+ value: { image_name: 'unused.png' },
+ },
+ returned: {
+ type: 'workflow_return_output',
+ values: { Image: { image_name: 'returned.png' } },
+ },
+ },
+ },
+ status: 'completed',
+ });
+ }
+
+ const imageName = decodeURIComponent(url.replace('/api/v1/images/i/', ''));
+ return Promise.resolve({
+ height: 768,
+ image_name: imageName,
+ image_url: `/images/${imageName}`,
+ is_intermediate: false,
+ thumbnail_url: `/thumbs/${imageName}`,
+ width: 1024,
+ });
+ });
+
+ const { getResultImages } = await import('./submissionApi');
+
+ const images = await getResultImages(1, 'source-1', '2026-06-15T00:00:00.000Z');
+
+ expect(images.map((image) => image.imageName)).toEqual(['actual.png', 'returned.png']);
+ });
+
it('carries the backend creation timestamp, normalized to ISO, alongside the submission instant', async () => {
mocks.apiFetchJson.mockImplementation((url: string) => {
if (url === '/api/v1/queue/default/i/1') {
diff --git a/invokeai/frontend/webv2/src/features/queue/data/submissionApi.ts b/invokeai/frontend/webv2/src/features/queue/data/submissionApi.ts
index 4446a4dac3..8eb0e85b8c 100644
--- a/invokeai/frontend/webv2/src/features/queue/data/submissionApi.ts
+++ b/invokeai/frontend/webv2/src/features/queue/data/submissionApi.ts
@@ -14,6 +14,7 @@ import {
sanitizeBatchCount,
} from '@features/queue/core/promptBatch';
import { mapWithConcurrency } from '@platform/core/concurrency';
+import { getOutputImageNames } from '@platform/core/outputImages';
import { assertAccountScopeCurrent, captureAccountScope } from '@platform/state/accountLifecycle';
import { normalizeServerTimestamp } from '@platform/time/serverTimestamp';
import { absolutizeApiUrl, ApiError, apiFetch, apiFetchJson } from '@platform/transport/http';
@@ -154,25 +155,7 @@ const getResultImageNames = (queueItem: QueueServerItemDTO, options?: QueueResul
: Object.values(results);
for (const result of resultValues) {
- if (!result || typeof result !== 'object') {
- continue;
- }
-
- const imageName = (result as { image?: { image_name?: unknown } }).image?.image_name;
- if (typeof imageName === 'string') {
- imageNames.add(imageName);
- }
-
- const collection = (result as { collection?: unknown }).collection;
- if (Array.isArray(collection)) {
- for (const item of collection) {
- const collectionImageName =
- item && typeof item === 'object' ? (item as { image_name?: unknown }).image_name : undefined;
- if (typeof collectionImageName === 'string') {
- imageNames.add(collectionImageName);
- }
- }
- }
+ getOutputImageNames(result).forEach((imageName) => imageNames.add(imageName));
}
return [...imageNames];
diff --git a/invokeai/frontend/webv2/src/features/queue/runtime.test.ts b/invokeai/frontend/webv2/src/features/queue/runtime.test.ts
index 8ae3947ab9..3703f75762 100644
--- a/invokeai/frontend/webv2/src/features/queue/runtime.test.ts
+++ b/invokeai/frontend/webv2/src/features/queue/runtime.test.ts
@@ -166,6 +166,7 @@ describe('queue runtime', () => {
batchCount: 3,
graph: { edges: [], id: 'backend-graph', nodes: { noise: { id: 'noise', seed: 7, type: 'noise' } } },
kind: 'workflow',
+ workflow: { edges: [], name: 'Call-only workflow', nodes: [], version: '1.0.0' },
...(seeds === undefined ? {} : { seeds: seeds as never }),
};
queueItem.snapshot.sourceId = 'workflow';
@@ -176,7 +177,11 @@ describe('queue runtime', () => {
expect(createQueueItemBackendSubmission({ id: 'project-1' }, asWorkflow([seed]))).toMatchObject({
kind: 'workflow',
- request: { batchCount: 3, seeds: [seed] },
+ request: {
+ batchCount: 3,
+ seeds: [seed],
+ workflow: { name: 'Call-only workflow' },
+ },
});
expect(createQueueItemBackendSubmission({ id: 'project-1' }, asWorkflow(undefined))).toMatchObject({
kind: 'workflow',
diff --git a/invokeai/frontend/webv2/src/features/queue/runtime/coordinator.test.ts b/invokeai/frontend/webv2/src/features/queue/runtime/coordinator.test.ts
index a8bba83ee6..456eec498a 100644
--- a/invokeai/frontend/webv2/src/features/queue/runtime/coordinator.test.ts
+++ b/invokeai/frontend/webv2/src/features/queue/runtime/coordinator.test.ts
@@ -1011,6 +1011,100 @@ describe('queueCoordinator', () => {
await expect(harness.coordinator.waitForResults('local-1', '2026-06-10T00:00:00Z')).resolves.toHaveLength(1);
});
+ it('routes child invocation events to the parent call node', async () => {
+ harness.api.enqueueWorkflow.mockResolvedValue({ batchId: 'batch-1', enqueued: 1, itemIds: [1], requested: 1 });
+ harness.coordinator.connect();
+ await harness.coordinator.submitWorkflow('local-1', workflowRequest);
+
+ harness.socket.fire('invocation_started', {
+ ...createStatusEvent({ item_id: 2 }),
+ invocation_source_id: 'child-node',
+ root_item_id: 1,
+ workflow_call_parent_source_id: 'call-node',
+ });
+
+ expect(harness.nodeExecution.started).toHaveBeenCalledWith(
+ expect.objectContaining({
+ invocation_source_id: 'call-node',
+ item_id: 1,
+ })
+ );
+ });
+
+ it('routes child preview frames to the parent call node and root progress slot', async () => {
+ harness.api.enqueueWorkflow.mockResolvedValue({ batchId: 'batch-1', enqueued: 1, itemIds: [1], requested: 1 });
+ harness.coordinator.connect();
+ await harness.coordinator.submitWorkflow('local-1', workflowRequest);
+
+ harness.socket.fire('invocation_progress', {
+ ...createStatusEvent({ item_id: 2 }),
+ image: { dataURL: 'data:image/png;base64,child', height: 32, width: 64 },
+ invocation_source_id: 'child-node',
+ message: 'Child sampling',
+ percentage: 0.5,
+ root_item_id: 1,
+ workflow_call_parent_source_id: 'call-node',
+ });
+
+ expect(harness.nodeExecution.progress).toHaveBeenCalledWith('call-node', 0.5, 'Child sampling');
+ expect(harness.progressImage.set).toHaveBeenCalledWith(
+ { dataUrl: 'data:image/png;base64,child', height: 32, width: 64 },
+ { itemIndex: 1, queueItemId: 'local-1' }
+ );
+ });
+
+ it('allows a child preview revision again after the child reaches terminal status', async () => {
+ harness.api.enqueueWorkflow.mockResolvedValue({ batchId: 'batch-1', enqueued: 1, itemIds: [1], requested: 1 });
+ harness.coordinator.connect();
+ await harness.coordinator.submitWorkflow('local-1', workflowRequest);
+
+ const childFrame = {
+ ...createStatusEvent({ item_id: 2 }),
+ image: { dataURL: 'data:image/png;base64,child', height: 32, width: 64 },
+ invocation_source_id: 'child-node',
+ message: 'Child sampling',
+ percentage: 0.5,
+ revision: 1,
+ root_item_id: 1,
+ session_id: 'child-session',
+ workflow_call_parent_source_id: 'call-node',
+ };
+
+ harness.socket.fire('invocation_progress', childFrame);
+ harness.socket.fire('queue_item_status_changed', createStatusEvent({ item_id: 2, status: 'completed' }));
+ harness.socket.fire('invocation_progress', childFrame);
+
+ expect(harness.progressImage.set).toHaveBeenCalledTimes(2);
+ });
+
+ it('bounds preview gates when child terminal events are missed', async () => {
+ harness.api.enqueueWorkflow.mockResolvedValue({ batchId: 'batch-1', enqueued: 1, itemIds: [1], requested: 1 });
+ harness.coordinator.connect();
+ await harness.coordinator.submitWorkflow('local-1', workflowRequest);
+
+ const frame = (item_id: number) => ({
+ ...createStatusEvent({ item_id }),
+ image: { dataURL: `data:image/png;base64,child-${item_id}`, height: 32, width: 64 },
+ invocation_source_id: 'child-node',
+ message: 'Child sampling',
+ percentage: 0.5,
+ revision: 1,
+ root_item_id: 1,
+ session_id: `child-session-${item_id}`,
+ workflow_call_parent_source_id: 'call-node',
+ });
+
+ for (let itemId = 2; itemId <= 1026; itemId += 1) {
+ harness.socket.fire('invocation_progress', frame(itemId));
+ }
+
+ // Item 2's gate was evicted by the bounded fallback, so a missed terminal
+ // event cannot leave it permanently stale if the id is reused.
+ harness.socket.fire('invocation_progress', frame(2));
+
+ expect(harness.progressImage.set).toHaveBeenCalledTimes(1026);
+ });
+
it('does not buffer node events while no enqueue request is in flight', async () => {
harness.api.enqueueWorkflow.mockResolvedValueOnce({ batchId: 'batch-1', enqueued: 1, itemIds: [1], requested: 1 });
harness.coordinator.connect();
diff --git a/invokeai/frontend/webv2/src/features/queue/runtime/coordinator.ts b/invokeai/frontend/webv2/src/features/queue/runtime/coordinator.ts
index f0f6cf7c59..245a3b1032 100644
--- a/invokeai/frontend/webv2/src/features/queue/runtime/coordinator.ts
+++ b/invokeai/frontend/webv2/src/features/queue/runtime/coordinator.ts
@@ -41,6 +41,7 @@ const TERMINAL_EVENT_BUFFER_LIMIT = 256;
const NODE_EVENT_BUFFER_ITEM_LIMIT = 64;
const NODE_EVENT_BUFFER_EVENTS_PER_ITEM = 512;
const BACKEND_READ_CONCURRENCY = 16;
+const FRAME_GATE_LIMIT = 1024;
/**
* Queue's view of model-load activity derived from socket events. The
@@ -256,6 +257,46 @@ export const createQueueCoordinator = (
*/
const latestFrameGates = new Map<number, { revision: number | null; sessionId: string }>();
+ const rememberFrameGate = (itemId: number, gate: { revision: number | null; sessionId: string }): void => {
+ latestFrameGates.delete(itemId);
+ latestFrameGates.set(itemId, gate);
+
+ while (latestFrameGates.size > FRAME_GATE_LIMIT) {
+ let oldestId: number | undefined;
+
+ for (const candidate of latestFrameGates.keys()) {
+ if (!waits.has(candidate)) {
+ oldestId = candidate;
+ break;
+ }
+ }
+
+ if (oldestId === undefined) {
+ return;
+ }
+
+ latestFrameGates.delete(oldestId);
+ }
+ };
+
+ const getTrackedBackendItemId = (event: { item_id: number; root_item_id?: number | null }): number =>
+ event.root_item_id ?? event.item_id;
+
+ const getNodeSourceId = (event: { invocation_source_id: string; workflow_call_parent_source_id?: string | null }) =>
+ event.workflow_call_parent_source_id ?? event.invocation_source_id;
+
+ const routeNodeEvent = <T extends NodeEvent['event']>(
+ event: T,
+ backendItemId: number,
+ invocationSourceId: string
+ ): T => {
+ if (backendItemId === event.item_id && invocationSourceId === event.invocation_source_id) {
+ return event;
+ }
+
+ return { ...event, invocation_source_id: invocationSourceId, item_id: backendItemId } as T;
+ };
+
const detachers: Array<() => void> = [];
let isAttached = false;
let isDisposed = false;
@@ -354,7 +395,7 @@ export const createQueueCoordinator = (
*/
const isStaleNodeEvent = (nodeEvent: NodeEvent): boolean =>
nodeExecutionItemId !== null &&
- nodeEvent.event.item_id !== nodeExecutionItemId &&
+ getTrackedBackendItemId(nodeEvent.event) !== nodeExecutionItemId &&
nodeEvent.sequence < nodeExecutionItemSequence;
const trackNodeForItem = (backendItemId: number, nodeId: string, sequence: number): void => {
@@ -378,28 +419,32 @@ export const createQueueCoordinator = (
return;
}
- trackNodeForItem(nodeEvent.event.item_id, nodeEvent.event.invocation_source_id, nodeEvent.sequence);
+ const backendItemId = getTrackedBackendItemId(nodeEvent.event);
+ const invocationSourceId = getNodeSourceId(nodeEvent.event);
+
+ trackNodeForItem(backendItemId, invocationSourceId, nodeEvent.sequence);
switch (nodeEvent.kind) {
case 'started': {
- const wait = waits.get(nodeEvent.event.item_id);
+ const routedEvent = routeNodeEvent(nodeEvent.event, backendItemId, invocationSourceId);
+ const wait = waits.get(backendItemId);
if (wait) {
- activeProgressTarget.set(getProgressImageTarget(wait.localQueueItemId, nodeEvent.event.item_id));
+ activeProgressTarget.set(getProgressImageTarget(wait.localQueueItemId, backendItemId));
}
- nodeExecution.started(nodeEvent.event);
+ nodeExecution.started(routedEvent);
return;
}
case 'completed':
- nodeExecution.completed(nodeEvent.event);
+ nodeExecution.completed(routeNodeEvent(nodeEvent.event, backendItemId, invocationSourceId));
return;
case 'failed':
- nodeExecution.failed(nodeEvent.event);
+ nodeExecution.failed(routeNodeEvent(nodeEvent.event, backendItemId, invocationSourceId));
return;
}
};
const bufferNodeEvent = (nodeEvent: NodeEvent): void => {
- const itemId = nodeEvent.event.item_id;
+ const itemId = getTrackedBackendItemId(nodeEvent.event);
const events = pendingNodeEvents.get(itemId) ?? [];
if (events.length >= NODE_EVENT_BUFFER_EVENTS_PER_ITEM) {
@@ -537,7 +582,8 @@ export const createQueueCoordinator = (
}
};
- const isTrackedEvent = (event: { item_id: number }): boolean => waits.has(event.item_id);
+ const isTrackedEvent = (event: { item_id: number; root_item_id?: number | null }): boolean =>
+ waits.has(getTrackedBackendItemId(event));
const trackBackendItem = (localQueueItemId: string, backendItemId: number): Promise<TerminalOutcome> => {
const bufferedOutcome = recentTerminalOutcomes.get(backendItemId);
@@ -688,6 +734,11 @@ export const createQueueCoordinator = (
return;
}
+ // Child status events are not tracked waits, but their preview gate is
+ // still per-child. Release it when the child ends so repeated calls do not
+ // retain one entry forever. The size cap below covers missed terminal events.
+ latestFrameGates.delete(event.item_id);
+
if (!isTrackedEvent(event)) {
bufferTerminalOutcome(event.item_id, toTerminalOutcome(event.status, event.error_message, event.error_type));
return;
@@ -731,7 +782,7 @@ export const createQueueCoordinator = (
return true;
}
- latestFrameGates.set(event.item_id, { revision, sessionId: event.session_id });
+ rememberFrameGate(event.item_id, { revision, sessionId: event.session_id });
return false;
};
@@ -741,7 +792,8 @@ export const createQueueCoordinator = (
return;
}
- const wait = waits.get(event.item_id);
+ const backendItemId = getTrackedBackendItemId(event);
+ const wait = waits.get(backendItemId);
if (!wait) {
return;
@@ -751,10 +803,11 @@ export const createQueueCoordinator = (
return;
}
- trackNodeForItem(event.item_id, event.invocation_source_id, ++nodeEventSequence);
- nodeExecution.progress(event.invocation_source_id, event.percentage, event.message);
+ const invocationSourceId = getNodeSourceId(event);
+ trackNodeForItem(backendItemId, invocationSourceId, ++nodeEventSequence);
+ nodeExecution.progress(invocationSourceId, event.percentage, event.message);
- const target = getProgressImageTarget(wait.localQueueItemId, event.item_id);
+ const target = getProgressImageTarget(wait.localQueueItemId, backendItemId);
activeProgressTarget.set(target);
if (event.image?.dataURL) {
@@ -764,7 +817,7 @@ export const createQueueCoordinator = (
const state = runProgress.get(wait.localQueueItemId);
if (state) {
- state.activeBackendItemId = event.item_id;
+ state.activeBackendItemId = backendItemId;
state.message = event.message;
state.percentage = event.percentage;
publishRunProgress(wait.localQueueItemId);
diff --git a/invokeai/frontend/webv2/src/platform/core/outputImages.ts b/invokeai/frontend/webv2/src/platform/core/outputImages.ts
new file mode 100644
index 0000000000..d213e05af4
--- /dev/null
+++ b/invokeai/frontend/webv2/src/platform/core/outputImages.ts
@@ -0,0 +1,57 @@
+/**
+ * Collect image names from an invocation output, including named values returned by
+ * `workflow_return`. A collection is intentionally flattened: callers that render one
+ * thumbnail use the first name, while queue result routing uses every name.
+ */
+export const getOutputImageNames = (output: unknown): string[] => {
+ const imageNames = new Set<string>();
+
+ const visitImageValue = (value: unknown): void => {
+ if (Array.isArray(value)) {
+ value.forEach(visitImageValue);
+ return;
+ }
+
+ if (!value || typeof value !== 'object') {
+ return;
+ }
+
+ const imageName = (value as { image_name?: unknown }).image_name;
+ if (typeof imageName === 'string') {
+ imageNames.add(imageName);
+ return;
+ }
+
+ if ('image' in value) {
+ visitImageValue(value.image);
+ }
+
+ if ('collection' in value) {
+ visitImageValue(value.collection);
+ }
+
+ // `values` is the only output field whose nested values are all returned
+ // values. Do not walk arbitrary output fields such as `value` or metadata.
+ if ('values' in value) {
+ visitImageValue(value.values);
+ }
+
+ // A workflow return value is a mapping from names to output values. Its
+ // entries need one more explicit descent, without opening unrelated fields.
+ if (!('image' in value) && !('collection' in value) && !('values' in value)) {
+ Object.entries(value)
+ .filter(([key]) => key !== 'output_meta')
+ .forEach(([, nestedValue]) => visitImageValue(nestedValue));
+ }
+ };
+
+ if (output && typeof output === 'object' && !Array.isArray(output)) {
+ const result = output as Record<string, unknown>;
+
+ visitImageValue(result.image);
+ visitImageValue(result.collection);
+ visitImageValue(result.values);
+ }
+
+ return [...imageNames];
+};
diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
index 67a3859501..d9ce639b05 100644
--- a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
@@ -3425,6 +3425,22 @@ describe('workbenchReducer Phase 5 generation flow', () => {
version: '1.0.0',
},
});
+ expect(readSubmission(state)).toMatchObject({
+ workflow: {
+ author: '',
+ contact: '',
+ description: '',
+ edges: [],
+ exposedFields: [],
+ form: { elements: expect.any(Object), rootElementId: expect.any(String) },
+ meta: { category: 'user', version: '3.0.0' },
+ name: 'Untitled Workflow',
+ nodes: [{ id: 'noise-1' }],
+ notes: '',
+ tags: '',
+ version: '1.0.0',
+ },
+ });
expect(readSubmission(state)).not.toHaveProperty('workflow.id');
expect(readSubmission(state)).toMatchObject({ graph: { nodes: { 'noise-1': { seed: 42 } } } });
expect(getActiveProject(state).queue.items[0]?.snapshot.presentation.batchCount).toBe(3);
diff --git a/tests/app/services/session_queue/test_session_queue_workflow_call_metadata.py b/tests/app/services/session_queue/test_session_queue_workflow_call_metadata.py
index edf678f0df..7dd31ffb86 100644
--- a/tests/app/services/session_queue/test_session_queue_workflow_call_metadata.py
+++ b/tests/app/services/session_queue/test_session_queue_workflow_call_metadata.py
@@ -1,11 +1,18 @@
"""Tests for workflow-call relationship metadata on session_queue items."""
import uuid
+from unittest.mock import MagicMock
import pytest
+from PIL import Image
from invokeai.app.invocations.call_saved_workflow import CallSavedWorkflowInvocation
-from invokeai.app.services.events.events_common import QueueItemsRetriedEvent, QueueItemStatusChangedEvent
+from invokeai.app.services.events.events_common import (
+ InvocationStartedEvent,
+ QueueItemsRetriedEvent,
+ QueueItemStatusChangedEvent,
+)
+from invokeai.app.services.image_files.image_files_disk import DiskImageFileStorage
from invokeai.app.services.invoker import Invoker
from invokeai.app.services.session_queue.session_queue_common import (
NodeFieldValue,
@@ -14,6 +21,8 @@ from invokeai.app.services.session_queue.session_queue_common import (
)
from invokeai.app.services.session_queue.session_queue_sqlite import SqliteSessionQueue
from invokeai.app.services.shared.graph import Graph, GraphExecutionState
+from invokeai.app.services.shared.invocation_context import ImagesInterface, InvocationContextData
+from invokeai.app.services.workflow_records.workflow_records_common import WorkflowMeta, WorkflowWithoutID
from tests.test_nodes import TestEventService
@@ -45,6 +54,7 @@ def _insert_queue_item(
parent_session_id: str | None = None,
root_item_id: int | None = None,
workflow_call_depth: int | None = None,
+ workflow: WorkflowWithoutID | None = None,
) -> int:
with session_queue._db.transaction() as cursor:
cursor.execute(
@@ -77,7 +87,7 @@ def _insert_queue_item(
batch_id or str(uuid.uuid4()),
None,
0,
- None,
+ workflow.model_dump_json() if workflow else None,
None,
destination,
None,
@@ -93,6 +103,23 @@ def _insert_queue_item(
return cursor.lastrowid
+def _workflow_without_id() -> WorkflowWithoutID:
+ return WorkflowWithoutID(
+ name="Parent workflow",
+ author="Tester",
+ description="",
+ version="1.0.0",
+ contact="",
+ tags="",
+ notes="",
+ exposedFields=[],
+ meta=WorkflowMeta(version="1.0.0", category="user"),
+ nodes=[],
+ edges=[],
+ form=None,
+ )
+
+
def test_get_queue_item_round_trips_workflow_call_metadata(session_queue: SqliteSessionQueue) -> None:
session = GraphExecutionState(graph=Graph())
session_json = session.model_dump_json(warnings=False)
@@ -191,7 +218,9 @@ def test_status_transition_reuses_loaded_queue_item(
assert updated.status_sequence == 1
-def test_enqueue_workflow_call_child_persists_pending_child_queue_item(session_queue: SqliteSessionQueue) -> None:
+def test_enqueue_workflow_call_child_inherits_workflow_for_image_metadata(
+ session_queue: SqliteSessionQueue, tmp_path
+) -> None:
parent_graph = Graph()
parent_graph.add_node(CallSavedWorkflowInvocation(id="call-node", workflow_id="workflow-a"))
parent_session = GraphExecutionState(graph=parent_graph)
@@ -229,7 +258,7 @@ def test_enqueue_workflow_call_child_persists_pending_child_queue_item(session_q
str(uuid.uuid4()),
None,
0,
- None,
+ _workflow_without_id().model_dump_json(),
None,
None,
None,
@@ -249,6 +278,30 @@ def test_enqueue_workflow_call_child_persists_pending_child_queue_item(session_q
assert child_queue_item.root_item_id == parent_item_id
assert child_queue_item.workflow_call_depth == 1
assert child_queue_item.session_id == child_session.id
+ assert child_queue_item.workflow == _workflow_without_id()
+
+ services = MagicMock()
+ services.configuration.multiuser = False
+ services.configuration.pil_compress_level = 6
+ services.images.create.return_value = MagicMock()
+ images = ImagesInterface(
+ services,
+ InvocationContextData(
+ queue_item=child_queue_item,
+ invocation=MagicMock(is_intermediate=False),
+ source_invocation_id="image-node",
+ ),
+ MagicMock(),
+ )
+ images.save(Image.new("RGB", (4, 4)))
+ workflow_json = services.images.create.call_args.kwargs["workflow"]
+
+ storage = DiskImageFileStorage(tmp_path)
+ storage._DiskImageFileStorage__invoker = services # type: ignore
+ storage.save(image=Image.new("RGB", (4, 4)), image_name="child.png", workflow=workflow_json)
+
+ with Image.open(storage.get_path("child.png")) as saved:
+ assert saved.info["invokeai_workflow"] == workflow_json
def test_enqueue_workflow_call_child_rejects_full_pending_queue(session_queue: SqliteSessionQueue) -> None:
@@ -274,6 +327,54 @@ def test_enqueue_workflow_call_child_rejects_full_pending_queue(session_queue: S
assert session_queue.get_queue_status("default").pending == 1
+def test_enqueue_workflow_call_child_preserves_workflow_through_nested_calls(
+ session_queue: SqliteSessionQueue,
+) -> None:
+ workflow = _workflow_without_id()
+
+ root_graph = Graph()
+ root_graph.add_node(CallSavedWorkflowInvocation(id="root-call", workflow_id="workflow-a"))
+ root_session = GraphExecutionState(graph=root_graph)
+ root_invocation = root_session.next()
+ assert isinstance(root_invocation, CallSavedWorkflowInvocation)
+ root_frame = root_session.build_workflow_call_frame(root_invocation.id, root_invocation.workflow_id)
+
+ child_graph = Graph()
+ child_graph.add_node(CallSavedWorkflowInvocation(id="nested-call", workflow_id="workflow-b"))
+ child_session = root_session.create_child_workflow_execution_state(child_graph, root_frame)
+ root_session.begin_waiting_on_workflow_call(root_frame)
+ root_session.attach_waiting_workflow_call_child_session(child_session)
+ root_item_id = _insert_queue_item(session_queue, session=root_session, status="in_progress", workflow=workflow)
+
+ root_queue_item = session_queue.get_queue_item(root_item_id)
+ child_queue_item = session_queue.enqueue_workflow_call_child(root_queue_item, child_session)
+ nested_invocation = child_session.next()
+ assert isinstance(nested_invocation, CallSavedWorkflowInvocation)
+ nested_frame = child_session.build_workflow_call_frame(nested_invocation.id, nested_invocation.workflow_id)
+ grandchild_graph = Graph()
+ grandchild_graph.add_node(CallSavedWorkflowInvocation(id="leaf-call", workflow_id="workflow-c"))
+ grandchild_session = child_session.create_child_workflow_execution_state(grandchild_graph, nested_frame)
+ child_session.begin_waiting_on_workflow_call(nested_frame)
+ child_session.attach_waiting_workflow_call_child_session(grandchild_session)
+ child_queue_item.session = child_session
+
+ child_event = InvocationStartedEvent.build(child_queue_item, nested_invocation)
+ assert child_event.root_item_id == root_item_id
+ assert child_event.parent_item_id == root_item_id
+ assert child_event.workflow_call_parent_source_id == "root-call"
+
+ grandchild_queue_item = session_queue.enqueue_workflow_call_child(child_queue_item, grandchild_session)
+ grandchild_invocation = grandchild_queue_item.session.next()
+ assert grandchild_invocation is not None
+ grandchild_event = InvocationStartedEvent.build(grandchild_queue_item, grandchild_invocation)
+ assert grandchild_event.root_item_id == root_item_id
+ assert grandchild_event.parent_item_id == child_queue_item.item_id
+ assert grandchild_event.workflow_call_parent_source_id == "root-call"
+
+ assert child_queue_item.workflow == workflow
+ assert grandchild_queue_item.workflow == workflow
+
+
def test_enqueue_workflow_call_child_persists_batch_field_values(session_queue: SqliteSessionQueue) -> None:
parent_graph = Graph()
parent_graph.add_node(CallSavedWorkflowInvocation(id="call-node", workflow_id="workflow-a"))
diff --git a/tests/app/test_progress_preview_replay_socketio.py b/tests/app/test_progress_preview_replay_socketio.py
index c7f858d7c2..b263bfbf9c 100644
--- a/tests/app/test_progress_preview_replay_socketio.py
+++ b/tests/app/test_progress_preview_replay_socketio.py
@@ -9,6 +9,7 @@ from fastapi import FastAPI
from invokeai.app.api.dependencies import ApiDependencies
from invokeai.app.api.sockets import SocketIO
from invokeai.app.services.events.events_common import InvocationProgressEvent
+from invokeai.app.services.progress_previews.progress_previews_common import ProgressPreviewDTO
from invokeai.app.services.progress_previews.progress_previews_default import MemoryProgressPreviews
@@ -33,6 +34,22 @@ def _event(item_id: int, user_id: str, queue_id: str = "default") -> InvocationP
)
+def test_preview_dto_preserves_workflow_call_routing_metadata() -> None:
+ event = _event(2, "owner-1").model_copy(
+ update={
+ "parent_item_id": 1,
+ "root_item_id": 1,
+ "workflow_call_parent_source_id": "call-node",
+ }
+ )
+
+ preview = ProgressPreviewDTO.from_event(event)
+
+ assert preview.parent_item_id == 1
+ assert preview.root_item_id == 1
+ assert preview.workflow_call_parent_source_id == "call-node"
+
+
@pytest.mark.anyio
async def test_subscribe_replays_only_the_users_previews_to_that_socket(monkeypatch) -> None:
previews = MemoryProgressPreviews()