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(image-map): resolve review findings on the clustering-strength control

Lincoln Stein1f38cfa1b57d
diff --git a/invokeai/app/api/routers/image_map.py b/invokeai/app/api/routers/image_map.py
index e72004b1e7..7e1799eee7 100644
--- a/invokeai/app/api/routers/image_map.py
+++ b/invokeai/app/api/routers/image_map.py
@@ -124,7 +124,9 @@ ClusterEpsQuery = Query(
ge=MIN_BUDGETED_EPS,
le=2.0,
description="DBSCAN eps for clustering. Defaults to an adaptive value derived from the projection's "
- "k-distance distribution. Clamped server-side relative to the projection's coordinate span.",
+ "k-distance distribution; that default is clamped relative to the coordinate span, a supplied value is "
+ "not. Either way it is reduced if needed to keep DBSCAN's neighbourhoods inside a memory budget, and "
+ "the value actually used is returned as `cluster_eps`.",
)
ClusterMinSamplesQuery = Query(
default=DEFAULT_CLUSTER_MIN_SAMPLES, ge=2, le=100, description="DBSCAN min_samples for clustering"
diff --git a/invokeai/app/services/image_index/projection.py b/invokeai/app/services/image_index/projection.py
index 049fd51827..8667140c11 100644
--- a/invokeai/app/services/image_index/projection.py
+++ b/invokeai/app/services/image_index/projection.py
@@ -152,8 +152,8 @@ def _top_cluster_share(coords: np.ndarray, eps: float, min_samples: int) -> floa
from sklearn.neighbors import KDTree
if coords.shape[0] > 1:
- pairs = int(KDTree(coords).query_radius(coords, r=eps, count_only=True).sum())
- if pairs > MAX_NEIGHBOR_PAIRS:
+ tree = KDTree(coords)
+ if _count_neighbor_pairs(tree, coords, eps, MAX_NEIGHBOR_PAIRS) > MAX_NEIGHBOR_PAIRS:
return 1.0
labels = DBSCAN(eps=eps, min_samples=min_samples).fit(coords).labels_
@@ -234,6 +234,32 @@ MAX_NEIGHBOR_PAIRS = 50_000_000
MIN_BUDGETED_EPS = 1e-6
+# Query points per chunk when counting neighbor pairs. The count only has to
+# answer "is this over the budget?", and an eps far above it blows past the
+# budget within the first chunk — so chunking turns the expensive probes into
+# a fixed small cost while an under-budget eps still gets an exact full count.
+# Without it, resolving a requested eps of 2.0 on a dense 150k-point map took
+# 50s of CPU: thirteen full passes counting billions of pairs, only to reject
+# every one of them.
+_PAIR_COUNT_CHUNK = 4096
+
+
+def _count_neighbor_pairs(tree, coords: np.ndarray, eps: float, cap: int) -> int:
+ """Neighbor pairs at eps, abandoned once the count passes `cap`.
+
+ Exact whenever the result is within the cap, which is the only case a
+ caller acts on the number itself; above it the return is a lower bound.
+ """
+ total = 0
+ for start in range(0, coords.shape[0], _PAIR_COUNT_CHUNK):
+ chunk = coords[start : start + _PAIR_COUNT_CHUNK]
+ total += int(tree.query_radius(chunk, r=eps, count_only=True).sum())
+ if total > cap:
+ break
+
+ return total
+
+
def _shrink_eps_to_pair_budget(coords: np.ndarray, eps: float) -> tuple[float, Optional[int]]:
"""Shrink eps until DBSCAN's neighbor-pair count fits MAX_NEIGHBOR_PAIRS.
@@ -250,13 +276,13 @@ def _shrink_eps_to_pair_budget(coords: np.ndarray, eps: float) -> tuple[float, O
from sklearn.neighbors import KDTree
tree = KDTree(coords)
- pairs = int(tree.query_radius(coords, r=eps, count_only=True).sum())
+ pairs = _count_neighbor_pairs(tree, coords, eps, MAX_NEIGHBOR_PAIRS)
# Iterate until the budget is met rather than a fixed count: 12 rounds of
# 0.7 only covers a 71x reduction, and a tight blob can need far more.
# Bounded below by MIN_BUDGETED_EPS so a fully coincident map terminates.
while pairs > MAX_NEIGHBOR_PAIRS and eps > MIN_BUDGETED_EPS:
eps *= 0.7
- pairs = int(tree.query_radius(coords, r=eps, count_only=True).sum())
+ pairs = _count_neighbor_pairs(tree, coords, eps, MAX_NEIGHBOR_PAIRS)
return eps, pairs
diff --git a/invokeai/frontend/webv2/src/workbench/image-map/clusterEps.test.ts b/invokeai/frontend/webv2/src/workbench/image-map/clusterEps.test.ts
index 610bb3bf6f..05282d5558 100644
--- a/invokeai/frontend/webv2/src/workbench/image-map/clusterEps.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/image-map/clusterEps.test.ts
@@ -23,6 +23,10 @@ describe('getImageMapClusterEps', () => {
expect(getImageMapClusterEps({ clusterEps: Infinity })).toBeNull();
expect(getImageMapClusterEps({ clusterEps: '0.2' })).toBeNull();
expect(getImageMapClusterEps({ clusterEps: MIN_CLUSTER_EPS / 2 })).toBeNull();
+ // And the high side: the endpoint caps eps at 2.0, so a larger stored
+ // value 422s every refresh and strands the map on an error.
+ expect(getImageMapClusterEps({ clusterEps: MAX_CLUSTER_EPS + 1 })).toBeNull();
+ expect(getImageMapClusterEps({ clusterEps: 1000 })).toBeNull();
});
it('keeps the bounds the control and the endpoint agree on', () => {
diff --git a/invokeai/frontend/webv2/src/workbench/image-map/imageMap.test.ts b/invokeai/frontend/webv2/src/workbench/image-map/imageMap.test.ts
index 3e238c80ad..c9627354b2 100644
--- a/invokeai/frontend/webv2/src/workbench/image-map/imageMap.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/image-map/imageMap.test.ts
@@ -29,6 +29,7 @@ import {
recordImageIndexStatus,
refreshImageIndexStatus,
refreshImageMapPoints,
+ setClusterEps,
} from './imageMapStore';
import {
ALL_POINTS_TRACE,
@@ -135,6 +136,7 @@ describe('image map store', () => {
mocks.apiFetchJson.mockReset();
imageMapStore.setSnapshot({
clusterLabels: null,
+ clusterLabelsEps: null,
clusterLabelsHash: null,
data: null,
error: null,
@@ -150,6 +152,74 @@ describe('image map store', () => {
vi.useRealTimers();
});
+ it('clusters at the chosen strength on every later refresh', async () => {
+ // The strength is module state rather than a call argument precisely so
+ // that socket-driven refreshes carry it too; nothing else would.
+ mockPointsWithForeignLabels();
+ await refreshImageMapPoints();
+ setClusterEps(0.25);
+ await Promise.resolve();
+ await refreshImageMapPoints();
+
+ const pointsCalls = mocks.apiFetchJson.mock.calls
+ .map((call) => String(call[0]))
+ .filter((url) => url.startsWith('/api/v1/image_map/points'));
+
+ expect(pointsCalls[0]).not.toContain('eps=');
+ expect(pointsCalls.at(-1)).toContain('eps=0.25');
+
+ setClusterEps(null);
+ await Promise.resolve();
+ await refreshImageMapPoints();
+
+ const afterClearing = mocks.apiFetchJson.mock.calls
+ .map((call) => String(call[0]))
+ .filter((url) => url.startsWith('/api/v1/image_map/points'))
+ .at(-1);
+
+ expect(afterClearing).not.toContain('eps=');
+ setClusterEps(null);
+ });
+
+ it('refetches when the strength changes, and retires the old labels', async () => {
+ // Changing eps renumbers every cluster while the projection and the
+ // visible set stay put, so `visibleHash` cannot detect it: labels left in
+ // the store would be shown against a clustering they do not describe.
+ mocks.apiFetchJson.mockImplementation((url: string) =>
+ url.startsWith('/api/v1/image_map/cluster_labels')
+ ? Promise.resolve({
+ labels: { '0': { label: 'boats' } },
+ updated_at: '2026-08-02 12:00:00',
+ visible_hash: 'hash-1',
+ })
+ : Promise.resolve(BACKEND_RESPONSE)
+ );
+
+ await refreshImageMapPoints();
+ await Promise.resolve();
+ await Promise.resolve();
+ expect(imageMapStore.getSnapshot().clusterLabels).not.toBeNull();
+ expect(imageMapStore.getSnapshot().clusterLabelsEps).toBe(0.42);
+
+ const before = mocks.apiFetchJson.mock.calls.length;
+ setClusterEps(0.3);
+
+ expect(imageMapStore.getSnapshot().clusterLabels).toBeNull();
+ expect(imageMapStore.getSnapshot().clusterLabelsEps).toBeNull();
+ expect(mocks.apiFetchJson.mock.calls.length).toBeGreaterThan(before);
+ setClusterEps(null);
+ });
+
+ it('does not refetch for a strength that is already in force', async () => {
+ mockPointsWithForeignLabels();
+ await refreshImageMapPoints();
+ const before = mocks.apiFetchJson.mock.calls.length;
+
+ setClusterEps(null);
+
+ expect(mocks.apiFetchJson.mock.calls.length).toBe(before);
+ });
+
it('loads points into the snapshot', async () => {
mockPointsWithForeignLabels();
@@ -676,6 +746,7 @@ describe('snapshot transitions', () => {
// starts at null; seed a real error first so the clearing is what is tested.
imageMapStore.setSnapshot({
clusterLabels: null,
+ clusterLabelsEps: null,
clusterLabelsHash: null,
data: null,
error: 'boom',
@@ -708,6 +779,7 @@ describe('snapshot transitions', () => {
// mounting the plot, and nothing else ever resets renderError.
imageMapStore.setSnapshot({
clusterLabels: null,
+ clusterLabelsEps: null,
clusterLabelsHash: null,
data: null,
error: null,
@@ -729,6 +801,7 @@ const drainMacrotask = (): Promise<void> =>
const EMPTY_SNAPSHOT = {
clusterLabels: null,
+ clusterLabelsEps: null,
clusterLabelsHash: null,
data: null,
error: null,
diff --git a/invokeai/frontend/webv2/src/workbench/image-map/imageMapSettings.ts b/invokeai/frontend/webv2/src/workbench/image-map/imageMapSettings.ts
index 0c89ce3be5..e3ccc21dc6 100644
--- a/invokeai/frontend/webv2/src/workbench/image-map/imageMapSettings.ts
+++ b/invokeai/frontend/webv2/src/workbench/image-map/imageMapSettings.ts
@@ -23,5 +23,9 @@ export const MAX_CLUSTER_EPS = 2;
export const getImageMapClusterEps = (values: Record<string, unknown>): number | null => {
const raw = values.clusterEps;
- return typeof raw === 'number' && Number.isFinite(raw) && raw >= MIN_CLUSTER_EPS ? raw : null;
+ // Bounded at BOTH ends against the endpoint's own range. A persisted value
+ // outside it — an imported project, a hand-edited file, a future change to
+ // the bounds — is sent on every refresh and 422s each one, leaving the map
+ // stuck on an error with no way back through the UI.
+ return typeof raw === 'number' && raw >= MIN_CLUSTER_EPS && raw <= MAX_CLUSTER_EPS ? raw : null;
};
diff --git a/invokeai/frontend/webv2/src/workbench/image-map/imageMapStore.ts b/invokeai/frontend/webv2/src/workbench/image-map/imageMapStore.ts
index 30f0fef094..fb6c3a07c1 100644
--- a/invokeai/frontend/webv2/src/workbench/image-map/imageMapStore.ts
+++ b/invokeai/frontend/webv2/src/workbench/image-map/imageMapStore.ts
@@ -47,6 +47,14 @@ export interface ImageMapSnapshot {
* nothing rather than another cluster's tags.
*/
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
@@ -58,6 +66,7 @@ export interface ImageMapSnapshot {
const EMPTY_IMAGE_MAP_SNAPSHOT: ImageMapSnapshot = {
clusterLabels: null,
+ clusterLabelsEps: null,
clusterLabelsHash: null,
data: null,
error: null,
@@ -82,6 +91,10 @@ 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.
labelsSequence += 1;
@@ -107,6 +120,11 @@ export const setClusterEps = (eps: number | null): void => {
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') {
@@ -222,7 +240,7 @@ export const setClusterLabelsEnabled = (enabled: boolean): void => {
if (!enabled) {
// Bump the sequence so a request already in flight cannot land after this.
labelsSequence += 1;
- imageMapStore.patchSnapshot({ clusterLabels: null, clusterLabelsHash: null });
+ imageMapStore.patchSnapshot({ clusterLabels: null, clusterLabelsEps: null, clusterLabelsHash: null });
return;
}
@@ -284,7 +302,11 @@ const attemptClusterLabels = (sequence: number, data: ImageMapPoints, attempt: n
}
if (!areLabelMapsEqual(current.clusterLabels, response.labels)) {
- imageMapStore.patchSnapshot({ clusterLabels: response.labels, clusterLabelsHash: response.visibleHash });
+ imageMapStore.patchSnapshot({
+ clusterLabels: response.labels,
+ clusterLabelsEps: data.clusterEps,
+ clusterLabelsHash: response.visibleHash,
+ });
}
})
.catch((error: unknown) => {
@@ -295,7 +317,7 @@ const attemptClusterLabels = (sequence: number, data: ImageMapPoints, attempt: n
return;
}
- imageMapStore.patchSnapshot({ clusterLabels: null, clusterLabelsHash: null });
+ imageMapStore.patchSnapshot({ clusterLabels: null, clusterLabelsEps: null, clusterLabelsHash: null });
if (attempt >= LABELS_RETRY_DELAYS_MS.length || !isRetryableLabelsFailure(error)) {
return;
@@ -325,7 +347,7 @@ const refreshClusterLabels = (data: ImageMapPoints): void => {
// sequence so an in-flight labels response cannot repopulate the labels
// this clears.
labelsSequence += 1;
- imageMapStore.patchSnapshot({ clusterLabels: null, clusterLabelsHash: null });
+ imageMapStore.patchSnapshot({ clusterLabels: null, clusterLabelsEps: null, clusterLabelsHash: null });
return;
}
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ClusterStrengthField.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ClusterStrengthField.browser.test.tsx
index 4b0bd90ca1..8676c738fa 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ClusterStrengthField.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ClusterStrengthField.browser.test.tsx
@@ -75,6 +75,7 @@ const field = imageMapSettingsContribution.fields.find((entry) => entry.id === '
const render = async (resolved: number | null) => {
imageMapStore.setSnapshot({
clusterLabels: null,
+ clusterLabelsEps: null,
clusterLabelsHash: null,
data: {
clusterEps: resolved,
@@ -138,7 +139,7 @@ describe('ClusterStrengthField', () => {
it('shows the strength the server derived, marked as not the user’s', async () => {
await render(0.0945);
- expect(spinner().value).toBe('0.095');
+ expect(spinner().value).toBe('0.0945');
expect(autoBadgeShown()).toBe(true);
expect(host?.textContent).toContain('Higher values create larger clusters');
});
@@ -167,7 +168,7 @@ describe('ClusterStrengthField', () => {
expect(settings.patch).toHaveBeenCalledWith({ clusterEps: null });
// And the box refills with the derived value rather than staying empty.
- expect(spinner().value).toBe('0.095');
+ expect(spinner().value).toBe('0.0945');
expect(autoBadgeShown()).toBe(true);
});
@@ -204,6 +205,75 @@ describe('ClusterStrengthField', () => {
expect(settings.patch).toHaveBeenCalledWith({ clusterEps: 0.15 });
});
+ it('refills the box when cleared from the heuristic it was already on', async () => {
+ // Nothing was chosen, so committing null changes no state and the sync
+ // effect never fires. Without an explicit refill the box sits empty while
+ // the map clusters at a strength the control is no longer showing.
+ await render(0.0945);
+
+ await userEvent.clear(spinner());
+ await settle();
+
+ expect(settings.patch).toHaveBeenCalledWith({ clusterEps: null });
+ expect(spinner().value).toBe('0.0945');
+ expect(autoBadgeShown()).toBe(true);
+ });
+
+ it('does not leave the refilled heuristic for the next keystroke to append to', async () => {
+ // Clearing refills the box with the derived value — while the caret is
+ // still in it. Without selecting the refilled text, typing "0.5" next
+ // lands "0.09450.5" and the map reclusters at a number nobody chose.
+ await render(0.0945);
+ await userEvent.fill(spinner(), '0.25');
+ await settle();
+ settings.patch.mockClear();
+
+ spinner().focus();
+ await userEvent.clear(spinner());
+ await settle();
+ expect(spinner().value).toBe('0.0945');
+
+ await userEvent.type(spinner(), '0.5');
+ await settle();
+
+ expect(settings.patch).toHaveBeenLastCalledWith({ clusterEps: 0.5 });
+ expect(spinner().value).toBe('0.5');
+ });
+
+ it('keeps every digit of a value with more precision than the box shows', async () => {
+ // forDisplay trims to three significant digits. Rewriting the box with
+ // the trimmed value would delete the keystroke that produced it.
+ await render(0.0945);
+
+ await userEvent.fill(spinner(), '0.1234');
+ await settle();
+
+ expect(settings.patch).toHaveBeenCalledWith({ clusterEps: 0.1234 });
+ expect(spinner().value).toBe('0.1234');
+ });
+
+ it('commits an edit the dialog closes on top of', async () => {
+ await render(0.0945);
+ await userEvent.fill(spinner(), '0.25');
+
+ // Unmounted inside the debounce window, which is what closing the
+ // settings dialog does if the field never blurs.
+ await act(() => root?.unmount());
+ root = null;
+
+ expect(settings.patch).toHaveBeenCalledWith({ clusterEps: 0.25 });
+ });
+
+ it('commits an edit the user clicks away from', async () => {
+ await render(0.0945);
+ await userEvent.fill(spinner(), '0.25');
+ await act(() => {
+ spinner().blur();
+ });
+
+ expect(settings.patch).toHaveBeenCalledWith({ clusterEps: 0.25 });
+ });
+
it('refuses a strength the endpoint would reject', async () => {
await render(0.0945);
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ClusterStrengthField.tsx b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ClusterStrengthField.tsx
index 10c6c1aa13..6d5936d0e3 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ClusterStrengthField.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ClusterStrengthField.tsx
@@ -20,8 +20,13 @@ const COMMIT_DEBOUNCE_MS = 500;
const DIALOG_DIRECTION = { base: 'column', md: 'row' } as const;
const DIALOG_ALIGNMENT = { base: 'stretch', md: 'center' } as const;
-/** Trims the heuristic's float to something a 0.01 spinner can step from. */
-const forDisplay = (eps: number): string => String(Number(eps.toFixed(3)));
+/**
+ * Trims the heuristic's float to something a spinner can step from. Three
+ * significant digits rather than three decimals: the endpoint reports values
+ * as small as 1e-6 (the pair budget's floor on a near-coincident map) and
+ * asks for them back, and `toFixed(3)` renders every one of those as "0".
+ */
+const forDisplay = (eps: number): string => String(Number(eps.toPrecision(3)));
/**
* "Clustering strength" — the DBSCAN eps, as a number the user can nudge.
@@ -37,11 +42,16 @@ export const ClusterStrengthField = ({ field, surface, target }: SettingFieldPro
const { disabled, patch, value: chosen } = useWidgetSettingsTarget('image-map', target, getImageMapClusterEps);
// What the server actually clustered with, which is the heuristic's answer
// whenever nothing has been chosen.
- const resolved = imageMapStore.useSnapshot().data?.clusterEps ?? null;
+ // Only this one field of the snapshot: the footer's index counts tick about
+ // once a second during a backfill, and none of that concerns this control.
+ const resolved = imageMapStore.useSelector((snapshot) => snapshot.data?.clusterEps ?? null);
const shown = chosen ?? resolved;
const [invalid, setInvalid] = useState<string | null>(null);
const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
const pending = useRef(false);
+ // Read by the unmount cleanup, which cannot see the render's closure.
+ const flush = useRef<(() => void) | null>(null);
+ const resolvedRef = useRef<number | null>(null);
// Uncontrolled on purpose. A controlled `value` driven from the element
// would erase exactly the input this field has to tolerate: `type="number"`
// reports "" for a half-typed "0.", so React would write that "" straight
@@ -50,30 +60,70 @@ export const ClusterStrengthField = ({ field, surface, target }: SettingFieldPro
// number from a deliberately cleared box.
const input = useRef<HTMLInputElement | null>(null);
+ /**
+ * Writes the box, selecting it when the caret is inside — otherwise the
+ * next keystroke appends to a number the user did not type.
+ */
+ const show = useCallback((eps: number | null) => {
+ const field = input.current;
+
+ if (!field) {
+ return;
+ }
+
+ field.value = eps === null ? '' : forDisplay(eps);
+
+ if (document.activeElement === field) {
+ field.select();
+ }
+ }, []);
+
const commit = useCallback(
(eps: number | null) => {
pending.current = false;
patch({ clusterEps: eps });
+
+ if (eps === null) {
+ // Refilled from here rather than left to the sync effect below:
+ // clearing a field that was already on the heuristic changes no
+ // state at all, so that effect would never run and the box would sit
+ // empty. A committed number needs no write — the box already holds
+ // exactly what was typed, to more digits than forDisplay keeps.
+ show(resolvedRef.current);
+ }
},
- [patch]
+ [patch, show]
);
+ useEffect(() => {
+ resolvedRef.current = resolved;
+ }, [resolved]);
+
// Anything arriving from outside — a recluster's resolved value, another
// surface changing the setting — must not move the number under the
- // cursor, so it waits until the edit has settled.
+ // cursor, so it is skipped while an edit is in flight. Skipped, not
+ // queued: an update landing mid-edit is dropped, and the box catches up on
+ // the next keystroke or on blur, both of which rewrite it from `shown`.
+ // Skipped too when the box already holds this number, since rewriting it
+ // through forDisplay would truncate a value typed to more digits than it
+ // keeps.
useEffect(() => {
- if (pending.current || !input.current) {
+ if (pending.current || !input.current || Number(input.current.value) === shown) {
return;
}
setInvalid(null);
- input.current.value = shown === null ? '' : forDisplay(shown);
- }, [shown]);
+ show(shown);
+ }, [show, shown]);
+ // Flushed rather than dropped: the settings dialog can close without the
+ // field ever blurring, and an edit made and then dismissed should still
+ // take effect.
useEffect(
() => () => {
if (timer.current !== null) {
clearTimeout(timer.current);
+ flush.current?.();
}
},
[]
@@ -133,6 +183,7 @@ export const ClusterStrengthField = ({ field, surface, target }: SettingFieldPro
clearTimeout(timer.current);
}
+ flush.current = () => resolve(value, validity.badInput);
timer.current = setTimeout(() => resolve(value, validity.badInput), COMMIT_DEBOUNCE_MS);
},
[resolve]
@@ -152,11 +203,8 @@ export const ClusterStrengthField = ({ field, surface, target }: SettingFieldPro
pending.current = false;
setInvalid(null);
-
- if (input.current) {
- input.current.value = shown === null ? '' : forDisplay(shown);
- }
- }, [resolve, shown]);
+ show(shown);
+ }, [resolve, show, shown]);
const label = resolveSettingsText(field.label, t);
const description = field.description ? resolveSettingsText(field.description, t) : undefined;
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapDataRuntime.test.ts b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapDataRuntime.test.ts
index 2cd3231c1f..2d75ebfa28 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapDataRuntime.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapDataRuntime.test.ts
@@ -41,6 +41,7 @@ describe('attachImageMapDataRuntime', () => {
mocks.getAuthSession.mockReset().mockReturnValue({ user: null });
imageMapStore.setSnapshot({
clusterLabels: null,
+ clusterLabelsEps: null,
clusterLabelsHash: null,
data: null,
error: null,
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapPlot.tsx b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapPlot.tsx
index 505ffd3de4..dc5111cdd6 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapPlot.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapPlot.tsx
@@ -129,7 +129,10 @@ const ImageMapPlot = ({
// id, and a refresh can renumber every id — so it shows no tags rather than
// another cluster's.
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
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetFooter.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetFooter.browser.test.tsx
index 8d053339ca..a8dc12abe1 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetFooter.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetFooter.browser.test.tsx
@@ -32,6 +32,7 @@ const CROWDED = { embedded: 123456, failed: 12, pending: 60544, total: 184012 };
const renderFooter = async (clusters: number[], width?: string, crowded = false) => {
imageMapStore.setSnapshot({
clusterLabels: null,
+ clusterLabelsEps: null,
clusterLabelsHash: null,
data: {
clusterEps: 0.2,
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 15dfc48b03..8a01ccea79 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
@@ -124,6 +124,7 @@ const dataFor = (
const renderState = async (state: Extract<ImageMapState, 'disabled' | 'model_missing'>, modelName?: string) => {
imageMapStore.setSnapshot({
clusterLabels: null,
+ clusterLabelsEps: null,
clusterLabelsHash: null,
data: dataFor(state, modelName),
error: null,
@@ -311,6 +312,7 @@ describe('Image Map indexing activity', () => {
) => {
imageMapStore.setSnapshot({
clusterLabels: null,
+ clusterLabelsEps: null,
clusterLabelsHash: null,
data: {
clusterEps: null,