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): scan only well-formed batch datums for input media

Josh Corbett7015f9f9172d
diff --git a/invokeai/frontend/webv2/src/features/queue/core/graphInputMedia.test.ts b/invokeai/frontend/webv2/src/features/queue/core/graphInputMedia.test.ts
index 3bb10e3483..ad4b00c675 100644
--- a/invokeai/frontend/webv2/src/features/queue/core/graphInputMedia.test.ts
+++ b/invokeai/frontend/webv2/src/features/queue/core/graphInputMedia.test.ts
@@ -58,6 +58,18 @@ describe('collectSubmissionInputMediaNames', () => {
{ batchData: null, graph: { nodes: {} } },
{ batchData: 'oops', graph: { nodes: {} } },
{ batchData: [null, 7, [null, 'datum']], graph: { nodes: {} } },
+ // Media-bearing values outside the persisted batch datum shape.
+ { batchData: [{ image_name: 'flat.png' }], graph: { nodes: {} } },
+ { batchData: [[{ image_name: 'loose.png' }]], graph: { nodes: {} } },
+ {
+ batchData: [[{ field_name: 'image', items: [{ image_name: 'wire.png' }], node_path: 'n' }]],
+ graph: { nodes: {} },
+ },
+ {
+ batchData: [[{ fieldName: 'image', items: [{ image_name: 'a.png' }, null], nodeId: 'n' }]],
+ graph: { nodes: {} },
+ },
+ { batchData: [[{ fieldName: 'video', items: [{ video_name: 'clip.mp4' }], nodeId: 'n' }]], graph: { nodes: {} } },
]) {
const { imageNames, videoNames } = collectSubmissionInputMediaNames(submission);
expect(imageNames.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
index 407eb97c72..c13ee467a2 100644
--- a/invokeai/frontend/webv2/src/features/queue/core/graphInputMedia.ts
+++ b/invokeai/frontend/webv2/src/features/queue/core/graphInputMedia.ts
@@ -4,14 +4,17 @@
* which the backend substitutes into nodes per session.
*/
+import { isQueueWorkflowBatchDatum } from './promptBatch';
+
export interface SubmissionInputMediaNames {
imageNames: ReadonlySet<string>;
videoNames: ReadonlySet<string>;
}
/**
- * Collect image_name/video_name strings from a compiled submission's graph nodes and batch data. Malformed or legacy
- * persisted submissions yield empty sets.
+ * Collect image_name/video_name strings from a compiled submission's graph nodes and the image items of its well-formed
+ * batch datums. Malformed or legacy persisted submissions, and malformed batch datums, yield no names: restored
+ * snapshots are not validated, and a stray name must not filter out a real result.
*/
export const collectSubmissionInputMediaNames = (submission: unknown): SubmissionInputMediaNames => {
const imageNames = new Set<string>();
@@ -54,7 +57,21 @@ export const collectSubmissionInputMediaNames = (submission: unknown): Submissio
}
}
if (Array.isArray(batchData)) {
- visit(batchData);
+ for (const group of batchData) {
+ if (!Array.isArray(group)) {
+ continue;
+ }
+ for (const datum of group) {
+ if (!isQueueWorkflowBatchDatum(datum)) {
+ continue;
+ }
+ for (const item of datum.items) {
+ if (typeof item === 'object') {
+ imageNames.add(item.image_name);
+ }
+ }
+ }
+ }
}
return { imageNames, videoNames };