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): keep the template through queue recall and rehydration

joshistoast95061fc4c888
diff --git a/invokeai/frontend/webv2/src/workbench/queue-integration/queueRecall.test.ts b/invokeai/frontend/webv2/src/workbench/queue-integration/queueRecall.test.ts
index 9a3d2386e6..d24e2fc47c 100644
--- a/invokeai/frontend/webv2/src/workbench/queue-integration/queueRecall.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/queue-integration/queueRecall.test.ts
@@ -92,7 +92,7 @@ describe('buildQueueRecallValues', () => {
// Session metadata carries the prompt the model was given, template already
// applied, so recalling it has to stop the active template wrapping it again.
- it('clears the active prompt template when recalling prompts', () => {
+ it('clears the active prompt template when recalling prompts from session meta', () => {
const withTemplate = makeValues({
promptTemplate: { id: 't1', name: 'Cinematic', negativePrompt: '', positivePrompt: '{prompt}, cinematic' },
});
@@ -103,6 +103,23 @@ describe('buildQueueRecallValues', () => {
).toBeNull();
});
+ // A snapshot is the other story: it stores the prompt as *authored*, so the
+ // template that shaped it has to come back too. Recalling `a cat` and dropping
+ // `Cinematic` silently generated something other than the item recalled from.
+ it('recalls the snapshot`s own template alongside its authored prompt', () => {
+ const promptTemplate = { id: 't1', name: 'Cinematic', negativePrompt: '', positivePrompt: '{prompt}, cinematic' };
+ const snapshot = makeValues({ positivePrompt: 'a cat', promptTemplate });
+
+ const result = buildQueueRecallValues('prompts', {
+ current: makeValues(),
+ meta: { positivePrompt: 'a cat, cinematic' },
+ snapshot,
+ });
+
+ expect(result?.positivePrompt).toBe('a cat');
+ expect(result?.promptTemplate).toEqual(promptTemplate);
+ });
+
it('prefers the executed session seed and pins randomization off', () => {
const snapshot = makeValues({ seed: 7, shouldRandomizeSeed: false });
diff --git a/invokeai/frontend/webv2/src/workbench/queue-integration/queueRecall.ts b/invokeai/frontend/webv2/src/workbench/queue-integration/queueRecall.ts
index 3b49596612..9d405e7c66 100644
--- a/invokeai/frontend/webv2/src/workbench/queue-integration/queueRecall.ts
+++ b/invokeai/frontend/webv2/src/workbench/queue-integration/queueRecall.ts
@@ -58,10 +58,16 @@ export const buildQueueRecallValues = (
return {
...current,
positivePrompt,
- // The recalled text already went through whatever template that run used —
- // the session metadata carries the merged prompt outright. Keeping the
- // current template active would wrap it a second time.
- promptTemplate: null,
+ // The two sources disagree about what they hold, so the template has to
+ // follow whichever one the prompt came from. A snapshot stores the text as
+ // authored, alongside the template that shaped it — recalling the text and
+ // dropping the template would quietly generate something else. The session
+ // metadata has no snapshot and carries the merged prompt outright, so
+ // there the current template has to go or it would wrap it a second time.
+ //
+ // Coalesced because queue history is persisted: a snapshot written before
+ // templates existed has no such field, and must not recall `undefined`.
+ promptTemplate: snapshot ? (snapshot.promptTemplate ?? null) : null,
...(negativePrompt !== undefined
? { negativePrompt, negativePromptEnabled: snapshot?.negativePromptEnabled ?? negativePrompt.length > 0 }
: {}),
diff --git a/invokeai/frontend/webv2/src/workbench/queueHistoryNormalization.test.ts b/invokeai/frontend/webv2/src/workbench/queueHistoryNormalization.test.ts
index fea5e5ead4..43b3675191 100644
--- a/invokeai/frontend/webv2/src/workbench/queueHistoryNormalization.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/queueHistoryNormalization.test.ts
@@ -171,6 +171,24 @@ describe('normalizeWorkbenchQueueHistory', () => {
});
});
+ // The queue row is written at submit time from the merged prompt. Rehydrating
+ // from the raw settings made that row change under the user on reload, from
+ // `a cat, cinematic` back to the `a cat` they typed.
+ it('rehydrates a templated item with the prompt that generated', () => {
+ const values = createGenerateValues({
+ positivePrompt: 'a cat',
+ promptTemplate: { id: 't1', name: 'Cinematic', negativePrompt: '', positivePrompt: '{prompt}, cinematic' },
+ });
+ const item = createLegacyItem('generate', {
+ widgetStates: { generate: state('generate', values) },
+ });
+
+ const normalized = normalizeWorkbenchQueueHistory({ items: [item] }, createContext()).items[0]!;
+
+ expect(normalized.snapshot.presentation).toMatchObject({ positivePrompt: 'a cat, cinematic' });
+ expect(normalized.snapshot.backendSubmission).toMatchObject({ positivePrompt: 'a cat, cinematic' });
+ });
+
it('upgrades Canvas items both before and after the captured generate payload was added', () => {
const widgetValues = createGenerateValues({ positivePrompt: 'widget prompt', seed: 10 });
const capturedValues = createGenerateValues({ positivePrompt: 'captured prompt', seed: 99 });
diff --git a/invokeai/frontend/webv2/src/workbench/queueHistoryNormalization.ts b/invokeai/frontend/webv2/src/workbench/queueHistoryNormalization.ts
index 8fb9f7f81d..2d50e74ca8 100644
--- a/invokeai/frontend/webv2/src/workbench/queueHistoryNormalization.ts
+++ b/invokeai/frontend/webv2/src/workbench/queueHistoryNormalization.ts
@@ -221,7 +221,10 @@ const getBackendSubmission = (
const effectivePrompts = getEffectivePrompts(sourceSettings);
return {
- presentationSource: sourceId === 'upscale' ? null : sourceSettings,
+ // The merged source computed above, not the raw settings: the row is written
+ // at submit time from the merged prompt, so returning the authored text here
+ // made a rehydrated item's prompt change under the user on reload.
+ presentationSource: sourceId === 'upscale' ? null : presentationSource,
submission: {
batchCount: sourceSettings.batchCount,
graph: backendGraph,