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(preview): keep recall details current
joshistoast8104aeb03cb2
diff --git a/.superpowers/sdd/mixed-media-gallery-parity/task-9-report.md b/.superpowers/sdd/mixed-media-gallery-parity/task-9-report.mdindex 6e4d83cd8f..8ad5090e0c 100644--- a/.superpowers/sdd/mixed-media-gallery-parity/task-9-report.md+++ b/.superpowers/sdd/mixed-media-gallery-parity/task-9-report.md@@ -92,10 +92,9 @@ Tests 1 failed | 327 passed (328)Its intentionally invalid data-video URL could emit a trusted native mediaerror after the test's deterministic manual error when the full suite wasbusy. That second event correctly entered the terminal retry state, racing the-first-retry assertion. The test harness now suppresses only trusted native-media errors for that invalid URL; its explicit untrusted recovery events are-unchanged. The focused file remained green at 17/17 and the repeated full-browser gate passed 328/328.+first-retry assertion. The final harness uses a minimal valid media URL for+tests that dispatch deterministic recovery events and reserves an invalid URL+for one focused native-error contract. No trusted media error is suppressed.### Completion-review follow-up@@ -125,6 +124,49 @@ The same three files then passed all 38 tests. The Details file passed 9/9without its prior `act(...)` diagnostics after its asynchronous queryassertions were wrapped correctly.+### Review-fix round++The next review found that image recall capabilities were cached under only+the account epoch and item key even though they also depend on current+generation values and model inventory. The focused regression kept the epoch,+item, and cached metadata fixed, changed the current capability action, and+failed because the Recall All button remained enabled:++```text+Test Files 1 failed (1)+Tests 1 failed | 9 skipped (10)+AssertionError: expected false to be true+```++The cache now owns server metadata only. `ImageActions` exposes a synchronous+`deriveImageRecallCapabilities(image, metadata)` operation backed by its+current generation values and model inventory, and Preview calls it on every+render after metadata resolves. The regression proves that the button updates+without another metadata request. A second hook-level test switches the+current model from SD-1 to FLUX and proves clip-skip capability changes without+starting a metadata transport.++The review also found that a test-host capture listener suppressed every+trusted media error in the native-video file. A focused browser-generated+error test failed because protected-media recovery was never called:++```text+Test Files 1 failed (1)+Tests 1 failed | 17 skipped (18)+AssertionError: expected "vi.fn()" to be called once, but got 0 times+```++The blanket listener was removed. Deterministic synthetic recovery tests use a+valid media data URL, while the focused invalid-source test observes an+`isTrusted` browser error and proves it reaches cookie refresh. The existing+deterministic recovery tests retain terminal failure-UI coverage. The three+directly affected browser files then passed:++```text+Test Files 3 passed (3)+Tests 49 passed (49)+```+## Implementation### Preview-owned frame capture@@ -163,8 +205,11 @@ assertions were wrapped correctly.`['preview', 'details', accountEpoch, itemKey]`.- Unmounting on close/item/epoch change cancels supported transports throughthe TanStack Query signal.-- Image recall-capability metadata combines that signal with its account-owned- signal, so closing Details aborts both image metadata transports.+- The image query performs exactly one metadata transport. Recall capabilities+ are derived synchronously from that cached metadata and the current+ generation/model state, so they never become stale behind the item-only key.+- The asynchronous recall-capability port retained for context menus still+ combines caller and account-lifecycle signals.- Video metadata and workflow/graph requests use `Promise.all` and the samesignal.- Video Metadata, Workflow, and Graph use `JsonPreview` from the direct@@ -200,15 +245,11 @@ pnpm test:browser```textTest Files 67 passed (67)-Tests 332 passed (332)+Tests 335 passed (335)```-The first final full-browser attempt passed every Task 9 test but an unrelated-existing platform Tabs hover test hit its 15-second timeout under suite load.-That file immediately passed 1/1 focused; the complete browser rerun above then-passed 332/332. The full suite retained non-failing React `act(...)`,-missing-i18n-instance, and intentional error-boundary diagnostics from-pre-existing files.+The full suite retained non-failing React `act(...)`, missing-i18n-instance,+and intentional error-boundary diagnostics from pre-existing files.```shpnpm test:fixturesdiff --git a/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.browser.test.tsxindex e158bb22fe..3ef8601cd2 100644--- a/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.browser.test.tsx+++ b/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.browser.test.tsx@@ -47,6 +47,7 @@ const createActions = (deleteItems: ImageActions['deleteItems']): ImageActions =copyImage: vi.fn(() => Promise.resolve()),deleteItems,deleteImages: vi.fn(() => Promise.resolve()),+ deriveImageRecallCapabilities: vi.fn(() => EMPTY_IMAGE_RECALL_CAPABILITIES),downloadItem: vi.fn(() => Promise.resolve()),downloadItems: vi.fn(() => Promise.resolve()),downloadImage: vi.fn(() => Promise.resolve()),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.tsxindex 29cee86a2c..4242d2de9c 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@@ -62,13 +62,21 @@ vi.mock('@features/gallery/queries', () => ({vi.mock('@features/models', () => ({ensureModelsLoaded: vi.fn(() => Promise.resolve()),getModelsSnapshot: () => ({- models: [{ base: 'sdxl', key: 'sdxl-model', name: 'SDXL', type: 'main' }],+ models: [+ { base: 'sd-1', key: 'sd-1-model', name: 'SD 1', type: 'main' },+ { base: 'flux', key: 'flux-model', name: 'FLUX', type: 'main' },+ ],}),useModelsSelector: (- selector: (snapshot: { models: Array<{ base: 'sdxl'; key: string; name: string; type: 'main' }> }) => unknown+ selector: (snapshot: {+ models: Array<{ base: 'sd-1' | 'flux'; key: string; name: string; type: 'main' }>;+ }) => unknown) =>selector({- models: [{ base: 'sdxl', key: 'sdxl-model', name: 'SDXL', type: 'main' }],+ models: [+ { base: 'sd-1', key: 'sd-1-model', name: 'SD 1', type: 'main' },+ { base: 'flux', key: 'flux-model', name: 'FLUX', type: 'main' },+ ],}),}));@@ -126,10 +134,10 @@ interface ItemActionContext {let currentItemActionContext: ItemActionContext | null = null;(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;-const Probe = ({ ref }: { ref: Ref<ImageActions> }) => {+const Probe = ({ modelKey = 'sd-1-model', ref }: { modelKey?: string; ref: Ref<ImageActions> }) => {const actions = useImageActions({boards: [],- generateValues: { modelKey: 'sdxl-model' },+ generateValues: { modelKey },getItemActionContext: () => currentItemActionContext,projectId: 'project-1',});@@ -165,6 +173,34 @@ afterEach(async () => {});describe('image recall capability cancellation', () => {+ it('re-derives capabilities from the current generate model without another metadata request', async () => {+ const image: GalleryImage = {+ boardId: 'none',+ height: 512,+ imageCategory: 'general',+ imageName: 'recall.png',+ imageUrl: '/full/recall.png',+ queuedAt: '2026-07-30T00:00:00.000Z',+ sourceQueueItemId: 'queue-recall',+ starred: false,+ thumbnailUrl: '/thumb/recall.png',+ width: 512,+ };++ expect(actionsRef.current?.deriveImageRecallCapabilities(image, { clip_skip: 2 }).clipSkip).toBe(true);++ await act(() => {+ root?.render(+ <QueryClientProvider client={new QueryClient()}>+ <Probe ref={actionsRef} modelKey="flux-model" />+ </QueryClientProvider>+ );+ });++ expect(actionsRef.current?.deriveImageRecallCapabilities(image, { clip_skip: 2 }).clipSkip).toBe(false);+ expect(mocks.imageMetadata).not.toHaveBeenCalled();+ });+it('combines a caller signal with the account lifecycle signal for metadata transport', async () => {let resolveMetadata!: (value: null) => void;const metadata = new Promise<null>((resolve) => {diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.ts b/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.tsindex 642cc11d30..8be2be4acd 100644--- a/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.ts+++ b/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.ts@@ -10,6 +10,7 @@ import {toGalleryItemRef,type GalleryBoard,type GalleryImage,+ type GalleryImageMetadata,type GalleryItem,type GalleryItemMutationResult,type GalleryItemRef,@@ -59,6 +60,11 @@ export interface ImageActions extends GalleryItemActions {canUseAsReferenceImage: boolean;copyImage: (image: GalleryImage) => Promise<void>;deleteImages: (imageNames: string[]) => Promise<void>;+ /** Derives recall availability from already-fetched metadata and the current generate/model state. */+ deriveImageRecallCapabilities: (+ image: GalleryImage,+ metadata: GalleryImageMetadata | null+ ) => ImageRecallCapabilities;downloadImage: (image: GalleryImage) => Promise<void>;downloadImages: (imageNames: string[]) => Promise<void>;getImageRecallCapabilities: (image: GalleryImage, signal?: AbortSignal) => Promise<ImageRecallCapabilities>;@@ -464,6 +470,23 @@ export const useImageActions = ({);}};+ const deriveImageRecallCapabilities = (+ image: GalleryImage,+ metadata: GalleryImageMetadata | null+ ): ImageRecallCapabilities => {+ if (!currentGenerateValues) {+ return EMPTY_IMAGE_RECALL_CAPABILITIES;+ }++ return getImageRecallCapabilities({+ currentValues: currentGenerateValues,+ image,+ metadata,+ models,+ supportedModels,+ vaeModels,+ });+ };return {deleteItems,@@ -501,6 +524,7 @@ export const useImageActions = ({}},deleteImages: (imageNames) => deleteItems(imageNames.map((name) => ({ kind: 'image', name }))),+ deriveImageRecallCapabilities,downloadImage: async (image) => {const owner = captureAccountScope();@@ -531,14 +555,7 @@ export const useImageActions = ({const metadata = await galleryImages.metadata(image.imageName, requestSignal);assertAccountScopeCurrent(owner);- return getImageRecallCapabilities({- currentValues: currentGenerateValues,- image,- metadata,- models,- supportedModels,- vaeModels,- });+ return deriveImageRecallCapabilities(image, metadata);} catch {if (!isAccountScopeCurrent(owner)) {return EMPTY_IMAGE_RECALL_CAPABILITIES;diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewDetails.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewDetails.browser.test.tsxindex fa1d238656..536ffc2e95 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewDetails.browser.test.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewDetails.browser.test.tsx@@ -99,6 +99,14 @@ const ALL_RECALL_CAPABILITIES: ImageRecallCapabilities = {remix: true,seed: true,};+const NO_RECALL_CAPABILITIES: ImageRecallCapabilities = {+ all: false,+ clipSkip: false,+ dimensions: false,+ prompts: false,+ remix: false,+ seed: false,+};const i18n = createInstance();void i18n.use(initReactI18next).init({@@ -184,6 +192,7 @@ beforeEach(() => {galleryMocks.videoMetadata.mockReset().mockResolvedValue(null);galleryMocks.videoWorkflow.mockReset().mockResolvedValue({ graph: null, workflow: null });actions = {+ deriveImageRecallCapabilities: vi.fn(() => ALL_RECALL_CAPABILITIES),getImageRecallCapabilities: vi.fn(() => Promise.resolve(ALL_RECALL_CAPABILITIES)),recallImageData: vi.fn(() => Promise.resolve()),} as unknown as ImageActions;@@ -218,12 +227,6 @@ describe('Preview query-driven Details', () => {// Intentionally pending.}));- actions.getImageRecallCapabilities = vi.fn(- () =>- new Promise<ImageRecallCapabilities>(() => {- // Intentionally pending.- })- );await renderFooter({ isOpen: true, item: imageItem });@@ -231,26 +234,20 @@ describe('Preview query-driven Details', () => {expect(getButton('Recall All').disabled).toBe(true);});- it('passes the Details query signal to image recall capability work and aborts it on close', async () => {+ it('aborts the sole image metadata transport on close without starting duplicate capability work', async () => {const metadata = deferred<null>();- const capabilities = deferred<ImageRecallCapabilities>();- const getImageRecallCapabilities = vi.fn((_image: GalleryImage, _signal?: AbortSignal) => capabilities.promise);galleryMocks.imageMetadata.mockReturnValueOnce(metadata.promise);- actions.getImageRecallCapabilities = getImageRecallCapabilities;await renderFooter({ isOpen: true, item: imageItem });const metadataSignal = galleryMocks.imageMetadata.mock.calls[0]?.[1] as AbortSignal;- const capabilitiesSignal = getImageRecallCapabilities.mock.calls[0]?.[1];- expect(capabilitiesSignal).toBe(metadataSignal);+ expect(actions.getImageRecallCapabilities).not.toHaveBeenCalled();await renderFooter({ isOpen: false, item: imageItem });expect(metadataSignal.aborted).toBe(true);- expect(capabilitiesSignal?.aborted).toBe(true);await interact(() => {metadata.resolve(null);- capabilities.resolve(ALL_RECALL_CAPABILITIES);}, 0);});@@ -401,6 +398,24 @@ describe('Preview query-driven Details', () => {await interact(() => getButton('Recall All').click());expect(actions.recallImageData).toHaveBeenCalledWith(actionImage, 'all');});++ it('updates recall buttons when capability inputs change without refetching cached metadata', async () => {+ galleryMocks.imageMetadata.mockResolvedValueOnce({ positive_prompt: 'cached prompt' });++ await renderFooter({ isOpen: true, item: imageItem });+ await act(async () => {+ await vi.waitFor(() => expect(getButton('Recall All').disabled).toBe(false));+ });++ actions = {+ ...actions,+ deriveImageRecallCapabilities: vi.fn(() => NO_RECALL_CAPABILITIES),+ } as unknown as ImageActions;+ await renderFooter({ isOpen: true, item: imageItem });++ expect(getButton('Recall All').disabled).toBe(true);+ expect(galleryMocks.imageMetadata).toHaveBeenCalledOnce();+ });});const getButton = (text: string): HTMLButtonElement => {diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrameVideo.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrameVideo.browser.test.tsxindex 2842facbd5..9748597342 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrameVideo.browser.test.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrameVideo.browser.test.tsx@@ -55,20 +55,15 @@ const videoSource: VideoSource = {kind: 'video' as const,label: 'Video clip.mp4',poster: 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="9"/>',- src: 'data:video/mp4;base64,AAAA',+ src: 'data:audio/wav;base64,UklGRiUAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQEAAACA',};+const invalidVideoSource: VideoSource = { ...videoSource, src: 'data:video/mp4;base64,AAAA' };let host: HTMLDivElement | null = null;let root: Root | null = null;let onDragStart = vi.fn();(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;-const suppressNativeMediaError = (event: Event): void => {- if (event.isTrusted && event.target instanceof HTMLMediaElement) {- event.stopImmediatePropagation();- }-};-const interact = (action: () => void, delay = 0): Promise<void> =>act(async () => {action();@@ -130,9 +125,6 @@ beforeEach(() => {onDragStart = vi.fn();host = document.createElement('div');host.style.cssText = 'height:320px;left:20px;position:fixed;top:20px;width:480px;';- // The deliberately invalid data URL may fail at any time under browser-suite- // load. Recovery tests dispatch deterministic, untrusted error events.- host.addEventListener('error', suppressNativeMediaError, true);document.body.append(host);root = createRoot(host);});@@ -199,6 +191,32 @@ describe('PreviewFrame native video arm', () => {expect(document.body.textContent).not.toContain('Drop to compare');});+ it('lets a trusted browser media error enter protected-media recovery', async () => {+ const trustedErrors: Event[] = [];+ const recordTrustedMediaError = (event: Event): void => {+ if (event.isTrusted && event.target instanceof HTMLMediaElement) {+ trustedErrors.push(event);+ }+ };+ document.addEventListener('error', recordTrustedMediaError, true);+ identityMocks.refreshProtectedMediaCookie.mockResolvedValueOnce(false);++ try {+ await renderVideo(() => true, invalidVideoSource);+ await act(async () => {+ await vi.waitFor(+ () => {+ expect(trustedErrors.length).toBeGreaterThan(0);+ expect(identityMocks.refreshProtectedMediaCookie).toHaveBeenCalledOnce();+ },+ { timeout: 5_000 }+ );+ });+ } finally {+ document.removeEventListener('error', recordTrustedMediaError, true);+ }+ });+it('refreshes the protected-media cookie once and reloads after the first media failure', async () => {const refresh = deferred<boolean>();identityMocks.refreshProtectedMediaCookie.mockReturnValueOnce(refresh.promise);@@ -314,7 +332,6 @@ describe('PreviewFrame native video arm', () => {...videoSource,itemKey: 'video:next.mp4' as const,label: 'Video next.mp4',- src: 'data:video/mp4;base64,BBBB',};await renderVideo(() => true, nextSource);const nextVideo = getVideo();@@ -514,17 +531,6 @@ const renderVideo = async (videoControllerRef?: Ref<PreviewVideoFrameController>,onCopyAvailabilityChange?: (itemKey: GalleryItemKey, isAvailable: boolean) => void): Promise<void> => {- if (videoControllerRef) {- // The intentionally invalid data URL may emit a browser media error. Copy- // tests exercise the frame controller, not protected-media recovery, so- // keep that unrelated async branch pending and silent.- identityMocks.refreshProtectedMediaCookie.mockReturnValue(- new Promise<boolean>(() => {- // Intentionally pending for this render's lifetime.- })- );- }-await interact(() => {root?.render(<I18nextProvider i18n={i18n}>diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewMetadataPanel.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewMetadataPanel.tsxindex 3173775c91..7141a74d10 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewMetadataPanel.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewMetadataPanel.tsx@@ -80,7 +80,6 @@ export const PreviewMetadataPanel = ({type PreviewDetailsData =| {- capabilities: ImageRecallCapabilities;kind: 'image';metadata: GalleryImageMetadata | null;}@@ -109,15 +108,12 @@ const PreviewDetailsQuery = ({queryFn: async ({ signal }): Promise<PreviewDetailsData> => {if (item.kind === 'image') {if (!image) {- return { capabilities: EMPTY_IMAGE_RECALL_CAPABILITIES, kind: 'image', metadata: null };+ return { kind: 'image', metadata: null };}- const [metadata, capabilities] = await Promise.all([- galleryImages.metadata(item.name, signal),- actions.getImageRecallCapabilities(image, signal),- ]);+ const metadata = await galleryImages.metadata(item.name, signal);- return { capabilities, kind: 'image', metadata };+ return { kind: 'image', metadata };}const [metadata, workflow] = await Promise.all([@@ -152,11 +148,13 @@ const PreviewDetailsQuery = ({}const details = isImageDetails(detailsQuery.data) ? detailsQuery.data : null;+ const capabilities =+ image && details ? actions.deriveImageRecallCapabilities(image, details.metadata) : EMPTY_IMAGE_RECALL_CAPABILITIES;return (<ImageDetailsactions={actions}- capabilities={details?.capabilities ?? EMPTY_IMAGE_RECALL_CAPABILITIES}+ capabilities={capabilities}image={image}isLoading={detailsQuery.isPending}metadata={details?.metadata ?? null}