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
Merge remote-tracking branch 'origin/main' into diag/image-map-clustering
Lincoln Stein642fac7442c4
diff --cc invokeai/frontend/webv2/src/workbench/image-map/imageMap.test.tsindex c9627354b2,f62d9360dc..828754502a--- a/invokeai/frontend/webv2/src/workbench/image-map/imageMap.test.ts+++ b/invokeai/frontend/webv2/src/workbench/image-map/imageMap.test.ts@@@ -775,11 -685,9 +756,10 @@@ describe('snapshot transitions', () =>});it('clears a render failure on a successful refresh so the plot can retry', () => {- // Without this the WebGL error is permanent for the session: the view stops- // mounting the plot, and nothing else ever resets renderError.+ // Retry must clear renderError so a transient WebGL failure can remount the plot.imageMapStore.setSnapshot({clusterLabels: null,+ clusterLabelsEps: null,clusterLabelsHash: null,data: null,error: null,diff --cc invokeai/frontend/webv2/src/workbench/image-map/imageMapStore.tsindex fb6c3a07c1,fc12af49d2..9e3a5ab46f--- a/invokeai/frontend/webv2/src/workbench/image-map/imageMapStore.ts+++ b/invokeai/frontend/webv2/src/workbench/image-map/imageMapStore.ts@@@ -35,31 -25,13 +25,21 @@@ export interface ImageMapSnapshot/** Cluster id -> automatic label info; null when unavailable (e.g. no text encoder). */clusterLabels: Record<string, ImageMapClusterLabelInfo> | null;/**- * The visible-set fingerprint `clusterLabels` were computed over, so a- * consumer can tell whether they still describe the drawn clustering.- *- * Labels lag their points by a request: a refresh replaces `data` while the- * previous clustering's labels are still in the store, and DBSCAN can- * renumber every cluster between the two. Annotations have always accepted- * that lag (clearing them on each refresh would blink every label off and- * back on), but a consumer making a stronger promise — the hover card names- * one specific cluster — compares this against `data.visibleHash` and shows- * nothing rather than another cluster's tags.+ * Fingerprint of the visible set used for cluster labels. Labels may lag refreshed points whose cluster ids+ * changed; precise consumers such as hover cards require equality with `data.visibleHash`.*/clusterLabelsHash: string | null;+ /**+ * The eps `clusterLabels` were clustered at. The visible-set hash alone+ * stopped being enough once the strength became adjustable: changing it+ * renumbers every cluster while the projection and the visible set — and+ * so `visibleHash` — stay exactly the same, which would let the previous+ * strength's tags be shown against the new clustering for a round trip.+ */+ clusterLabelsEps: number | null;/**- * The plot canvas itself failed (WebGL unavailable). Distinct from `error`,- * which means a fetch failed: with `error` the cached points are still worth- * showing, whereas here there is nothing that can draw them, so the view must- * stop mounting the plot and say so.+ * Plot/WebGL failure differs from fetch failure: cached points remain useful after fetch errors, but render+ * errors require unmounting the plot and reporting inability to draw.*/renderError: string | null;}@@@ -91,12 -62,7 +71,11 @@@ registerAccountOwnedResource(clear: () => {inflight = null;rerunRequested = false;+ // Per-project widget state, so it must not survive into the next+ // account: the widget pushes the new one down when it mounts, but a+ // socket-driven refresh could beat it there.+ clusterEps = null;- // Orphan any in-flight labels request so its completion (or failure)- // cannot touch the next account's labels.+ // Retire label requests so old-account completion/failure cannot update the new account.labelsSequence += 1;statusInflight = null;indexEventSequence += 1;@@@ -105,40 -71,10 +84,39 @@@name: 'image-map',});+/**+ * The eps the clustering-strength control has been set to, or null for the+ * server's adaptive value. Pushed down from the widget rather than passed by+ * callers: every refresh — socket-driven, manual, or the first load — has to+ * cluster at the strength the user chose, and only this module sees them all.+ */+let clusterEps: number | null = null;++export const setClusterEps = (eps: number | null): void => {+ if (eps === clusterEps) {+ return;+ }++ clusterEps = eps;++ // The labels in the store describe the previous strength's cluster ids, and+ // the refresh below will not move `visibleHash`, so nothing else retires+ // them.+ imageMapStore.patchSnapshot({ clusterLabels: null, clusterLabelsEps: null, clusterLabelsHash: null });++ // Nothing has been fetched yet, so the first fetch will carry the new value+ // on its own; refreshing here would race it for no gain.+ if (imageMapStore.getSnapshot().loadState === 'idle') {+ return;+ }++ void refreshImageMapPoints();+};+export const refreshImageMapPoints = (): Promise<void> => {if (inflight) {- // A refresh requested mid-flight (e.g. projection_ready arriving while- // the fetch that triggered the recompute is still running) must not be- // swallowed by the dedup: run once more when the current fetch settles.+ // Coalesce mid-flight refresh requests into one rerun after settling instead of swallowing them through+ // dedupe.rerunRequested = true;return inflight;diff --cc invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapPlot.tsxindex dc5111cdd6,8cee93fe3c..768c7e8d78--- a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapPlot.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapPlot.tsx@@@ -123,20 -113,12 +113,15 @@@ const ImageMapPlot = (const containerRef = useRef<HTMLDivElement | null>(null);const points = imageMapStore.useSelector((snapshot) => snapshot.data?.points ?? null);const clusterLabels = imageMapStore.useSelector((snapshot) => snapshot.clusterLabels);- // Whether those labels were computed over the clustering now drawn. The- // annotations accept a stale set for the ~1s until fresh ones land (see the- // relayout effect below), but the hover card names one specific cluster by- // id, and a refresh can renumber every id — so it shows no tags rather than- // another cluster's.+ // Require matching clustering for hover tags: refresh may renumber ids even while stale annotations remain+ // briefly visible.const clusterLabelsMatchPoints = imageMapStore.useSelector(- (snapshot) => snapshot.clusterLabelsHash !== null && snapshot.clusterLabelsHash === snapshot.data?.visibleHash+ (snapshot) =>+ snapshot.clusterLabelsHash !== null &&+ snapshot.clusterLabelsHash === snapshot.data?.visibleHash &&+ snapshot.clusterLabelsEps === snapshot.data?.clusterEps);- // The primary selection as an item key: a selected video is marked on the- // map like any other item, and the key is a string so the refs and the- // recenter comparisons below stay plain equality checks.+ // Use item keys for selection/recentering equality, including videos.const selectedKey = useWidgetValuesSelector('gallery', (values) => {const item = getSelectedGalleryItemFromValues(values);diff --cc invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetFooter.tsxindex 17b513f2f1,d935ec745a..d032cfaef5--- a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetFooter.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetFooter.tsx@@@ -10,35 -8,16 +10,25 @@@ import { useMemo } from 'react'import { ImageIndexProgressInline } from './ImageIndexProgress';+/** Stable identity for the pre-`ready` renders, so the memo below never re-runs on null. */+const NO_POINTS: never[] = [];+const handleRefresh = () => {void refreshImageMapPoints();- // The counts too: this footer is the surface that shows them once the map- // exists, and counts left stale by a status event missed while offline are- // exactly what its refresh should be able to correct.+ // Refresh counts too, recovering final status events missed while offline.refreshImageIndexStatus();};- /**- * Widget-chrome footer: point count, how those points clustered, a stale hint- * while a recompute is pending, embedding-index progress (admins only receive- * those events), and a manual refresh.- */export const ImageMapWidgetFooter = (_props: WidgetViewProps) => {const { data, indexCounts, indexUpdatedAt, loadState } = imageMapStore.useSnapshot();+ // Before the early return, and keyed on the array the store swaps wholesale.+ // The footer re-renders on every index-progress tick, and those patch other+ // snapshot keys and leave `data` identity intact — so the count runs once per+ // points refresh rather than once per tick, which matters at 170k points.+ const points = data?.points ?? NO_POINTS;+ const clusterSummary = useMemo(() => describeClusters(summarizeClusters(points)), [points]);- // Only the states that actually show a map. `disabled`, `model_missing` and- // `empty` all carry data too, and each renders its own explanation — a- // "0 points" line with a Refresh button under "Image indexing is off" says- // nothing, and `computing` already offers its own "Check again".+ // Show footer controls only with a rendered map; other data states own their explanations and retry controls.if (loadState === 'idle' || !data || data.state !== 'ready') {return null;}diff --cc invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetView.browser.test.tsxindex 8a01ccea79,e001df6c96..0c19781ad6--- 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@@@ -8,20 -8,12 +8,16 @@@ import { createRoot, type Root } from 'import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';vi.mock('@workbench/WorkbenchContext', () => ({- useWidgetValuesSelector: () => false,+ // Applied to an empty value bag rather than answering `false` to every+ // selector: each accessor owns its own default, and handing a boolean to a+ // setting that is a number or null makes the widget act on a value it could+ // never be given in production.+ useWidgetValuesSelector: (_widgetId: string, select: (values: Record<string, unknown>) => unknown) => select({}),}));- // 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.+ // Stub the heavy Plotly sibling; this test owns the progress badge.vi.mock('./ImageMapPlot', () => ({ default: () => <div data-testid="plot" /> }));- // The install link resolves the configured encoder against the starter- // catalog and queues it; both come from the models feature, so the catalog is- // pinned here and the queueing spied on.const models = vi.hoisted(() => {// A real subscribable store, like the one behind `useActiveInstallSources`:// putting the encoder into (and out of) an in-flight install has to re-render