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(webv2): never route graph-input media as run results

Lincoln Stein2208a3ea807a
diff --git a/invokeai/frontend/webv2/src/features/queue/core/graphInputMedia.test.ts b/invokeai/frontend/webv2/src/features/queue/core/graphInputMedia.test.ts
new file mode 100644
index 0000000000..f17200ca21
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/queue/core/graphInputMedia.test.ts
@@ -0,0 +1,47 @@
+import { describe, expect, it } from 'vitest';
+
+import { collectGraphInputMediaNames } from './graphInputMedia';
+
+describe('collectGraphInputMediaNames', () => {
+ it('collects image and video names from node field values, including nested ones', () => {
+ const graph = {
+ edges: [],
+ id: 'g',
+ nodes: {
+ first_frame: { id: 'first_frame', image: { image_name: 'keyframe.png' }, type: 'image' },
+ ref_collection: {
+ id: 'ref_collection',
+ type: 'image_collection',
+ value: [{ image_name: 'ref-1.png' }, { image_name: 'ref-2.png' }],
+ },
+ source_clip: { id: 'source_clip', type: 'video', video: { video_name: 'input.mp4' } },
+ },
+ };
+
+ const { imageNames, videoNames } = collectGraphInputMediaNames(graph);
+
+ expect([...imageNames].sort()).toEqual(['keyframe.png', 'ref-1.png', 'ref-2.png']);
+ expect([...videoNames]).toEqual(['input.mp4']);
+ });
+
+ it('returns empty sets for malformed or legacy graphs', () => {
+ for (const graph of [undefined, null, 'not-a-graph', 42, {}, { nodes: null }, { nodes: 'oops' }]) {
+ const { imageNames, videoNames } = collectGraphInputMediaNames(graph);
+ expect(imageNames.size).toBe(0);
+ expect(videoNames.size).toBe(0);
+ }
+ });
+
+ it('ignores non-string name values', () => {
+ const graph = {
+ nodes: {
+ weird: { id: 'weird', image: { image_name: 7 }, type: 'image', video: { video_name: null } },
+ },
+ };
+
+ const { imageNames, videoNames } = collectGraphInputMediaNames(graph);
+
+ expect(imageNames.size).toBe(0);
+ expect(videoNames.size).toBe(0);
+ });
+});
diff --git a/invokeai/frontend/webv2/src/features/queue/core/graphInputMedia.ts b/invokeai/frontend/webv2/src/features/queue/core/graphInputMedia.ts
new file mode 100644
index 0000000000..1a9d3225fa
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/queue/core/graphInputMedia.ts
@@ -0,0 +1,61 @@
+/**
+ * Media names referenced by a compiled graph's node field values — the run's INPUTS
+ * (keyframes, source videos, reference images).
+ *
+ * Settlement collects result media by walking every node output in the backend
+ * session. A media primitive node echoes its input into `session.results` under the
+ * same name (e.g. the first-frame keyframe of an image-to-video workflow), so without
+ * this set the runtime would treat the user's source image as a generated result:
+ * board-attach it and record it on every run. Generated outputs are always saved
+ * server-side under fresh names, so a result name that appears in the compiled graph
+ * can only be an input passthrough.
+ */
+
+export interface GraphInputMediaNames {
+ imageNames: ReadonlySet<string>;
+ videoNames: ReadonlySet<string>;
+}
+
+/**
+ * Collect every `image_name` / `video_name` string reachable from the compiled
+ * graph's nodes. `graph` is `unknown` because it comes from persisted snapshots;
+ * anything malformed yields empty sets (previous routing behavior).
+ */
+export const collectGraphInputMediaNames = (graph: unknown): GraphInputMediaNames => {
+ const imageNames = new Set<string>();
+ const videoNames = new Set<string>();
+
+ const visit = (value: unknown): void => {
+ if (Array.isArray(value)) {
+ for (const entry of value) {
+ visit(entry);
+ }
+ return;
+ }
+ if (!value || typeof value !== 'object') {
+ return;
+ }
+
+ const imageName = (value as { image_name?: unknown }).image_name;
+ if (typeof imageName === 'string') {
+ imageNames.add(imageName);
+ }
+ const videoName = (value as { video_name?: unknown }).video_name;
+ if (typeof videoName === 'string') {
+ videoNames.add(videoName);
+ }
+
+ for (const entry of Object.values(value)) {
+ visit(entry);
+ }
+ };
+
+ const nodes = graph && typeof graph === 'object' ? (graph as { nodes?: unknown }).nodes : undefined;
+ if (nodes && typeof nodes === 'object') {
+ for (const node of Object.values(nodes)) {
+ visit(node);
+ }
+ }
+
+ return { imageNames, videoNames };
+};
diff --git a/invokeai/frontend/webv2/src/features/queue/runtime.test.ts b/invokeai/frontend/webv2/src/features/queue/runtime.test.ts
index d53ad60c84..658b5a338b 100644
--- a/invokeai/frontend/webv2/src/features/queue/runtime.test.ts
+++ b/invokeai/frontend/webv2/src/features/queue/runtime.test.ts
@@ -1,5 +1,5 @@
import type { QueueItem } from '@features/queue/core/historyTypes';
-import type { QueueBackendPort } from '@features/queue/core/types';
+import type { QueueBackendInvocation, QueueBackendPort, QueueResultImage } from '@features/queue/core/types';
import { buildQueueItemOrigin } from '@features/queue/data/events';
import { describe, expect, it, vi } from 'vitest';
@@ -144,12 +144,18 @@ describe('queue runtime video board routing', () => {
const createHarness = (options: {
getResultVideoNames: QueueBackendPort['getResultVideoNames'];
galleryBoardId?: string | null;
+ getResultImages?: QueueBackendPort['getResultImages'];
+ /** Nodes of the compiled submission graph — media values here mark run INPUTS. */
+ graphNodes?: Record<string, QueueBackendInvocation>;
}) => {
const queueItem = createPendingQueueItem();
queueItem.snapshot.destination = 'gallery';
queueItem.snapshot.galleryBoardId = options.galleryBoardId === undefined ? 'board-1' : options.galleryBoardId;
queueItem.snapshot.filterIntermediateResults = true;
delete (queueItem.snapshot as { resultNodeIds?: unknown }).resultNodeIds;
+ if (options.graphNodes && queueItem.snapshot.backendSubmission.kind !== 'invalid') {
+ queueItem.snapshot.backendSubmission.graph.nodes = options.graphNodes;
+ }
const project = { id: 'project-1', queue: { items: [queueItem] } };
const backend: QueueBackendPort = {
cancelCurrentItem: vi.fn(),
@@ -163,7 +169,7 @@ describe('queue runtime video board routing', () => {
enqueueGenerate: vi.fn(),
enqueueWorkflow: vi.fn(),
getItem: vi.fn(),
- getResultImages: vi.fn().mockResolvedValue([]),
+ getResultImages: options.getResultImages ?? vi.fn().mockResolvedValue([]),
getResultVideoNames: options.getResultVideoNames,
// The backend already accepted and completed this run before "reload": reconcile
// adopts it and settles immediately, driving both settlement paths without sockets.
@@ -285,4 +291,64 @@ describe('queue runtime video board routing', () => {
runtime.dispose();
});
+
+ const resultImage = (imageName: string): QueueResultImage => ({
+ height: 512,
+ imageName,
+ imageUrl: `http://test/i/${imageName}`,
+ isIntermediate: false,
+ queuedAt: '2026-07-17T00:00:00.000Z',
+ sourceQueueItemId: 'local-queue-item',
+ thumbnailUrl: `http://test/t/${imageName}`,
+ width: 512,
+ });
+
+ it('never routes an input image echoed into the results (first-frame keyframe)', async () => {
+ // The i2v workflow's `image` primitive echoes the uploaded keyframe into
+ // session.results as a non-intermediate output; only the generated image may
+ // reach the board or the recorded results.
+ const { commands, destinations, runtime } = createHarness({
+ getResultImages: vi.fn().mockResolvedValue([resultImage('keyframe.png'), resultImage('generated.png')]),
+ getResultVideoNames: vi.fn().mockResolvedValue([]),
+ graphNodes: {
+ first_frame: { id: 'first_frame', image: { image_name: 'keyframe.png' }, type: 'image' },
+ },
+ });
+
+ runtime.start();
+
+ await vi.waitFor(() => {
+ expect(destinations.addImagesToGalleryBoard).toHaveBeenCalledWith('board-1', ['generated.png']);
+ expect(commands.routeResults).toHaveBeenCalledWith(
+ expect.objectContaining({ images: [expect.objectContaining({ imageName: 'generated.png' })] })
+ );
+ });
+ expect(destinations.addImagesToGalleryBoard).not.toHaveBeenCalledWith(
+ 'board-1',
+ expect.arrayContaining(['keyframe.png'])
+ );
+
+ runtime.dispose();
+ });
+
+ it('never routes an input video echoed into the results (extend-video source clip)', async () => {
+ const { destinations, runtime } = createHarness({
+ getResultVideoNames: vi.fn().mockResolvedValue(['source.mp4', 'extended.mp4']),
+ graphNodes: {
+ source_clip: { id: 'source_clip', type: 'video', video: { video_name: 'source.mp4' } },
+ },
+ });
+
+ runtime.start();
+
+ await vi.waitFor(() => {
+ expect(destinations.addVideosToGalleryBoard).toHaveBeenCalledWith('board-1', ['extended.mp4']);
+ });
+ expect(destinations.addVideosToGalleryBoard).not.toHaveBeenCalledWith(
+ 'board-1',
+ expect.arrayContaining(['source.mp4'])
+ );
+
+ runtime.dispose();
+ });
});
diff --git a/invokeai/frontend/webv2/src/features/queue/runtime.ts b/invokeai/frontend/webv2/src/features/queue/runtime.ts
index 99c3f3baef..09c728fbbb 100644
--- a/invokeai/frontend/webv2/src/features/queue/runtime.ts
+++ b/invokeai/frontend/webv2/src/features/queue/runtime.ts
@@ -8,6 +8,7 @@ import type {
} from '@features/queue/core/types';
import type { BackendConnectionStatus } from '@platform/transport/types';
+import { collectGraphInputMediaNames } from '@features/queue/core/graphInputMedia';
import { isQueuePromptSeedBehaviour } from '@features/queue/core/promptBatch';
import { shouldSubmitPendingQueueItem } from '@features/queue/core/submissionRules';
import {
@@ -75,6 +76,16 @@ export const getQueueItemResultImageOptions = (queueItem: QueueItem): QueueResul
return queueItem.snapshot.resultNodeIds ? { resultNodeIds: queueItem.snapshot.resultNodeIds } : undefined;
};
+/**
+ * The compiled backend graph this item submitted, or undefined for legacy/invalid
+ * snapshots. Used to recognize input passthroughs among collected results — see
+ * `collectGraphInputMediaNames`.
+ */
+const getQueueItemCompiledGraph = (queueItem: QueueItem): unknown => {
+ const submission = (queueItem.snapshot as Partial<QueueItem['snapshot']>).backendSubmission;
+ return submission && typeof submission === 'object' && 'graph' in submission ? submission.graph : undefined;
+};
+
export const createQueueItemBackendSubmission = (
project: Pick<QueueHistoryProject, 'id'>,
queueItem: QueueItem
@@ -249,7 +260,10 @@ export const createQueueRuntime = ({
const namesPerItem = await Promise.all(
deliverableItemIds.map((backendItemId) => backend.getResultVideoNames(backendItemId, options))
);
- const videoNames = [...new Set(namesPerItem.flat())];
+ // A video primitive echoes the run's INPUT video into session.results (e.g. the
+ // source clip of an extend-video workflow) — exclude it like input images.
+ const inputMedia = collectGraphInputMediaNames(getQueueItemCompiledGraph(queueItem));
+ const videoNames = [...new Set(namesPerItem.flat())].filter((name) => !inputMedia.videoNames.has(name));
if (videoNames.length === 0 || !isActive()) {
return;
@@ -268,14 +282,22 @@ export const createQueueRuntime = ({
}
};
- /** Drop intermediates when the item asks for it, then land what remains on its destination. */
+ /**
+ * Drop input passthroughs and (when the item asks) intermediates, then land what
+ * remains on the item's destination. Session results include every node's output,
+ * so a media primitive echoes the run's INPUT image under its original name — e.g.
+ * the first-frame keyframe of an image-to-video workflow — and routing it would
+ * board-attach the user's source image on every run.
+ */
const deliverVisibleImages = async (
queueItem: QueueItem,
allImages: QueueResultImage[]
): Promise<QueueResultImage[]> => {
+ const inputMedia = collectGraphInputMediaNames(getQueueItemCompiledGraph(queueItem));
+ const producedImages = allImages.filter((image) => !inputMedia.imageNames.has(image.imageName));
const images = queueItem.snapshot.filterIntermediateResults
- ? allImages.filter((image) => !image.isIntermediate)
- : allImages;
+ ? producedImages.filter((image) => !image.isIntermediate)
+ : producedImages;
await addImagesToDestination(
queueItem,