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): restore child workflow failure feedback

JPPhoto8623ed114ab0
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.json
index 1556ad4029..0f03f21233 100644
--- a/invokeai/frontend/webv2/public/locales/en.json
+++ b/invokeai/frontend/webv2/public/locales/en.json
@@ -1463,6 +1463,7 @@
"forReturnOwnership": "Each ForReturn must belong to exactly one For",
"executionCompleted": "Completed",
"executionFailed": "Failed",
+ "childWorkflowError": "Child workflow error: {{error}}",
"latestOutput": "Latest output",
"latestOutputImage": "Latest output of this node",
"forLoopBodyBoundary": "For loop body",
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 446aaea8f9..da9bc2f894 100644
--- a/invokeai/frontend/webv2/src/features/nodes/data/nodeExecutionStore.test.ts
+++ b/invokeai/frontend/webv2/src/features/nodes/data/nodeExecutionStore.test.ts
@@ -81,4 +81,15 @@ describe('node execution lifecycle', () => {
expect(nodeExecutionStore.get('other-run')).toBeNull();
});
+
+ it('preserves a failed outcome and error when queue status precedes invocation error', () => {
+ nodeExecutionStore.started({ invocation_source_id: 'node-1' });
+
+ nodeExecutionStore.settleRunning(['node-1'], 'failed', 'Workflow failed');
+
+ expect(nodeExecutionStore.get('node-1')).toMatchObject({
+ error: 'Workflow failed',
+ status: 'failed',
+ });
+ });
});
diff --git a/invokeai/frontend/webv2/src/features/nodes/data/nodeExecutionStore.ts b/invokeai/frontend/webv2/src/features/nodes/data/nodeExecutionStore.ts
index 440d987053..c2b1889763 100644
--- a/invokeai/frontend/webv2/src/features/nodes/data/nodeExecutionStore.ts
+++ b/invokeai/frontend/webv2/src/features/nodes/data/nodeExecutionStore.ts
@@ -89,7 +89,7 @@ export const nodeExecutionStore = {
* The queue item running these nodes reached a terminal state: a node still marked running
* finished with it, or never will (its failure/cancel event was lost or never sent).
*/
- settleRunning(nodeIds: Iterable<string>, outcome: NodeExecutionOutcome): void {
+ settleRunning(nodeIds: Iterable<string>, outcome: NodeExecutionOutcome, error?: string): void {
for (const nodeId of nodeIds) {
const state = stateByNodeId.get(nodeId);
@@ -99,6 +99,14 @@ export const nodeExecutionStore = {
if (outcome === 'completed') {
stateByNodeId.set(nodeId, { ...state, progress: null, progressMessage: null, status: 'completed' });
+ } else if (outcome === 'failed') {
+ stateByNodeId.set(nodeId, {
+ ...state,
+ error: error ?? state.error,
+ progress: null,
+ progressMessage: null,
+ status: 'failed',
+ });
} else {
stateByNodeId.delete(nodeId);
}
@@ -124,7 +132,7 @@ export interface NodeExecutionSink {
failed(event: NodeInvocationErrorEvent): void;
get(nodeId: string): NodeExecutionState | null;
progress(nodeId: string, percentage: number | null, message: string): void;
- settleRunning(nodeIds: Iterable<string>, outcome: NodeExecutionOutcome): void;
+ settleRunning(nodeIds: Iterable<string>, outcome: NodeExecutionOutcome, error?: string): void;
started(event: NodeInvocationStartedEvent): void;
subscribe(nodeId: string, listener: () => void): () => void;
}
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 620c20f52e..39239fbcc8 100644
--- a/invokeai/frontend/webv2/src/features/queue/runtime/coordinator.test.ts
+++ b/invokeai/frontend/webv2/src/features/queue/runtime/coordinator.test.ts
@@ -1244,7 +1244,7 @@ describe('queueCoordinator', () => {
createStatusEvent({ error_message: 'boom', item_id: 1, status: 'failed' })
);
- expect(harness.nodeExecution.settleRunning).toHaveBeenLastCalledWith(new Set(['node-1']), 'failed');
+ expect(harness.nodeExecution.settleRunning).toHaveBeenLastCalledWith(new Set(['node-1']), 'failed', 'boom');
harness.socket.fire('invocation_started', { ...createStatusEvent({ item_id: 2 }), invocation_source_id: 'node-1' });
expect(harness.nodeExecution.clearAll).toHaveBeenCalledTimes(2);
@@ -1253,6 +1253,54 @@ describe('queueCoordinator', () => {
expect(harness.nodeExecution.settleRunning).toHaveBeenLastCalledWith(new Set(['node-1']), 'canceled');
});
+ it('preserves a root failure when queue status precedes the root invocation error', 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: 1 }),
+ invocation_source_id: 'call-node',
+ });
+ harness.socket.fire(
+ 'queue_item_status_changed',
+ createStatusEvent({ error_message: 'Workflow failed', item_id: 1, status: 'failed' })
+ );
+
+ expect(harness.nodeExecution.settleRunning).toHaveBeenLastCalledWith(
+ new Set(['call-node']),
+ 'failed',
+ 'Workflow failed'
+ );
+ });
+
+ it('settles the root node after child activity when the root queue status arrives first', 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: 1 }),
+ invocation_source_id: 'call-node',
+ });
+ 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',
+ });
+ harness.socket.fire(
+ 'queue_item_status_changed',
+ createStatusEvent({ error_message: 'Child workflow failed', item_id: 1, status: 'failed' })
+ );
+
+ expect(harness.nodeExecution.settleRunning).toHaveBeenLastCalledWith(
+ new Set(['call-node']),
+ 'failed',
+ 'Child workflow failed'
+ );
+ });
+
it('ignores untracked queue events before mutating local execution state', () => {
vi.useFakeTimers();
harness = createHarness({ galleryRefreshCoalesceMs: 400 });
diff --git a/invokeai/frontend/webv2/src/features/queue/runtime/coordinator.ts b/invokeai/frontend/webv2/src/features/queue/runtime/coordinator.ts
index 11c90d0105..e19b72ceeb 100644
--- a/invokeai/frontend/webv2/src/features/queue/runtime/coordinator.ts
+++ b/invokeai/frontend/webv2/src/features/queue/runtime/coordinator.ts
@@ -60,7 +60,7 @@ export interface QueueNodeExecutionPort {
completed(event: InvocationCompleteEvent): void;
failed(event: InvocationErrorEvent): void;
progress(nodeId: string, percentage: number | null, message: string): void;
- settleRunning(nodeIds: Iterable<string>, outcome: 'completed' | 'failed' | 'canceled'): void;
+ settleRunning(nodeIds: Iterable<string>, outcome: 'completed' | 'failed' | 'canceled', error?: string): void;
started(event: InvocationStartedEvent): void;
}
@@ -254,9 +254,9 @@ export const createQueueCoordinator = (
const pendingProgressEvents = new Map<number, InvocationProgressEvent>();
/** Nodes each backend item has driven; settled with the item's terminal outcome. */
const nodeIdsByBackendItem = new Map<number, Set<string>>();
- /** The backend item whose node events the execution store currently reflects, and the receipt sequence it took over at. */
- let nodeExecutionItemId: number | null = null;
- let nodeExecutionItemSequence = 0;
+ /** The root backend item whose node events the execution store currently reflects. */
+ let nodeExecutionRootItemId: number | null = null;
+ let nodeExecutionRootItemSequence = 0;
let nodeEventSequence = 0;
/** Enqueue requests awaiting a response; early node events and previews are buffered while one is in flight. */
let inFlightSubmissions = 0;
@@ -360,14 +360,18 @@ export const createQueueCoordinator = (
return { itemIndex: itemIndex === -1 ? 1 : itemIndex + 1, queueItemId: localQueueItemId };
};
- const settleNodes = (backendItemId: number, outcome: TerminalOutcome['status']): void => {
+ const settleNodes = (backendItemId: number, outcome: TerminalOutcome): void => {
const nodeIds = nodeIdsByBackendItem.get(backendItemId);
nodeIdsByBackendItem.delete(backendItemId);
// A late settle for an item the store no longer reflects must not touch the current run's nodes.
- if (nodeIds && isActive() && nodeExecutionItemId === backendItemId) {
- nodeExecution.settleRunning(nodeIds, outcome);
+ if (nodeIds && isActive() && nodeExecutionRootItemId === backendItemId) {
+ if (outcome.status === 'failed') {
+ nodeExecution.settleRunning(nodeIds, outcome.status, outcome.error);
+ } else {
+ nodeExecution.settleRunning(nodeIds, outcome.status);
+ }
}
};
@@ -376,14 +380,14 @@ export const createQueueCoordinator = (
* in any order, so only a replayed event from before the current item's takeover is a straggler.
*/
const isStaleNodeEvent = (nodeEvent: NodeEvent): boolean =>
- nodeExecutionItemId !== null &&
- getTrackedBackendItemId(nodeEvent.event) !== nodeExecutionItemId &&
- nodeEvent.sequence < nodeExecutionItemSequence;
+ nodeExecutionRootItemId !== null &&
+ getTrackedBackendItemId(nodeEvent.event) !== nodeExecutionRootItemId &&
+ nodeEvent.sequence < nodeExecutionRootItemSequence;
const trackNodeForItem = (backendItemId: number, nodeId: string, sequence: number): void => {
- if (nodeExecutionItemId !== backendItemId) {
- nodeExecutionItemId = backendItemId;
- nodeExecutionItemSequence = sequence;
+ if (nodeExecutionRootItemId !== backendItemId) {
+ nodeExecutionRootItemId = backendItemId;
+ nodeExecutionRootItemSequence = sequence;
nodeExecution.clearAll();
}
@@ -523,7 +527,7 @@ export const createQueueCoordinator = (
wait.frameGates.clear();
waits.delete(backendItemId);
- settleNodes(backendItemId, outcome.status);
+ settleNodes(backendItemId, outcome);
const progressTarget = getProgressImageTarget(wait.localQueueItemId, backendItemId);
const releaseProgressSlot = (): void => {
if (isActive()) {
@@ -603,7 +607,7 @@ export const createQueueCoordinator = (
replayNodeEvents(backendItemId);
recentTerminalOutcomes.delete(backendItemId);
pendingProgressEvents.delete(backendItemId);
- settleNodes(backendItemId, bufferedOutcome.status);
+ settleNodes(backendItemId, bufferedOutcome);
return Promise.resolve(bufferedOutcome);
}
@@ -880,8 +884,8 @@ export const createQueueCoordinator = (
progress.clearAll?.();
nodeExecution.clearAll();
- nodeExecutionItemId = null;
- nodeExecutionItemSequence = 0;
+ nodeExecutionRootItemId = null;
+ nodeExecutionRootItemSequence = 0;
pendingNodeEvents.clear();
// Keep previews received before enqueue adoption; the HTTP response may still be in flight.
nodeIdsByBackendItem.clear();
@@ -1215,7 +1219,7 @@ export const createQueueCoordinator = (
if (wait?.localQueueItemId === localQueueItemId) {
waits.delete(backendItemId);
wait.frameGates.clear();
- settleNodes(backendItemId, 'canceled');
+ settleNodes(backendItemId, { status: 'canceled' });
wait.settle({ status: 'canceled' });
}
}
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/editor/InvocationFlowNode.browser.test.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/editor/InvocationFlowNode.browser.test.tsx
index d675b82422..d242909d59 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/editor/InvocationFlowNode.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/editor/InvocationFlowNode.browser.test.tsx
@@ -12,7 +12,7 @@ import { ReactFlow } from '@xyflow/react';
import { act } from 'react';
import { createRoot, type Root } from 'react-dom/client';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
-import { page } from 'vitest/browser';
+import { page, userEvent } from 'vitest/browser';
import { toFlowEdges, toFlowNodes } from './flowAdapters';
import { InvocationFlowNode } from './InvocationFlowNode';
@@ -23,8 +23,14 @@ import '@xyflow/react/dist/style.css';
vi.mock('react-i18next', () => ({
useTranslation: () => ({
- t: (key: string) =>
- ({ 'nodes.latestOutput': 'Latest output', 'nodes.latestOutputImage': 'Latest output of this node' })[key] ?? key,
+ t: (key: string, options?: { error?: string }) =>
+ ({
+ 'nodes.childWorkflowError': `Child workflow error: ${options?.error ?? ''}`,
+ 'nodes.executionFailed': 'Failed',
+ 'nodes.executionCompleted': 'Completed',
+ 'nodes.latestOutput': 'Latest output',
+ 'nodes.latestOutputImage': 'Latest output of this node',
+ })[key] ?? key,
}),
}));
@@ -100,6 +106,23 @@ const templates = { preview: template };
const flowNodes = toFlowNodes(projectGraph, [], templates);
const nodeTypes = { invocation: InvocationFlowNode };
+const callNodeId = 'call-node';
+const callNode: WorkflowInvocationNode = {
+ ...documentNode,
+ data: { ...documentNode.data, type: 'call_saved_workflow' },
+ id: callNodeId,
+};
+const callTemplate: InvocationTemplate = {
+ ...template,
+ inputs: {},
+ outputType: 'workflow_return_output',
+ outputs: {},
+ title: 'Call Saved Workflow',
+ type: 'call_saved_workflow',
+};
+const callProjectGraph: ProjectGraphState = { ...createProjectGraph('call-test'), nodes: [callNode] };
+const callFlowNodes = toFlowNodes(callProjectGraph, [], { call_saved_workflow: callTemplate });
+
const outputImage = (width: number, height: number): string => {
const canvas = document.createElement('canvas');
canvas.width = width;
@@ -120,13 +143,13 @@ const completed = (outputImageUrl: string): WorkflowNodeExecutionState => ({
});
/** A node-execution port the test can advance between renders. */
-const createExecutionPort = () => {
+const createExecutionPort = (nodeId = NODE_ID) => {
const listeners = new Set<() => void>();
let state: WorkflowNodeExecutionState | null = null;
return {
port: {
- get: (nodeId: string) => (nodeId === NODE_ID ? state : null),
+ get: (requestedNodeId: string) => (requestedNodeId === nodeId ? state : null),
subscribe: (_nodeId: string, listener: () => void) => {
listeners.add(listener);
return () => listeners.delete(listener);
@@ -270,6 +293,58 @@ describe('InvocationFlowNode output preview', () => {
});
});
+describe('InvocationFlowNode failure outcome', () => {
+ let host: HTMLDivElement;
+ let root: Root;
+
+ beforeEach(() => {
+ host = document.createElement('div');
+ host.style.cssText = 'width: 480px; height: 520px;';
+ document.body.append(host);
+ root = createRoot(host);
+ });
+
+ afterEach(async () => {
+ await act(() => root.unmount());
+ host.remove();
+ });
+
+ it('shows translated child-workflow attribution in the failure tooltip', async () => {
+ const execution = createExecutionPort(callNodeId);
+ execution.set({
+ error: 'Child node failed',
+ latestOutput: null,
+ outputImageUrl: null,
+ progress: null,
+ progressMessage: null,
+ status: 'failed',
+ });
+
+ await act(() =>
+ root.render(
+ <ChakraProvider value={system}>
+ <WorkflowUiProvider adapter={createAdapter(execution.port)}>
+ <ReactFlow defaultViewport={{ x: 0, y: 0, zoom: 1 }} nodes={callFlowNodes} nodeTypes={nodeTypes} />
+ </WorkflowUiProvider>
+ </ChakraProvider>
+ )
+ );
+
+ const failureIcon = await vi.waitFor(() => {
+ const icon = host.querySelector<HTMLElement>('[aria-label="Failed"]');
+ expect(icon).not.toBeNull();
+ return icon!;
+ });
+
+ await act(() => userEvent.hover(failureIcon));
+ await vi.waitFor(() =>
+ expect(document.querySelector('[data-part="content"]')?.textContent).toContain(
+ 'Child workflow error: Child node failed'
+ )
+ );
+ });
+});
+
describe('InvocationFlowNode edge stacking', () => {
let host: HTMLDivElement;
let root: Root;
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/editor/InvocationFlowNode.test.ts b/invokeai/frontend/webv2/src/features/workflow/ui/editor/InvocationFlowNode.test.ts
index 8ef45a8b4d..2ec5253a73 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/editor/InvocationFlowNode.test.ts
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/editor/InvocationFlowNode.test.ts
@@ -3,6 +3,7 @@ import type { WorkflowInvocationNode } from '@features/workflow/contracts';
import { describe, expect, it } from 'vitest';
import {
+ getNodeExecutionError,
shouldShowCallSavedWorkflowLoadingHint,
shouldShowCallSavedWorkflowNoExposedFieldsHint,
} from './InvocationFlowNode';
@@ -42,3 +43,17 @@ describe('shouldShowCallSavedWorkflowNoExposedFieldsHint', () => {
).toBe(false);
});
});
+
+describe('getNodeExecutionError', () => {
+ const translate = (key: string, options: { error: string }) => `${key}: ${options.error}`;
+
+ it('attributes call saved workflow failures while preserving ordinary invocation errors', () => {
+ const execution = { error: 'Child node failed' };
+
+ expect(getNodeExecutionError(node('call_saved_workflow'), execution.error, translate)).toBe(
+ 'nodes.childWorkflowError: Child node failed'
+ );
+ expect(getNodeExecutionError(node('other'), execution.error, translate)).toBe('Child node failed');
+ expect(getNodeExecutionError(node('call_saved_workflow'), null, translate)).toBeNull();
+ });
+});
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/editor/InvocationFlowNode.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/editor/InvocationFlowNode.tsx
index 92437259b4..6d27187094 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/editor/InvocationFlowNode.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/editor/InvocationFlowNode.tsx
@@ -106,6 +106,18 @@ const hasMissingRequiredInputs = (
const getExecutionOutcome = (execution: NodeExecutionState | null): WorkflowNodeOutcome | null =>
execution?.status === 'completed' || execution?.status === 'failed' ? execution.status : null;
+export const getNodeExecutionError = (
+ node: WorkflowInvocationNode,
+ error: string | null | undefined,
+ translate: (key: string, options: { error: string }) => string
+): string | null | undefined => {
+ if (!error || node.data.type !== 'call_saved_workflow') {
+ return error;
+ }
+
+ return translate('nodes.childWorkflowError', { error });
+};
+
const NodeShell = ({
hasMissingRequiredInput,
children,
@@ -131,7 +143,13 @@ const NodeShell = ({
};
/** The header's completed/failed mark, named for screen readers and tooltipped with the failure. */
-const NodeOutcomeIcon = ({ execution }: { execution: NodeExecutionState | null }) => {
+const NodeOutcomeIcon = ({
+ execution,
+ node,
+}: {
+ execution: NodeExecutionState | null;
+ node: WorkflowInvocationNode;
+}) => {
const { t } = useTranslation();
const outcome = getExecutionOutcome(execution);
@@ -141,7 +159,7 @@ const NodeOutcomeIcon = ({ execution }: { execution: NodeExecutionState | null }
return (
<WorkflowNodeOutcomeIcon
- error={execution?.error}
+ error={getNodeExecutionError(node, execution?.error, t)}
label={outcome === 'completed' ? t('nodes.executionCompleted') : t('nodes.executionFailed')}
outcome={outcome}
/>
@@ -765,7 +783,7 @@ const CompactInvocationNode = ({ data, selected }: NodeProps<InvocationFlowNodeT
<Flex {...getWorkflowNodeHeaderProps()}>
<MiddleTruncate fontSize="sm" fontWeight="700" minW="0" text={title} />
<Box flex="1" />
- <NodeOutcomeIcon execution={execution} />
+ <NodeOutcomeIcon execution={execution} node={node} />
</Flex>
{templateView ? (
<CompactNodeBody inputCount={inputTemplates.length} outputCount={outputTemplates.length} />
@@ -847,7 +865,7 @@ const ExpandedInvocationNode = ({ data, selected }: NodeProps<InvocationFlowNode
<>
<NodeTitle node={node} title={node.data.label || template.title} />
<Box flex="1" />
- <NodeOutcomeIcon execution={execution} />
+ <NodeOutcomeIcon execution={execution} node={node} />
<NodeInfoIcon node={node} template={template} />
</>
)}
diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
index 6ee351bce6..d74a586267 100644
--- a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
@@ -3425,22 +3425,6 @@ 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);