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): pin preview seed for uninitialized generate settings

joshistoastc2d506a57d48
diff --git a/invokeai/frontend/webv2/src/features/generation/core/previewGraph.test.ts b/invokeai/frontend/webv2/src/features/generation/core/previewGraph.test.ts
index 00e2ed43f0..651e322737 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/previewGraph.test.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/previewGraph.test.ts
@@ -111,6 +111,25 @@ describe('compileGeneratePreviewGraph', () => {
expect(result.status).toBe('invalid');
});
+
+ it('pins a deterministic seed across repeated compiles when generate settings are uninitialized', () => {
+ const input = { destination: 'gallery' as const, models, storedValues: undefined, useCpuNoise: false };
+ const first = compileGeneratePreviewGraph(input);
+ const second = compileGeneratePreviewGraph(input);
+
+ expect(first.status).toBe('ready');
+
+ if (first.status !== 'ready' || second.status !== 'ready') {
+ return;
+ }
+
+ expect(first.graph.nodes.map((node) => node.id)).toEqual(second.graph.nodes.map((node) => node.id));
+
+ const firstSeed = first.graph.nodes.find((node) => node.id === 'seed');
+ const secondSeed = second.graph.nodes.find((node) => node.id === 'seed');
+
+ expect(firstSeed?.inputs.value).toBe(secondSeed?.inputs.value);
+ });
});
describe('stabilizeBackendGraphIds', () => {
diff --git a/invokeai/frontend/webv2/src/features/generation/core/previewGraph.ts b/invokeai/frontend/webv2/src/features/generation/core/previewGraph.ts
index c8790bca85..381af006d7 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/previewGraph.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/previewGraph.ts
@@ -4,6 +4,7 @@ import type { GenerateWidgetValues } from './types';
import { getGenerationModelAvailabilityReasons, getGenerationValidationReasons } from './baseGenerationPolicies';
import { compileGenerateGraph } from './graph';
import { resolveGenerateWidgetValues } from './resolveGenerateWidgetValues';
+import { normalizeGenerateSettings } from './settings';
/**
* Preview-only compile: deterministic where the submit path is intentionally
@@ -14,6 +15,12 @@ import { resolveGenerateWidgetValues } from './resolveGenerateWidgetValues';
*/
const NO_SUPPORTED_MODEL = 'Generate needs a supported model before it can be invoked.';
+// `getDefaultGenerateSettings` (the fallback `resolveGenerateWidgetValues` reaches for
+// when `storedValues` doesn't parse — first run, cleared storage, corrupted state) sets
+// `seed: Math.floor(Math.random() * SEED_MAX)`. A stored seed is always kept verbatim;
+// this placeholder only stands in for the synthesized-default case, so the preview is
+// deterministic even before Generate settings have ever been persisted.
+const UNINITIALIZED_SEED_PLACEHOLDER = 0;
export interface GeneratePreviewInput {
destination: ResultDestination;
@@ -89,7 +96,10 @@ export const compileGeneratePreviewGraph = (input: GeneratePreviewInput): Genera
return { reasons: [NO_SUPPORTED_MODEL], status: 'invalid' };
}
- const settings = resolved.values;
+ const storedSettingsParsed = normalizeGenerateSettings(input.storedValues) !== null;
+ const settings = storedSettingsParsed
+ ? resolved.values
+ : { ...resolved.values, seed: UNINITIALIZED_SEED_PLACEHOLDER };
const reasons = [
...getGenerationValidationReasons(settings.model, settings),
...getGenerationModelAvailabilityReasons(settings.model, settings, input.models),