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): show indexing activity behind a queued label rebuild

Lincoln Stein414f45347bf6
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.json
index 6b3b71026c..f99b331698 100644
--- a/invokeai/frontend/webv2/public/locales/en.json
+++ b/invokeai/frontend/webv2/public/locales/en.json
@@ -1426,6 +1426,7 @@
"noTermsYet": "No supplementary terms yet. The built-in vocabulary is still used.",
"count": "{{count}} of {{max}} supplementary terms",
"rebuilding": "Updating cluster labels with the new vocabulary…",
+ "rebuildingQueued": "Waiting for image indexing to finish ({{progress}}) before updating cluster labels…",
"buildFailed": "The vocabulary could not be prepared: {{message}}",
"indexOff": "The image index is not running. Terms are saved and will apply when it is next enabled.",
"saveFailed": "Could not save the vocabulary.",
diff --git a/invokeai/frontend/webv2/src/workbench/settings/ImageMapVocabularySettings.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/settings/ImageMapVocabularySettings.browser.test.tsx
index 0019ccac93..4130975708 100644
--- a/invokeai/frontend/webv2/src/workbench/settings/ImageMapVocabularySettings.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/settings/ImageMapVocabularySettings.browser.test.tsx
@@ -10,6 +10,8 @@ import { userEvent } from 'vitest/browser';
const mocks = vi.hoisted(() => ({
canManage: true,
+ indexCounts: null as { total: number; embedded: number; pending: number; failed: number } | null,
+ refreshImageIndexStatus: vi.fn(),
updateImageMapVocab: vi.fn((_terms: string[]) => Promise.resolve(null as unknown as ImageMapVocab)),
vocab: null as ImageMapVocab | null,
}));
@@ -18,6 +20,14 @@ vi.mock('@features/identity', () => ({
useCapabilities: () => ({ canManageImageMapVocabulary: mocks.canManage }),
}));
+vi.mock('@workbench/image-map/imageMapStore', () => ({
+ imageMapStore: {
+ useSelector: (selector: (snapshot: object) => unknown) =>
+ selector({ indexCounts: mocks.indexCounts, indexUpdatedAt: null }),
+ },
+ refreshImageIndexStatus: () => mocks.refreshImageIndexStatus(),
+}));
+
vi.mock('@workbench/image-map/vocabulary', () => ({
imageMapVocabKeys: { all: ['image-map', 'vocab'] },
imageMapVocabQueryOptions: () => ({
@@ -45,6 +55,7 @@ vi.mock('react-i18next', () => ({
'settings.imageMapVocabulary.loadFailed': 'Could not load the vocabulary.',
'settings.imageMapVocabulary.noTermsYet': 'No supplementary terms yet.',
'settings.imageMapVocabulary.rebuilding': 'Updating cluster labels with the new vocabulary…',
+ 'settings.imageMapVocabulary.rebuildingQueued': `Waiting for image indexing to finish (${String(options?.progress)}) before updating cluster labels…`,
'settings.imageMapVocabulary.removeTerm': `Remove ${String(options?.term)}`,
'settings.imageMapVocabulary.saveFailed': 'Could not save the vocabulary.',
'settings.imageMapVocabulary.termTooLong': `Terms must be ${String(options?.max)} characters or fewer.`,
@@ -98,6 +109,8 @@ const chipCloseTriggers = (): HTMLElement[] =>
beforeEach(() => {
mocks.canManage = true;
+ mocks.indexCounts = null;
+ mocks.refreshImageIndexStatus.mockClear();
mocks.updateImageMapVocab.mockClear();
queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } });
host = document.createElement('div');
@@ -176,6 +189,35 @@ describe('ImageMapVocabularySettings', () => {
expect(mocks.updateImageMapVocab).toHaveBeenCalledWith(['zebra']);
});
+ it('explains that the rebuild is queued behind image indexing', async () => {
+ // The rebuild runs on the index worker only once it has no images left to
+ // embed, so during a backfill the spinner can stand for as long as the
+ // backfill does. Without the counts it reads as a hang.
+ mocks.indexCounts = { embedded: 1204, failed: 0, pending: 16846, total: 18050 };
+ await render({ state: 'building', terms: ['zebra'] });
+
+ expect(host?.textContent).toContain('Waiting for image indexing to finish (1,204 of 18,050 images)');
+ expect(host?.textContent).not.toContain('Updating cluster labels with the new vocabulary…');
+ // The panel may be opened mid-run with no status event due.
+ expect(mocks.refreshImageIndexStatus).toHaveBeenCalled();
+ });
+
+ it('says only that labels are updating when the index is idle', async () => {
+ mocks.indexCounts = { embedded: 18050, failed: 0, pending: 0, total: 18050 };
+ await render({ state: 'building', terms: ['zebra'] });
+
+ expect(host?.textContent).toContain('Updating cluster labels with the new vocabulary…');
+ expect(host?.textContent).not.toContain('Waiting for image indexing');
+ });
+
+ it('does not poll index status when no rebuild is running', async () => {
+ mocks.indexCounts = { embedded: 1204, failed: 0, pending: 16846, total: 18050 };
+ await render({ state: 'ready', terms: ['zebra'] });
+
+ expect(mocks.refreshImageIndexStatus).not.toHaveBeenCalled();
+ expect(host?.textContent).not.toContain('Waiting for image indexing');
+ });
+
it('shows a read-only list to a non-admin', async () => {
mocks.canManage = false;
await render({ terms: ['zebra'] });
diff --git a/invokeai/frontend/webv2/src/workbench/settings/ImageMapVocabularySettings.tsx b/invokeai/frontend/webv2/src/workbench/settings/ImageMapVocabularySettings.tsx
index e7896a2134..00903afdc7 100644
--- a/invokeai/frontend/webv2/src/workbench/settings/ImageMapVocabularySettings.tsx
+++ b/invokeai/frontend/webv2/src/workbench/settings/ImageMapVocabularySettings.tsx
@@ -1,4 +1,5 @@
/* eslint-disable react-perf/jsx-no-new-function-as-prop */
+import type { ImageIndexCounts } from '@workbench/image-map/indexProgress';
import type { ImageMapVocab } from '@workbench/image-map/vocabulary';
import { HStack, Icon, Input, Spinner, Stack, Tag, Text, Wrap } from '@chakra-ui/react';
@@ -8,11 +9,21 @@ import { assertAccountScopeCurrent } from '@platform/state/accountLifecycle';
import { getApiErrorMessage } from '@platform/transport/http';
import { Button, Field } from '@platform/ui';
import { useQuery, useQueryClient } from '@tanstack/react-query';
+import { imageMapStore, refreshImageIndexStatus } from '@workbench/image-map/imageMapStore';
+import { describeIndexProgress, isIndexing } from '@workbench/image-map/indexProgress';
import { imageMapVocabKeys, imageMapVocabQueryOptions, updateImageMapVocab } from '@workbench/image-map/vocabulary';
import { PlusIcon } from 'lucide-react';
-import { useState } from 'react';
+import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
+/**
+ * How often the index counts are re-read while a rebuild is queued behind one.
+ * Coarse on purpose: it only feeds a "waiting for indexing" line, and the
+ * backend pushes `image_index_status` per batch anyway — this exists so the
+ * line is right when the panel is opened mid-run with no event due.
+ */
+const INDEX_STATUS_POLL_MS = 5_000;
+
/**
* Normalize one draft entry the way the server will, so the chips a save adds
* are exactly the chips that come back. Splitting on commas and newlines makes
@@ -56,6 +67,22 @@ export const ImageMapVocabularySettings = () => {
const [inputError, setInputError] = useState<string | null>(null);
const [saveError, setSaveError] = useState<string | null>(null);
const { isBusy: isSaving, run } = useScopedAction();
+ // The rebuild runs on the index worker, which services it only once it has
+ // no images left to embed — so during a backfill the spinner can stand for
+ // as long as the backfill does. The counts turn that into a stated wait.
+ const indexCounts = imageMapStore.useSelector((snapshot) => snapshot.indexCounts);
+ const isBuilding = query.data?.state === 'building';
+
+ useEffect(() => {
+ if (!isBuilding) {
+ return;
+ }
+
+ refreshImageIndexStatus();
+ const timer = setInterval(refreshImageIndexStatus, INDEX_STATUS_POLL_MS);
+
+ return () => clearInterval(timer);
+ }, [isBuilding]);
const persist = (nextTerms: string[]): Promise<boolean> => {
setSaveError(null);
@@ -230,6 +257,7 @@ export const ImageMapVocabularySettings = () => {
</Text>
)}
<VocabularyStatusLine
+ indexCounts={indexCounts}
vocab={vocab}
onRetry={
canManageImageMapVocabulary
@@ -245,8 +273,25 @@ export const ImageMapVocabularySettings = () => {
);
};
-const VocabularyStatusLine = ({ onRetry, vocab }: { onRetry?: () => void; vocab: ImageMapVocab }) => {
+const VocabularyStatusLine = ({
+ indexCounts,
+ onRetry,
+ vocab,
+}: {
+ indexCounts: ImageIndexCounts | null;
+ onRetry?: () => void;
+ vocab: ImageMapVocab;
+}) => {
const { t } = useTranslation();
+ // Embedding a handful of terms takes seconds; a wait longer than that means
+ // the rebuild is queued behind image indexing, not running slowly. Saying
+ // which is the difference between "working" and "hung".
+ //
+ // No age is passed, so no "no progress reported for N" note: that needs a
+ // clock ticking in render, which the compiler rightly refuses, and the whole
+ // stall treatment already exists on the map widget where the counts live. A
+ // stalled index shows up here as a number that stops moving.
+ const progress = isIndexing(indexCounts) ? describeIndexProgress(indexCounts) : null;
return (
<Stack gap="1">
@@ -257,7 +302,9 @@ const VocabularyStatusLine = ({ onRetry, vocab }: { onRetry?: () => void; vocab:
<HStack gap="1.5">
<Spinner size="xs" />
<Text color="fg.subtle" fontSize="2xs">
- {t('settings.imageMapVocabulary.rebuilding')}
+ {progress
+ ? t('settings.imageMapVocabulary.rebuildingQueued', { progress: progress.counts })
+ : t('settings.imageMapVocabulary.rebuilding')}
</Text>
</HStack>
) : null}
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageIndexProgress.tsx b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageIndexProgress.tsx
index 0b5d71fae8..8a8d669a38 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageIndexProgress.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageIndexProgress.tsx
@@ -1,6 +1,6 @@
import type { ImageIndexCounts } from '@workbench/image-map/indexProgress';
-import { Button, HStack, Progress, Stack, Text } from '@chakra-ui/react';
+import { Box, Button, HStack, Progress, Stack, Text } from '@chakra-ui/react';
import { Tooltip } from '@platform/ui';
import { describeIndexProgress } from '@workbench/image-map/indexProgress';
import { useEffect, useState } from 'react';
@@ -112,6 +112,68 @@ export const ImageIndexProgressPanel = ({
);
};
+/**
+ * The same progress as a badge laid over the map itself.
+ *
+ * The panel above is only reachable when there is nothing to draw, so on a
+ * gallery that already has a map — the case for every re-index, including the
+ * automatic one after the embedding model changes — the view drew the old
+ * points and said nothing at all about the work in flight. The footer's line
+ * is 2xs chrome and renders only once `state === 'ready'`, so it is not that
+ * signal either.
+ *
+ * Overlaid rather than substituted: the stale map is still worth using while
+ * the new one is built, so this must not take the panel over. It also names
+ * the labels, which disappear for the duration whenever the vocabulary
+ * embeddings are being rebuilt (a model change, or a supplementary-vocabulary
+ * edit) — that silence was the other half of the map looking broken.
+ */
+export const ImageIndexActivityBadge = ({ counts, updatedAt }: ImageIndexProgressProps) => {
+ const progress = describeIndexProgress(counts, useCountsAge(updatedAt));
+ const label = progress.stale
+ ? `Indexing ${progress.counts} · ${progress.stale}`
+ : `Indexing ${progress.counts}. The map and its cluster labels update as images finish.`;
+
+ return (
+ // The wrapper spans the plot so the badge can sit in its corner, and passes
+ // every pointer event through: the plot underneath is drag-panned and
+ // wheel-zoomed across its whole area, and a full-width transparent layer
+ // that swallowed those would cost more than the badge is worth. The badge
+ // itself takes its events back so the tooltip still opens.
+ <Box inset="0" pointerEvents="none" position="absolute" zIndex="1">
+ <Tooltip content={label}>
+ <HStack
+ bg="bg.subtle"
+ borderColor="border.subtle"
+ borderRadius="md"
+ borderWidth="1px"
+ color="fg.muted"
+ fontSize="2xs"
+ gap="1.5"
+ insetStart="2"
+ maxW="calc(100% - 1rem)"
+ minW="0"
+ pointerEvents="auto"
+ position="absolute"
+ px="2"
+ py="1"
+ title={label}
+ top="2"
+ >
+ <Progress.Root flexShrink="0" max={100} size="xs" value={progress.percent} w="10">
+ <Progress.Track aria-label={`${PROGRESS_LABEL}: ${label}`} aria-valuenow={progress.percent}>
+ <Progress.Range />
+ </Progress.Track>
+ </Progress.Root>
+ <Text fontVariantNumeric="tabular-nums" truncate>
+ indexing {progress.compact}
+ </Text>
+ </HStack>
+ </Tooltip>
+ </Box>
+ );
+};
+
/**
* The same progress in one line, for the widget footer once the map itself is
* on screen: the bar is the glanceable part, the rest is one hover away rather
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetView.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetView.browser.test.tsx
index d385d81638..a81cd6f2ec 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetView.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetView.browser.test.tsx
@@ -11,6 +11,10 @@ vi.mock('@workbench/WorkbenchContext', () => ({
useWidgetValuesSelector: () => false,
}));
+// The real one pulls the ~1.5MB plotly chunk; the badge under test is its
+// sibling, not its child, so a stand-in is enough.
+vi.mock('./ImageMapPlot', () => ({ default: () => <div data-testid="plot" /> }));
+
vi.mock('@workbench/image-map/imageMapStore', async (importOriginal) => {
const original = (await importOriginal()) as object;
@@ -95,3 +99,85 @@ describe('Image Map unavailable states', () => {
expect(host?.querySelector('button')?.textContent).toBe('Retry');
});
});
+
+describe('Image Map indexing activity', () => {
+ const renderMapWithCounts = async (
+ counts: { total: number; embedded: number; pending: number; failed: number } | null
+ ) => {
+ imageMapStore.setSnapshot({
+ clusterLabels: null,
+ data: {
+ clusterEps: null,
+ modelName: null,
+ pointCount: 2,
+ points: [
+ { cluster: 0, imageName: 'a.png', x: 0, y: 0 },
+ { cluster: 0, imageName: 'b.png', x: 1, y: 1 },
+ ],
+ stale: false,
+ state: 'ready',
+ updatedAt: '2026-08-24T01:00:00',
+ visibleHash: 'hash',
+ },
+ error: null,
+ indexCounts: counts,
+ indexUpdatedAt: counts ? Date.now() : null,
+ loadState: 'loaded',
+ renderError: null,
+ });
+
+ await act(() =>
+ root?.render(
+ <ChakraProvider value={system}>
+ <ImageMapWidgetView {...({} as WidgetViewProps)} />
+ </ChakraProvider>
+ )
+ );
+ // The plot is `lazy()`, so the first render in the file waits on the
+ // dynamic import and then on the re-render Suspense schedules once it
+ // resolves. Polled rather than flushed a fixed number of times: the badge
+ // has to be asserted against the resolved tree, not the fallback.
+ for (let attempt = 0; attempt < 50 && !host?.querySelector('[data-testid="plot"]'); attempt += 1) {
+ await act(async () => {
+ await new Promise((resolve) => {
+ setTimeout(resolve, 10);
+ });
+ });
+ }
+ };
+
+ it('reports an index run over the map instead of drawing it silently', async () => {
+ // The has-points branch preempts the progress panel, which is right — a
+ // usable stale map beats a progress bar — but it used to do so with no
+ // sign that anything was happening, which is what a model-change re-index
+ // looks like from the panel: the old map, no labels, no explanation.
+ await renderMapWithCounts({ embedded: 1204, failed: 0, pending: 16846, total: 18050 });
+
+ expect(host?.querySelector('[data-testid="plot"]')).not.toBeNull();
+ expect(host?.textContent).toContain('indexing 1,204/18,050');
+ // The map stays: the badge must not replace it.
+ expect(host?.textContent).not.toContain('Indexing images');
+ });
+
+ it('names the labels in the badge, since they vanish while the vocabulary rebuilds', async () => {
+ await renderMapWithCounts({ embedded: 1204, failed: 0, pending: 16846, total: 18050 });
+
+ const progressbar = host?.querySelector('[role="progressbar"]');
+
+ expect(progressbar?.getAttribute('aria-label')).toContain('cluster labels update as images finish');
+ });
+
+ it('shows no badge once the index is idle', async () => {
+ await renderMapWithCounts({ embedded: 18050, failed: 0, pending: 0, total: 18050 });
+
+ expect(host?.querySelector('[data-testid="plot"]')).not.toBeNull();
+ expect(host?.textContent).not.toContain('indexing');
+ });
+
+ it('shows no badge when the counts are absent, as for a non-admin', async () => {
+ await renderMapWithCounts(null);
+
+ expect(host?.querySelector('[data-testid="plot"]')).not.toBeNull();
+ expect(host?.textContent).not.toContain('indexing');
+ });
+});
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetView.tsx b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetView.tsx
index 90338d65a7..26dc7cf2f0 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetView.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetView.tsx
@@ -1,6 +1,6 @@
import type { WidgetViewProps } from '@workbench/widgetContracts';
-import { Button, Center, Spinner, Stack, Text } from '@chakra-ui/react';
+import { Box, Button, Center, Spinner, Stack, Text } from '@chakra-ui/react';
import { getImageMapClickSelectsCluster, getImageMapShowClusterLabels } from '@workbench/image-map/imageMapSettings';
import {
ensureImageMapLoaded,
@@ -13,7 +13,7 @@ import { isIndexing } from '@workbench/image-map/indexProgress';
import { useWidgetValuesSelector } from '@workbench/WorkbenchContext';
import { lazy, Suspense, useEffect } from 'react';
-import { ImageIndexProgressPanel } from './ImageIndexProgress';
+import { ImageIndexActivityBadge, ImageIndexProgressPanel } from './ImageIndexProgress';
// Lazy so the plotly bundle (its own vite chunk, ~1.5MB) loads only when the
// widget is actually shown.
@@ -81,9 +81,16 @@ export const ImageMapWidgetView = (_props: WidgetViewProps) => {
// already-loaded map suspended anyway. Confining it here keeps the frame
// mounted and the spinner where the plot will appear.
return (
- <Suspense fallback={plotLoadingFallback}>
- <ImageMapPlot clickSelectsCluster={clickSelectsCluster} showClusterLabels={showClusterLabels} />
- </Suspense>
+ // Positioned so the indexing badge can overlay the plot. That badge is
+ // the only sign of an index run once there are points to draw: this
+ // branch preempts the progress panel below, which is right — a usable
+ // stale map beats a progress bar — but silently, which was not.
+ <Box h="full" position="relative" w="full">
+ <Suspense fallback={plotLoadingFallback}>
+ <ImageMapPlot clickSelectsCluster={clickSelectsCluster} showClusterLabels={showClusterLabels} />
+ </Suspense>
+ {isIndexing(indexCounts) ? <ImageIndexActivityBadge counts={indexCounts} updatedAt={indexUpdatedAt} /> : null}
+ </Box>
);
}