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.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
fix(webv2): replay pre-seed-mode queue items with the expansion they were planned with
Josh Corbett3446c76ee3fc
diff --git a/invokeai/frontend/webv2/src/features/queue/core/promptBatch.ts b/invokeai/frontend/webv2/src/features/queue/core/promptBatch.tsindex f3f29b9399..d334ae33c1 100644--- a/invokeai/frontend/webv2/src/features/queue/core/promptBatch.ts+++ b/invokeai/frontend/webv2/src/features/queue/core/promptBatch.ts@@ -141,6 +141,69 @@ export interface GeneratePromptBatchPlan {expectedImageCount: number;}+/** The pre-seed-mode sequence: consecutive from `start`, wrapping one short of the inclusive range. */+const generateLegacySeedSequence = (start: number, count: number): number[] =>+ Array.from({ length: sanitizeBatchCount(count) }, (_, index) => (start + index) % SEED_MAX);++/**+ * The expansion items queued before seed modes were planned with, reproduced so+ * recovery replays them as recorded. Those items knew only a random toggle,+ * which the runtime maps to a step of 1 or 0: the toggle decided whether one+ * prompt (or per-iteration prompts) stepped or held, while several prompts with+ * sharing disabled always stepped per image, and the sequence wrapped at+ * `SEED_MAX` exclusive. New submissions never take this path.+ */+export const buildLegacyGeneratePromptBatchPlan = ({+ batchCount,+ negativePrompt,+ negativePromptNodeId,+ positivePromptNodeId,+ prompts,+ seed,+ seedBehaviour,+ seedNodeId,+ seedStep,+}: GeneratePromptBatchPlanInput): GeneratePromptBatchPlan => {+ const shouldRandomizeSeed = seedStep !== 0;+ const iterations = sanitizeBatchCount(batchCount);+ const promptList = prompts.length > 0 ? [...prompts] : [''];+ const promptDatum = (items: string[]): GeneratePromptBatchDatum[] => [+ { field_name: 'value', items, node_path: positivePromptNodeId },+ { field_name: 'value', items: items.map(() => negativePrompt), node_path: negativePromptNodeId },+ ];++ if (promptList.length === 1) {+ const seeds = shouldRandomizeSeed ? generateLegacySeedSequence(seed, iterations) : [seed];++ return {+ data: [+ [{ field_name: 'value', items: seeds, node_path: seedNodeId }, ...promptDatum(seeds.map(() => promptList[0]))],+ ],+ expectedImageCount: iterations,+ runs: shouldRandomizeSeed ? 1 : iterations,+ };+ }++ if (seedBehaviour === 'per-image') {+ const seeds = generateLegacySeedSequence(seed, promptList.length * iterations);+ const repeatedPrompts = Array.from({ length: iterations }, () => promptList).flat();++ return {+ data: [[{ field_name: 'value', items: seeds, node_path: seedNodeId }, ...promptDatum(repeatedPrompts)]],+ expectedImageCount: seeds.length,+ runs: 1,+ };+ }++ const seeds = shouldRandomizeSeed ? generateLegacySeedSequence(seed, iterations) : [seed];++ return {+ data: [[{ field_name: 'value', items: seeds, node_path: seedNodeId }], promptDatum(promptList)],+ expectedImageCount: promptList.length * iterations,+ runs: shouldRandomizeSeed ? 1 : iterations,+ };+};+/*** With a single prompt this reproduces the pre-dynamic-prompts payload exactly,* which `promptBatch.test.ts` pins:diff --git a/invokeai/frontend/webv2/src/features/queue/core/types.ts b/invokeai/frontend/webv2/src/features/queue/core/types.tsindex 5f0b68c139..8096d9705c 100644--- a/invokeai/frontend/webv2/src/features/queue/core/types.ts+++ b/invokeai/frontend/webv2/src/features/queue/core/types.ts@@ -61,6 +61,11 @@ export interface QueueEnqueueGenerateRequest extends QueueEnqueueRequestBase {seedBehaviour?: QueuePromptSeedBehaviour;seedNodeId: string;seedStep: QueueSeedStep;+ /**+ * Set only when replaying an item queued before seed modes: its `seedStep` is+ * the mapped random toggle, and the expansion follows that version's rules.+ */+ legacySeedPlan?: true;}export interface QueueEnqueueResult {diff --git a/invokeai/frontend/webv2/src/features/queue/data/submissionApi.test.ts b/invokeai/frontend/webv2/src/features/queue/data/submissionApi.test.tsindex fe0ab0c7d2..860821b3c3 100644--- a/invokeai/frontend/webv2/src/features/queue/data/submissionApi.test.ts+++ b/invokeai/frontend/webv2/src/features/queue/data/submissionApi.test.ts@@ -234,6 +234,65 @@ describe('enqueueGenerate', () => {});});+describe('enqueueGenerate legacy replays', () => {+ beforeEach(() => {+ mocks.apiFetchJson.mockReset();+ mocks.apiFetchJson.mockResolvedValue({+ batch: { batch_id: 'batch-1' },+ enqueued: 1,+ item_ids: [1],+ requested: 1,+ });+ });++ it('replays a pinned two-prompt per-image batch with the seeds that version stepped', async () => {+ const { enqueueGenerate } = await import('./submissionApi');++ await enqueueGenerate(+ createRequest({+ batchCount: 2,+ legacySeedPlan: true,+ positivePrompts: ['a', 'b'],+ seed: 42,+ seedBehaviour: 'per-image',+ seedStep: 0,+ })+ );++ // Before seed modes, sharing disabled always stepped, toggle or not: one zipped group+ // with a seed per image and the prompt list repeated per iteration.+ expect(getSubmittedBody().batch.data).toEqual([+ [+ { field_name: 'value', items: [42, 43, 44, 45], node_path: 'seed' },+ { field_name: 'value', items: ['a', 'b', 'a', 'b'], node_path: 'positive_prompt' },+ {+ field_name: 'value',+ items: ['low quality', 'low quality', 'low quality', 'low quality'],+ node_path: 'negative_prompt',+ },+ ],+ ]);+ expect(getSubmittedBody().batch.runs).toBe(1);+ });++ it('wraps a legacy sequence one short of the range, as that version did', async () => {+ const { enqueueGenerate } = await import('./submissionApi');++ await enqueueGenerate(createRequest({ batchCount: 2, legacySeedPlan: true, seed: 4_294_967_294, seedStep: 1 }));++ expect(getSubmittedBody().batch.data[0]?.[0]?.items).toEqual([4_294_967_294, 0]);+ });++ it('holds a pinned single-prompt batch across its runs', async () => {+ const { enqueueGenerate } = await import('./submissionApi');++ await enqueueGenerate(createRequest({ batchCount: 3, legacySeedPlan: true, seed: 42, seedStep: 0 }));++ expect(getSubmittedBody().batch.data[0]?.[0]?.items).toEqual([42]);+ expect(getSubmittedBody().batch.runs).toBe(3);+ });+});+describe('enqueueWorkflow', () => {beforeEach(() => {mocks.apiFetchJson.mockReset();diff --git a/invokeai/frontend/webv2/src/features/queue/data/submissionApi.ts b/invokeai/frontend/webv2/src/features/queue/data/submissionApi.tsindex c962227745..da840c1574 100644--- a/invokeai/frontend/webv2/src/features/queue/data/submissionApi.ts+++ b/invokeai/frontend/webv2/src/features/queue/data/submissionApi.ts@@ -9,6 +9,7 @@ import type {import {buildGeneratePromptBatchPlan,+ buildLegacyGeneratePromptBatchPlan,buildWorkflowSeedBatchPlan,sanitizeBatchCount,} from '@features/queue/core/promptBatch';@@ -75,7 +76,7 @@ const mapEnqueueResult = (value: unknown, isReceipt = false): QueueEnqueueResult};export const enqueueGenerate = async (request: QueueEnqueueGenerateRequest): Promise<QueueEnqueueResult> => {- const plan = buildGeneratePromptBatchPlan({+ const planInput = {batchCount: sanitizeBatchCount(request.batchCount),negativePrompt: request.negativePrompt,negativePromptNodeId: request.negativePromptNodeId,@@ -84,6 +85,9 @@ export const enqueueGenerate = async (request: QueueEnqueueGenerateRequest): Proseed: request.seed,seedBehaviour: request.seedBehaviour ?? 'per-iteration',seedNodeId: request.seedNodeId,+ };+ const plan = (request.legacySeedPlan ? buildLegacyGeneratePromptBatchPlan : buildGeneratePromptBatchPlan)({+ ...planInput,seedStep: request.seedStep,});const result = await apiFetchJson<unknown>('/api/v1/queue/default/enqueue_batch', {diff --git a/invokeai/frontend/webv2/src/features/queue/runtime.test.ts b/invokeai/frontend/webv2/src/features/queue/runtime.test.tsindex 88bee15191..2800e6e5ca 100644--- a/invokeai/frontend/webv2/src/features/queue/runtime.test.ts+++ b/invokeai/frontend/webv2/src/features/queue/runtime.test.ts@@ -137,12 +137,23 @@ describe('queue runtime', () => {expect(createQueueItemBackendSubmission({ id: 'project-1' }, asLegacy(true))).toMatchObject({kind: 'generate',- request: { seedStep: 1 },+ request: { legacySeedPlan: true, seedStep: 1 },});expect(createQueueItemBackendSubmission({ id: 'project-1' }, asLegacy(false))).toMatchObject({kind: 'generate',- request: { seedStep: 0 },+ request: { legacySeedPlan: true, seedStep: 0 },});+ // An item that already carries a step never takes the legacy expansion, even if a+ // stale toggle rides along beside it.+ const withBoth = createPendingQueueItem();+ (withBoth.snapshot.backendSubmission as Record<string, unknown>).shouldRandomizeSeed = true;++ for (const queueItem of [createPendingQueueItem(), withBoth]) {+ const { request } = createQueueItemBackendSubmission({ id: 'project-1' }, queueItem) as { request: object };++ expect(request).not.toHaveProperty('legacySeedPlan');+ expect(request).toMatchObject({ seedStep: 0 });+ }expect((createQueueItemBackendSubmission({ id: 'project-1' }, asLegacy(false)) as { request: object }).request).not.toHaveProperty('shouldRandomizeSeed');diff --git a/invokeai/frontend/webv2/src/features/queue/runtime.ts b/invokeai/frontend/webv2/src/features/queue/runtime.tsindex bb9fc376e7..32ee5f3bd4 100644--- a/invokeai/frontend/webv2/src/features/queue/runtime.ts+++ b/invokeai/frontend/webv2/src/features/queue/runtime.ts@@ -125,8 +125,8 @@ const getQueueItemCompiledGraph = (queueItem: QueueItem): unknown => {/*** Items queued before seed modes recorded the random toggle instead of a step;- * a randomized batch ran consecutive seeds and a pinned one held its seed, so- * recovery replays them exactly as they were planned.+ * the mapped step plus `legacySeedPlan` lets the send path expand them with that+ * version's rules, so recovery replays the seeds exactly as they were planned.*/const readSubmissionSeedStep = (submission: { seedStep?: unknown; shouldRandomizeSeed?: unknown }) =>isQueueSeedStep(submission.seedStep)@@ -219,6 +219,7 @@ export const createQueueItemBackendSubmission = (request: {...compiled,destination: queueItem.snapshot.destination,+ ...(isQueueSeedStep(submission.seedStep) ? {} : { legacySeedPlan: true as const }),projectId: project.id,seedStep,sourceQueueItemId: queueItem.id,