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): fail closed on every recall path while capabilities are absent

Josh Corbett32c19704a99f
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.json
index 8f3e3f457c..dac671563f 100644
--- a/invokeai/frontend/webv2/public/locales/en.json
+++ b/invokeai/frontend/webv2/public/locales/en.json
@@ -1976,6 +1976,8 @@
"advanced": "Advanced",
"aspectRatio": "Aspect ratio",
"capabilitiesLoadFailed": "Could not load model capabilities from the backend.",
+ "capabilitiesUnavailableForRecall": "Model capabilities are not loaded, so settings that depend on the model cannot be applied yet. Prompts and seed can. If loading failed, retry from the Generate panel.",
+ "capabilitiesUnavailableForSetup": "Model capabilities are not loaded, so this project cannot be set up for Generate yet. If loading failed, retry from the Generate panel.",
"cfgRescale": "CFG rescale",
"chooseModelToStart": "Choose a model to start",
"clearPromptTemplate": "Stop using this template",
@@ -2200,6 +2202,7 @@
"savePresetAction": "Save",
"savePresetTitle": "Save preset",
"scaleBeforeProcessing": "Scale before processing",
+ "selectSupportedModelFirst": "Select a supported Generate model first.",
"scalingOptions": {
"height": "Height",
"method": "Scale method",
@@ -2594,6 +2597,7 @@
"recallAll": "Recall All",
"recallFromGallery": "Recall this generation from the gallery",
"recallUnavailable": "Nothing recallable for this item — select a supported Generate model first.",
+ "recallUnavailableCapabilities": "Nothing recallable yet — model capabilities have not loaded. If loading failed, retry from the Generate panel.",
"recallUnavailableForItem": "Nothing recallable for this item.",
"resumeProcessor": "Resume Processor",
"sendToCanvas": "Send to canvas",
diff --git a/invokeai/frontend/webv2/src/app/RecallParametersRuntime.tsx b/invokeai/frontend/webv2/src/app/RecallParametersRuntime.tsx
index ec3500edf6..7c1e3d23df 100644
--- a/invokeai/frontend/webv2/src/app/RecallParametersRuntime.tsx
+++ b/invokeai/frontend/webv2/src/app/RecallParametersRuntime.tsx
@@ -3,6 +3,7 @@ import { useMountEffect } from '@platform/react/useMountEffect';
import { socketHub } from '@platform/transport/socketHub';
import { attachRecallParametersRuntime } from '@workbench/image-actions/recallParametersBridge';
import { useWorkbenchInternalStore } from '@workbench/WorkbenchContext';
+import { useTranslation } from 'react-i18next';
/** Single-user servers tag events with a system user id, so only multi-user sessions can be fenced. */
const getSessionUserId = (): string | null => {
@@ -13,6 +14,8 @@ const getSessionUserId = (): string | null => {
/** App-owned composition: external `POST /api/v1/recall` updates land in the active project's Generate panel. */
export const RecallParametersRuntime = () => {
const store = useWorkbenchInternalStore();
+ // Captured once at mount; i18next resolves it against the current language at each call.
+ const { t } = useTranslation();
useMountEffect(
() =>
@@ -21,6 +24,7 @@ export const RecallParametersRuntime = () => {
getSessionUserId,
hub: socketHub,
queries: store.queries,
+ t,
}).dispose
);
diff --git a/invokeai/frontend/webv2/src/workbench/hotkeys/firstPartyCommands.ts b/invokeai/frontend/webv2/src/workbench/hotkeys/firstPartyCommands.ts
index 421ab4f9cf..96b9309c93 100644
--- a/invokeai/frontend/webv2/src/workbench/hotkeys/firstPartyCommands.ts
+++ b/invokeai/frontend/webv2/src/workbench/hotkeys/firstPartyCommands.ts
@@ -29,6 +29,7 @@ import { getWidgetsForRegion } from '@workbench/widgetRegistry';
import { getProjectWidgetValues } from '@workbench/widgetState';
import { useWorkbenchCommands, useWorkbenchExtensions, useWorkbenchQueries } from '@workbench/WorkbenchContext';
import { resolvePanelToggle } from '@workbench/workbenchState';
+import { useTranslation } from 'react-i18next';
const layoutPresetCommands = builtInLayoutPresetDescriptors.map(({ hotkeyId, preset }) => ({
id: `app.${hotkeyId}`,
@@ -86,6 +87,7 @@ export const useRegisterFirstPartyCommands = () => {
const { commands: commandApi } = useWorkbenchExtensions();
const queries = useWorkbenchQueries();
const queryClient = useQueryClient();
+ const { t } = useTranslation();
const { layout, notifications, queue, widgets } = commands;
useInvocationTemplatesSelector((snapshot) => snapshot.status);
@@ -132,6 +134,7 @@ export const useRegisterFirstPartyCommands = () => {
models: getAvailableModels() ?? [],
owner,
projectId: activeProject.id,
+ t,
});
assertAccountScopeCurrent(owner);
diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/executeImageRecall.test.ts b/invokeai/frontend/webv2/src/workbench/image-actions/executeImageRecall.test.ts
index bd162f3cd9..4b4fa240aa 100644
--- a/invokeai/frontend/webv2/src/workbench/image-actions/executeImageRecall.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/image-actions/executeImageRecall.test.ts
@@ -1,6 +1,8 @@
import type { GalleryImage } from '@features/gallery';
+import type { GenerateModelConfig } from '@features/generation/contracts';
import type { ModelConfig } from '@features/models';
import type { WorkbenchCommands } from '@workbench/workbenchStore';
+import type { TFunction } from 'i18next';
import { accountLifecycle } from '@platform/state/accountLifecycle';
import { beforeEach, describe, expect, it, vi } from 'vitest';
@@ -23,7 +25,7 @@ import {
seedArchitectureCapabilities,
} from '@features/generation/core/architectureCapabilities.testing';
-import { executeImageRecall } from './executeImageRecall';
+import { executeImageRecall, getCurrentGenerateValues } from './executeImageRecall';
const model = {
base: 'sdxl',
@@ -51,6 +53,8 @@ const image: GalleryImage = {
width: 512,
};
+const t = ((key: string) => key) as unknown as TFunction;
+
const createCommands = () => {
const add = vi.fn();
const setSettings = vi.fn();
@@ -78,6 +82,7 @@ describe('executeImageRecall', () => {
await expect(
executeImageRecall({
+ t,
commands,
generateValues: { modelKey: model.key },
image,
@@ -97,13 +102,19 @@ describe('executeImageRecall', () => {
it('persists no remix until model capabilities load, and says why', async () => {
const { add, commands, setSettings } = createCommands();
+ // Initialised while the table is present, so only the recall itself is gated.
+ const generateValues = getCurrentGenerateValues({
+ generateValues: { modelKey: model.key },
+ supportedModels: [model as GenerateModelConfig],
+ });
resetArchitectureCapabilities();
try {
await expect(
executeImageRecall({
+ t,
commands,
- generateValues: { modelKey: model.key },
+ generateValues: generateValues as unknown as Record<string, unknown>,
image,
kind: 'remix',
models: [model],
@@ -118,8 +129,38 @@ describe('executeImageRecall', () => {
expect(setSettings).not.toHaveBeenCalled();
expect(add).toHaveBeenCalledWith({
kind: 'info',
- message:
- 'Model capabilities are not loaded, so settings that depend on the model cannot be recalled yet. Prompts and seed can. If loading failed, retry from the Generate panel.',
+ message: 'widgets.generate.capabilitiesUnavailableForRecall',
+ title: 'Cannot recall image data',
+ });
+ });
+
+ it('does not initialise a fresh project from fallback defaults for a prompt recall during an outage', async () => {
+ const { add, commands, setSettings } = createCommands();
+
+ galleryApi.galleryImages.metadata.mockResolvedValue({ positive_prompt: 'recalled prompt' });
+
+ resetArchitectureCapabilities();
+ try {
+ await expect(
+ executeImageRecall({
+ t,
+ commands,
+ // Never initialised: nothing but a model key, so the values would be synthesised.
+ generateValues: { modelKey: model.key },
+ image,
+ kind: 'prompts',
+ models: [model],
+ projectId: 'project-1',
+ })
+ ).resolves.toBe(false);
+ } finally {
+ setArchitectureCapabilities(architectureCapabilitiesFixture);
+ }
+
+ expect(setSettings).not.toHaveBeenCalled();
+ expect(add).toHaveBeenCalledWith({
+ kind: 'info',
+ message: 'widgets.generate.capabilitiesUnavailableForSetup',
title: 'Cannot recall image data',
});
});
@@ -129,6 +170,7 @@ describe('executeImageRecall', () => {
await expect(
executeImageRecall({
+ t,
commands,
generateValues: { modelKey: model.key, positivePrompt: 'stale prompt' },
getGenerateValues: () => ({ modelKey: model.key, positivePrompt: 'fresh prompt' }),
@@ -172,6 +214,7 @@ describe('executeImageRecall', () => {
await expect(
executeImageRecall({
+ t,
commands,
generateValues: { modelKey: model.key },
image: recallImage,
@@ -204,6 +247,7 @@ describe('executeImageRecall', () => {
})
);
const oldRecall = executeImageRecall({
+ t,
commands: oldCommands.commands,
generateValues: { modelKey: model.key },
image,
@@ -219,6 +263,7 @@ describe('executeImageRecall', () => {
galleryApi.galleryImages.metadata.mockResolvedValueOnce({ positive_prompt: 'user b' });
await expect(
executeImageRecall({
+ t,
commands: newCommands.commands,
generateValues: { modelKey: model.key },
image,
@@ -247,6 +292,7 @@ describe('executeImageRecall', () => {
await expect(
executeImageRecall({
+ t,
commands: oldCommands.commands,
generateValues: { modelKey: model.key },
image,
diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/executeImageRecall.ts b/invokeai/frontend/webv2/src/workbench/image-actions/executeImageRecall.ts
index 3babdaf391..3cd1b7b477 100644
--- a/invokeai/frontend/webv2/src/workbench/image-actions/executeImageRecall.ts
+++ b/invokeai/frontend/webv2/src/workbench/image-actions/executeImageRecall.ts
@@ -7,11 +7,13 @@ import type {
} from '@features/generation/contracts';
import type { ModelConfig } from '@features/models';
import type { WorkbenchCommands } from '@workbench/workbenchStore';
+import type { TFunction } from 'i18next';
import { galleryImages } from '@features/gallery';
import {
getDefaultGenerateSettings,
getEffectiveReferenceImage,
+ hasArchitectureCapabilities,
isSupportedGenerateModel,
isVaeModelConfig,
normalizeGenerateWidgetValues,
@@ -91,6 +93,12 @@ export const filterAvailableReferenceImages = async (
});
};
+/** Why `getCurrentGenerateValues` answered null: no supported model, or no table to initialise from. */
+export const getMissingGenerateValuesMessage = (t: TFunction): string =>
+ hasArchitectureCapabilities()
+ ? t('widgets.generate.selectSupportedModelFirst')
+ : t('widgets.generate.capabilitiesUnavailableForSetup');
+
export const getCurrentGenerateValues = ({
generateValues,
supportedModels,
@@ -104,6 +112,11 @@ export const getCurrentGenerateValues = ({
return normalizedValues;
}
+ // A first set of values is synthesised from architecture policy, and every caller persists it.
+ if (!hasArchitectureCapabilities()) {
+ return null;
+ }
+
const fallbackModelKey = typeof generateValues.modelKey === 'string' ? generateValues.modelKey : null;
const fallbackModel = supportedModels.find((model) => model.key === fallbackModelKey) ?? supportedModels[0];
@@ -126,6 +139,7 @@ export const executeImageRecall = async ({
models,
owner: callerOwner,
projectId,
+ t,
}: {
commands: Pick<WorkbenchCommands, 'generation' | 'notifications'>;
generateValues: Record<string, unknown>;
@@ -136,6 +150,7 @@ export const executeImageRecall = async ({
/** Caller-captured identity lifetime; direct synchronous callers may omit it. */
owner?: AccountScope;
projectId?: string;
+ t: TFunction;
}): Promise<boolean> => {
const owner = callerOwner ?? captureAccountScope();
if (!isAccountScopeCurrent(owner)) {
@@ -153,7 +168,7 @@ export const executeImageRecall = async ({
if (!currentGenerateValues) {
commands.notifications.add({
kind: 'info',
- message: 'Select a supported Generate model first.',
+ message: getMissingGenerateValuesMessage(t),
title: 'Cannot recall image data',
});
return false;
@@ -162,8 +177,7 @@ export const executeImageRecall = async ({
if (!isImageRecallKindAvailable(kind)) {
commands.notifications.add({
kind: 'info',
- message:
- 'Model capabilities are not loaded, so settings that depend on the model cannot be recalled yet. Prompts and seed can. If loading failed, retry from the Generate panel.',
+ message: t('widgets.generate.capabilitiesUnavailableForRecall'),
title: 'Cannot recall image data',
});
return false;
diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/executeRecallParameters.test.ts b/invokeai/frontend/webv2/src/workbench/image-actions/executeRecallParameters.test.ts
index ad3235b626..b5d0000343 100644
--- a/invokeai/frontend/webv2/src/workbench/image-actions/executeRecallParameters.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/image-actions/executeRecallParameters.test.ts
@@ -1,5 +1,6 @@
-import type { ComponentModelConfig } from '@features/generation/contracts';
+import type { ComponentModelConfig, GenerateModelConfig } from '@features/generation/contracts';
import type { WorkbenchCommands } from '@workbench/workbenchStore';
+import type { TFunction } from 'i18next';
import { accountLifecycle, captureAccountScope, type AccountScope } from '@platform/state/accountLifecycle';
import { beforeEach, describe, expect, it, vi } from 'vitest';
@@ -13,11 +14,31 @@ const galleryApi = vi.hoisted(() => ({
vi.mock('@features/gallery', () => galleryApi);
-import { seedArchitectureCapabilities } from '@features/generation/core/architectureCapabilities.testing';
+import {
+ resetArchitectureCapabilities,
+ setArchitectureCapabilities,
+} from '@features/generation/core/architectureCapabilities';
+import {
+ architectureCapabilitiesFixture,
+ seedArchitectureCapabilities,
+} from '@features/generation/core/architectureCapabilities.testing';
+import { getCurrentGenerateValues } from './executeImageRecall';
import { executeRecallParameters } from './executeRecallParameters';
const sdxl = { base: 'sdxl', hash: 'h', key: 'sdxl-main', name: 'SDXL', type: 'main' } as ComponentModelConfig;
+const sd1 = { base: 'sd-1', hash: 'h1', key: 'sd1-main', name: 'SD 1', type: 'main' } as ComponentModelConfig;
+const t = ((key: string) => key) as unknown as TFunction;
+
+/** Runs `fn` with the capability table absent, the way a failed boot fetch leaves it. */
+const withoutCapabilities = async <T>(fn: () => Promise<T>): Promise<T> => {
+ resetArchitectureCapabilities();
+ try {
+ return await fn();
+ } finally {
+ setArchitectureCapabilities(architectureCapabilitiesFixture);
+ }
+};
const galleryImage = (imageName: string) => ({ height: 512, imageName, width: 512 });
const image = (imageName: string) => ({ height: 512, image_name: imageName, width: 512 });
const existingReference = {
@@ -68,6 +89,7 @@ const run = (
owner: owner ?? captureAccountScope(),
parameters,
projectId: 'project-1',
+ t,
});
seedArchitectureCapabilities();
@@ -118,6 +140,72 @@ describe('executeRecallParameters', () => {
);
});
+ describe('while the capability table is absent', () => {
+ // Initialised while the table is present, so the project already holds SDXL's real values.
+ const initialised = () =>
+ getCurrentGenerateValues({
+ generateValues: { modelKey: sdxl.key },
+ supportedModels: [sdxl as unknown as GenerateModelConfig],
+ }) as unknown as Record<string, unknown> & { height: number; width: number };
+
+ it('applies no model switch, and says why', async () => {
+ const { add, commands, setSettings } = createCommands();
+ const generateValues = initialised();
+
+ await expect(
+ withoutCapabilities(() => run(commands, { model: sd1.key }, { generateValues, models: [sdxl, sd1] }))
+ ).resolves.toBe(false);
+
+ expect(setSettings).not.toHaveBeenCalled();
+ expect(add).toHaveBeenCalledWith({
+ kind: 'info',
+ message: 'widgets.generate.capabilitiesUnavailableForRecall',
+ title: 'Cannot apply recalled parameters',
+ });
+ });
+
+ it('withholds a dimension reset, which would restore the fallback canvas', async () => {
+ const { commands, setSettings } = createCommands();
+ const generateValues = initialised();
+
+ await expect(withoutCapabilities(() => run(commands, { width: null }, { generateValues }))).resolves.toBe(false);
+
+ expect(setSettings).not.toHaveBeenCalled();
+ });
+
+ it('still applies prompts and seed, which read no policy', async () => {
+ const { commands, setSettings } = createCommands();
+ const generateValues = initialised();
+
+ await expect(
+ withoutCapabilities(() => run(commands, { positive_prompt: 'a cat', seed: 7 }, { generateValues }))
+ ).resolves.toBe(true);
+
+ expect(setSettings).toHaveBeenCalledWith(
+ expect.objectContaining({
+ height: generateValues.height,
+ positivePrompt: 'a cat',
+ seed: 7,
+ width: generateValues.width,
+ }),
+ 'project-1'
+ );
+ });
+
+ it('does not initialise a fresh project from fallback defaults', async () => {
+ const { add, commands, setSettings } = createCommands();
+
+ await expect(withoutCapabilities(() => run(commands, { positive_prompt: 'a cat' }))).resolves.toBe(false);
+
+ expect(setSettings).not.toHaveBeenCalled();
+ expect(add).toHaveBeenCalledWith({
+ kind: 'info',
+ message: 'widgets.generate.capabilitiesUnavailableForSetup',
+ title: 'Cannot apply recalled parameters',
+ });
+ });
+ });
+
it('asks for a supported model when the project has none selected', async () => {
const { add, commands, setSettings } = createCommands();
diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/executeRecallParameters.ts b/invokeai/frontend/webv2/src/workbench/image-actions/executeRecallParameters.ts
index 3ee48a3853..427a9eca3f 100644
--- a/invokeai/frontend/webv2/src/workbench/image-actions/executeRecallParameters.ts
+++ b/invokeai/frontend/webv2/src/workbench/image-actions/executeRecallParameters.ts
@@ -1,14 +1,20 @@
import type { ComponentModelConfig, VaeModelConfig } from '@features/generation/contracts';
import type { WorkbenchCommands } from '@workbench/workbenchStore';
+import type { TFunction } from 'i18next';
import { getEffectiveReferenceImage, isSupportedGenerateModel, isVaeModelConfig } from '@features/generation/settings';
import { assertAccountScopeCurrent, isAccountScopeCurrent, type AccountScope } from '@platform/state/accountLifecycle';
-import { filterAvailableReferenceImages, getCurrentGenerateValues } from './executeImageRecall';
+import {
+ filterAvailableReferenceImages,
+ getCurrentGenerateValues,
+ getMissingGenerateValuesMessage,
+} from './executeImageRecall';
import {
buildRecallParametersSettings,
getRecallParametersMessage,
getRecallParametersSkipMessage,
+ isRecallParametersAvailable,
type RecallParametersResult,
} from './recallParameters';
@@ -70,6 +76,7 @@ export const executeRecallParameters = async ({
owner,
parameters,
projectId,
+ t,
}: {
commands: Pick<WorkbenchCommands, 'generation' | 'notifications'>;
getGenerateValues: () => Record<string, unknown> | null;
@@ -77,6 +84,7 @@ export const executeRecallParameters = async ({
owner: AccountScope;
parameters: Record<string, unknown>;
projectId: string;
+ t: TFunction;
}): Promise<boolean> => {
if (!isAccountScopeCurrent(owner)) {
return false;
@@ -97,7 +105,16 @@ export const executeRecallParameters = async ({
if (!currentValues) {
commands.notifications.add({
kind: 'info',
- message: 'Select a supported Generate model first.',
+ message: getMissingGenerateValuesMessage(t),
+ title: 'Cannot apply recalled parameters',
+ });
+ return false;
+ }
+
+ if (!isRecallParametersAvailable(parameters)) {
+ commands.notifications.add({
+ kind: 'info',
+ message: t('widgets.generate.capabilitiesUnavailableForRecall'),
title: 'Cannot apply recalled parameters',
});
return false;
diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/recallParameters.ts b/invokeai/frontend/webv2/src/workbench/image-actions/recallParameters.ts
index ddbe9f68a2..b1ad5ae47f 100644
--- a/invokeai/frontend/webv2/src/workbench/image-actions/recallParameters.ts
+++ b/invokeai/frontend/webv2/src/workbench/image-actions/recallParameters.ts
@@ -24,6 +24,7 @@ import {
getMaxReferenceImages,
getModelDefaultVae,
getSettingsWithModelDefaults,
+ hasArchitectureCapabilities,
hasModelDefaultVae,
isLoraCompatibleWithModel,
isLoraModelConfig,
@@ -97,6 +98,23 @@ export const isRecallParametersUpdatedEvent = (payload: unknown): payload is Rec
/** Backend graphs that feed `cfgScale` to a `guidance` input, so the API's `guidance` names the same knob. */
const GUIDANCE_BASES = new Set(['flux', 'flux2', 'qwen-image', 'z-image']);
+/** Applied without reading architecture policy; every other handled key is snapped, coerced or defaulted by it. */
+const POLICY_FREE_KEYS = new Set([
+ 'append',
+ 'guidance',
+ 'loras',
+ 'negative_prompt',
+ 'positive_prompt',
+ 'seamless_x',
+ 'seamless_y',
+ 'seed',
+]);
+
+/** Whether a payload can be applied now: without the table, only policy-free keys may be. */
+export const isRecallParametersAvailable = (parameters: Record<string, unknown>): boolean =>
+ hasArchitectureCapabilities() ||
+ Object.keys(parameters).every((key) => POLICY_FREE_KEYS.has(key) || !HANDLED_KEYS.has(key));
+
const HANDLED_KEYS = new Set([
'append',
'cfg_rescale_multiplier',
diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/recallParametersBridge.test.ts b/invokeai/frontend/webv2/src/workbench/image-actions/recallParametersBridge.test.ts
index a2c3c5fe97..8d8d9dd207 100644
--- a/invokeai/frontend/webv2/src/workbench/image-actions/recallParametersBridge.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/image-actions/recallParametersBridge.test.ts
@@ -1,5 +1,6 @@
import type { SocketHub } from '@platform/transport/socketHub';
import type { WorkbenchCommands, WorkbenchQueries } from '@workbench/workbenchStore';
+import type { TFunction } from 'i18next';
import { describe, expect, it, vi } from 'vitest';
@@ -58,6 +59,7 @@ const createDeps = () => {
getSnapshot: () => ({ activeProject: active }),
} as unknown as Pick<WorkbenchQueries, 'getProject' | 'getSnapshot'>,
received,
+ t: ((key: string) => key) as unknown as TFunction,
reportError,
};
};
diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/recallParametersBridge.ts b/invokeai/frontend/webv2/src/workbench/image-actions/recallParametersBridge.ts
index 07ea6111d9..ba73dbe492 100644
--- a/invokeai/frontend/webv2/src/workbench/image-actions/recallParametersBridge.ts
+++ b/invokeai/frontend/webv2/src/workbench/image-actions/recallParametersBridge.ts
@@ -1,5 +1,6 @@
import type { SocketHub } from '@platform/transport/socketHub';
import type { WorkbenchCommands, WorkbenchQueries } from '@workbench/workbenchStore';
+import type { TFunction } from 'i18next';
import type {
createRecallParametersRuntime,
@@ -24,12 +25,14 @@ export const attachRecallParametersRuntime = ({
hub,
load = () => import('./recallParametersRuntime'),
queries,
+ t,
}: {
commands: Pick<WorkbenchCommands, 'generation' | 'notifications'>;
getSessionUserId?: () => string | null;
hub: Pick<SocketHub, 'on'>;
load?: () => Promise<RecallParametersRuntimeModule>;
queries: Pick<WorkbenchQueries, 'getProject' | 'getSnapshot'>;
+ t: TFunction;
}): RecallParametersRuntime => {
let disposed = false;
let loading: Promise<void> | null = null;
@@ -54,6 +57,7 @@ export const attachRecallParametersRuntime = ({
hub,
queries,
replay: pending.splice(0),
+ t,
});
})
.catch((error: unknown) => {
diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/recallParametersRuntime.test.ts b/invokeai/frontend/webv2/src/workbench/image-actions/recallParametersRuntime.test.ts
index bab84606e9..17e284eb31 100644
--- a/invokeai/frontend/webv2/src/workbench/image-actions/recallParametersRuntime.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/image-actions/recallParametersRuntime.test.ts
@@ -1,6 +1,7 @@
import type { ComponentModelConfig } from '@features/generation/contracts';
import type { ModelsSnapshot } from '@features/models';
import type { SocketHub } from '@platform/transport/socketHub';
+import type { TFunction } from 'i18next';
import { accountLifecycle } from '@platform/state/accountLifecycle';
import { getProjectWidgetValues } from '@workbench/widgetState';
@@ -79,7 +80,9 @@ const createRuntime = (
store: ReturnType<typeof createWorkbenchStore>,
hub: Pick<SocketHub, 'on'>,
options: Partial<Parameters<typeof createRecallParametersRuntime>[0]> = {}
-) => createRecallParametersRuntime({ commands: store.commands, hub, queries: store.queries, ...options });
+) => createRecallParametersRuntime({ commands: store.commands, hub, queries: store.queries, t, ...options });
+
+const t = ((key: string) => key) as unknown as TFunction;
seedArchitectureCapabilities();
diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/recallParametersRuntime.ts b/invokeai/frontend/webv2/src/workbench/image-actions/recallParametersRuntime.ts
index 0e06b58418..220b48dffa 100644
--- a/invokeai/frontend/webv2/src/workbench/image-actions/recallParametersRuntime.ts
+++ b/invokeai/frontend/webv2/src/workbench/image-actions/recallParametersRuntime.ts
@@ -1,5 +1,6 @@
import type { SocketHub } from '@platform/transport/socketHub';
import type { WorkbenchCommands, WorkbenchQueries } from '@workbench/workbenchStore';
+import type { TFunction } from 'i18next';
import { ensureModelsLoaded, getModelsSnapshot } from '@features/models';
import { captureAccountScope, isAccountScopeCurrent } from '@platform/state/accountLifecycle';
@@ -35,6 +36,7 @@ export const createRecallParametersRuntime = ({
hub,
queries,
replay = [],
+ t,
}: {
commands: Pick<WorkbenchCommands, 'generation' | 'notifications'>;
/**
@@ -46,6 +48,8 @@ export const createRecallParametersRuntime = ({
hub: Pick<SocketHub, 'on'>;
queries: Pick<WorkbenchQueries, 'getProject' | 'getSnapshot'>;
replay?: readonly PendingRecallEvent[];
+ /** Resolves against the current language at call time; captured once, at attach. */
+ t: TFunction;
}): RecallParametersRuntime => {
let disposed = false;
let chain: Promise<void> = Promise.resolve();
@@ -94,6 +98,7 @@ export const createRecallParametersRuntime = ({
await executeRecallParameters({
commands,
+ t,
getGenerateValues: () => {
const project = queries.getProject(projectId);
return project ? getProjectWidgetValues(project, 'generate') : null;
diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.browser.test.tsx
index 088adf5283..f9cbd66e24 100644
--- a/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.browser.test.tsx
@@ -1,7 +1,14 @@
import type { GalleryImage, GalleryItem, GalleryItemKey, GalleryItemRef } from '@features/gallery';
import type { CreateCanvasFromImagesResult } from '@workbench/canvas-operations/api';
-import { seedArchitectureCapabilities } from '@features/generation/core/architectureCapabilities.testing';
+import {
+ resetArchitectureCapabilities,
+ setArchitectureCapabilities,
+} from '@features/generation/core/architectureCapabilities';
+import {
+ architectureCapabilitiesFixture,
+ seedArchitectureCapabilities,
+} from '@features/generation/core/architectureCapabilities.testing';
import { accountLifecycle } from '@platform/state/accountLifecycle';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { act, createRef, type Ref, useImperativeHandle } from 'react';
@@ -237,7 +244,7 @@ const Probe = ({ modelKey = 'sd-1-model', ref }: { modelKey?: string; ref: Ref<I
return null;
};
-beforeEach(async () => {
+beforeEach(() => {
vi.clearAllMocks();
preferences.confirmImageDeletion = false;
mocks.requestDeletionConfirmation.mockImplementation(
@@ -251,6 +258,13 @@ beforeEach(async () => {
});
accountLifecycle.activate('user-a');
currentItemActionContext = null;
+});
+
+// After the account switch, which drops the table, and before the mount, so the Probe renders
+// with it present and is unmounted before it is dropped again; the order keeps both inside `act`.
+seedArchitectureCapabilities();
+
+beforeEach(async () => {
host = document.createElement('div');
document.body.append(host);
root = createRoot(host);
@@ -271,8 +285,6 @@ afterEach(async () => {
root = null;
});
-seedArchitectureCapabilities();
-
describe('new canvas from images', () => {
const galleryImage = (imageName: string): GalleryImage => ({
boardId: 'none',
@@ -320,6 +332,17 @@ describe('new canvas from images', () => {
});
});
+describe('reference image availability and the capability table', () => {
+ it('re-answers when the table lands without the project or the models changing', async () => {
+ await act(() => resetArchitectureCapabilities());
+ expect(actionsRef.current!.canUseAsReferenceImage).toBe(false);
+
+ // Nothing else re-renders the host: the same project values and the same model list.
+ await act(() => setArchitectureCapabilities(architectureCapabilitiesFixture));
+ expect(actionsRef.current!.canUseAsReferenceImage).toBe(true);
+ });
+});
+
describe('image recall capability cancellation', () => {
it('re-derives capabilities from the current generate model without another metadata request', async () => {
const image: GalleryImage = {
@@ -1273,7 +1296,8 @@ describe('primary successor after confirmed deletion', () => {
const deletion = getItemActions().deleteItems([{ kind: 'image', name: primary.name }]);
await vi.waitFor(() => expect(mocks.resolveItem).toHaveBeenCalledOnce());
- accountLifecycle.activate('user-b');
+ // The switch drops the capability table, which the hook now subscribes to.
+ await act(() => accountLifecycle.activate('user-b'));
resolveItem(successor);
await act(() => deletion);
diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.ts b/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.ts
index 4868d829a1..13ce924ee9 100644
--- a/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.ts
+++ b/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.ts
@@ -26,6 +26,7 @@ import {
patchGalleryItemCaches,
} from '@features/gallery/queries';
import { flushGenerateDrafts, setPendingPromptTemplateDraft } from '@features/generation/react';
+import { getArchitectureCapabilitiesSnapshot, subscribeArchitectureCapabilities } from '@features/generation/runtime';
import { getMaxReferenceImages, isVaeModelConfig, isSupportedGenerateModel } from '@features/generation/settings';
import { ensureModelsLoaded, useModelsSelector } from '@features/models';
import { downloadBlob } from '@platform/browser/downloadBlob';
@@ -35,6 +36,7 @@ import {
captureAccountScope,
isAccountScopeCurrent,
} from '@platform/state/accountLifecycle';
+import { useExternalStoreSelector } from '@platform/state/selectors';
import { useQueryClient } from '@tanstack/react-query';
import {
createCanvasFromImages,
@@ -47,7 +49,7 @@ import { useWorkbenchPreferenceSelector } from '@workbench/settings/store';
import { useOpenWorkbenchWidget } from '@workbench/useOpenWorkbenchWidget';
import { getProjectWidgetValues } from '@workbench/widgetState';
import { useWorkbenchCommands, useWorkbenchQueries } from '@workbench/WorkbenchContext';
-import { useMemo } from 'react';
+import { useCallback, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import type { RequestDeletionConfirmation } from './useDeletionConfirmation';
@@ -157,9 +159,20 @@ export const useImageActions = ({
const models = useModelsSelector((snapshot) => snapshot.models);
const supportedModels = useMemo(() => models.filter(isSupportedGenerateModel), [models]);
const vaeModels = useMemo(() => models.filter(isVaeModelConfig).map((model) => model as VaeModelConfig), [models]);
- const currentGenerateValues = useMemo(() => {
- return getCurrentGenerateValues({ generateValues, supportedModels });
- }, [generateValues, supportedModels]);
+ // Both read architecture policy, so they are read inside the capability store's selector: memoised
+ // on the project alone they would keep the answer given before the table arrived.
+ const { canUseAsReferenceImage, currentGenerateValues } = useExternalStoreSelector(
+ subscribeArchitectureCapabilities,
+ getArchitectureCapabilitiesSnapshot,
+ useCallback(() => {
+ const values = getCurrentGenerateValues({ generateValues, supportedModels });
+
+ return {
+ canUseAsReferenceImage: Boolean(values && values.referenceImages.length < getMaxReferenceImages(values.model)),
+ currentGenerateValues: values,
+ };
+ }, [generateValues, supportedModels])
+ );
useMountEffect(() => {
void ensureModelsLoaded();
@@ -906,6 +919,7 @@ export const useImageActions = ({
kind,
models,
projectId,
+ t,
});
if (isAccountScopeCurrent(owner) && didRecall && (!projectId || queries.isActiveProject(projectId))) {
@@ -1000,10 +1014,7 @@ export const useImageActions = ({
imageNames.map((name) => ({ kind: 'image', name })),
starred
),
- canUseAsReferenceImage: Boolean(
- currentGenerateValues &&
- currentGenerateValues.referenceImages.length < getMaxReferenceImages(currentGenerateValues.model)
- ),
+ canUseAsReferenceImage,
useAsReferenceImage: (image) => {
const result = appendReferenceImage({ generateValues: getLatestGenerateValues(), image, models });
@@ -1017,6 +1028,7 @@ export const useImageActions = ({
};
}, [
boards,
+ canUseAsReferenceImage,
confirmImageDeletion,
currentGenerateValues,
commands,
diff --git a/invokeai/frontend/webv2/src/workbench/queue-integration/useQueueItemRecall.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/queue-integration/useQueueItemRecall.browser.test.tsx
index edd9e96a83..33918cd381 100644
--- a/invokeai/frontend/webv2/src/workbench/queue-integration/useQueueItemRecall.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/queue-integration/useQueueItemRecall.browser.test.tsx
@@ -4,6 +4,14 @@ import type { QueueGenerationMeta } from '@features/queue/contracts';
import type { ImageRecallKind } from '@workbench/image-actions';
import type * as WorkbenchContextModule from '@workbench/WorkbenchContext';
+import {
+ resetArchitectureCapabilities,
+ setArchitectureCapabilities,
+} from '@features/generation/core/architectureCapabilities';
+import {
+ architectureCapabilitiesFixture,
+ seedArchitectureCapabilities,
+} from '@features/generation/core/architectureCapabilities.testing';
import { createDefaultVideoWidgetValues } from '@features/video';
import { act, createRef, type Ref, useImperativeHandle } from 'react';
import { createRoot, type Root } from 'react-dom/client';
@@ -42,6 +50,8 @@ vi.mock('@workbench/useNotify', () => ({
vi.mock('@workbench/useOpenWorkbenchWidget', () => ({ useOpenWorkbenchWidget: () => mocks.openWidget }));
vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }));
+seedArchitectureCapabilities();
+
const NO_META: QueueGenerationMeta = {};
const generateSnapshot = {
positivePrompt: 'snapshot prompt',
@@ -119,4 +129,18 @@ describe('useQueueItemRecall', () => {
expect(mocks.setSettings).not.toHaveBeenCalled();
expect(mocks.notifyInfo).toHaveBeenCalledWith(expect.any(String), 'widgets.queue.recallUnavailable');
});
+
+ it('names the missing capability table, not a missing model, while the table is absent', async () => {
+ await render(null, { positivePrompt: 'session prompt' });
+
+ await act(() => resetArchitectureCapabilities());
+ try {
+ await recall('seed');
+ } finally {
+ await act(() => setArchitectureCapabilities(architectureCapabilitiesFixture));
+ }
+
+ expect(mocks.setSettings).not.toHaveBeenCalled();
+ expect(mocks.notifyInfo).toHaveBeenCalledWith(expect.any(String), 'widgets.queue.recallUnavailableCapabilities');
+ });
});
diff --git a/invokeai/frontend/webv2/src/workbench/queue-integration/useQueueItemRecall.ts b/invokeai/frontend/webv2/src/workbench/queue-integration/useQueueItemRecall.ts
index dadaa4c94a..89195fe2a0 100644
--- a/invokeai/frontend/webv2/src/workbench/queue-integration/useQueueItemRecall.ts
+++ b/invokeai/frontend/webv2/src/workbench/queue-integration/useQueueItemRecall.ts
@@ -2,7 +2,7 @@ import type { QueueGenerationMeta } from '@features/queue/contracts';
import type { ImageRecallCapabilities, ImageRecallKind } from '@workbench/image-actions';
import { createGenerateFormValuesSelector } from '@features/generation/react';
-import { isSupportedGenerateModel } from '@features/generation/settings';
+import { hasArchitectureCapabilities, isSupportedGenerateModel } from '@features/generation/settings';
import { ensureModelsLoaded, useModelsSelector } from '@features/models';
import { useMountEffect } from '@platform/react/useMountEffect';
import {
@@ -68,12 +68,15 @@ export const useQueueItemRecall = (
const plan = planQueueRecall(kind, { current, isVideoItem, meta, snapshot: localGenerateValues, videoSnapshot });
if (!plan) {
- notify.info(
- getImageRecallTitle(kind),
- // The Generate copy names a missing Generate model, which is not why
- // a video recall would come back empty.
- t(isVideoItem ? 'widgets.queue.recallUnavailableForItem' : 'widgets.queue.recallUnavailable')
- );
+ // The Generate copy names a missing Generate model, which is not why a video recall
+ // would come back empty -- nor why a fresh project cannot be initialised without the
+ // capability table.
+ const reason = isVideoItem
+ ? 'widgets.queue.recallUnavailableForItem'
+ : !current && !hasArchitectureCapabilities()
+ ? 'widgets.queue.recallUnavailableCapabilities'
+ : 'widgets.queue.recallUnavailable';
+ notify.info(getImageRecallTitle(kind), t(reason));
return;
}