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
feat(webv2): track install transfer rates and local queue dismissals
Josh Corbett3278aa5538b3
diff --git a/invokeai/frontend/webv2/src/features/models/data/installsStore.test.ts b/invokeai/frontend/webv2/src/features/models/data/installsStore.test.tsindex 02a6e08025..fe1f653ecc 100644--- a/invokeai/frontend/webv2/src/features/models/data/installsStore.test.ts+++ b/invokeai/frontend/webv2/src/features/models/data/installsStore.test.ts@@ -32,7 +32,7 @@ describe('model install event interpretation', () => {const store = await import('./installsStore');store.handleModelInstallSocketEvent('model_install_download_progress', { bytes: 25, id: 7, total_bytes: 100 });- expect(store.getInstallProgress(7)).toEqual({ bytes: 25, totalBytes: 100 });+ expect(store.getInstallProgress(7)).toEqual({ bytes: 25, bytesPerSecond: null, totalBytes: 100 });store.handleModelInstallSocketEvent('model_install_complete', { config: {}, id: 7, source: 'org/model' });@@ -50,7 +50,7 @@ describe('model install event interpretation', () => {});expect(store.getInstallsSnapshot().jobs[0]?.status).toBe('downloading');- expect(store.getInstallProgress(7)).toEqual({ bytes: 25, totalBytes: 100 });+ expect(store.getInstallProgress(7)).toEqual({ bytes: 25, bytesPerSecond: null, totalBytes: 100 });store.handleModelInstallSocketEvent('model_install_started', { id: 7 });store.handleModelInstallSocketEvent('model_install_download_started', { id: 7 });@@ -114,14 +114,19 @@ describe('model install event interpretation', () => {accountLifecycle.invalidate();- expect(store.getInstallsSnapshot()).toEqual({ error: null, jobs: [], status: 'idle' });+ expect(store.getInstallsSnapshot()).toEqual({ dismissedJobIds: new Set(), error: null, jobs: [], status: 'idle' });const currentRefresh = store.refreshInstalls();first.resolve([{ id: 1, source: 'old/account', status: 'waiting' }]);await staleRefresh;- expect(store.getInstallsSnapshot()).toEqual({ error: null, jobs: [], status: 'loading' });+ expect(store.getInstallsSnapshot()).toEqual({+ dismissedJobIds: new Set(),+ error: null,+ jobs: [],+ status: 'loading',+ });expect(store.refreshInstalls()).toBe(currentRefresh);expect(dependencies.listModelInstalls).toHaveBeenCalledTimes(2);@@ -131,6 +136,7 @@ describe('model install event interpretation', () => {expect(dependencies.listModelInstalls).toHaveBeenCalledTimes(3);expect(store.getInstallsSnapshot()).toEqual({+ dismissedJobIds: new Set(),error: null,jobs: [{ id: 2, source: 'new/account', status: 'waiting' }],status: 'loaded',@@ -179,6 +185,7 @@ describe('model install event interpretation', () => {store.ensureInstallsLoaded();await vi.advanceTimersByTimeAsync(0);expect(store.getInstallsSnapshot()).toEqual({+ dismissedJobIds: new Set(),error: null,jobs: [{ id: 1, source: 'org/model', status: 'waiting' }],status: 'loaded',@@ -199,7 +206,7 @@ describe('model install event interpretation', () => {);expect(store.getInstallProgress(7)).toBeNull();- expect(store.getInstallsSnapshot()).toEqual({ error: null, jobs: [], status: 'idle' });+ expect(store.getInstallsSnapshot()).toEqual({ dismissedJobIds: new Set(), error: null, jobs: [], status: 'idle' });});});@@ -223,3 +230,40 @@ describe('getInstallSourceLabel', () => {expect(store.getInstallSourceLabel(42)).toBe('model');});});++describe('install queue presentation state', () => {+ it('smooths a transfer rate from spaced progress samples', async () => {+ const store = await import('./installsStore');++ store.handleModelInstallSocketEvent('model_install_download_progress', { bytes: 0, id: 7, total_bytes: 1000 });+ vi.advanceTimersByTime(100);+ store.handleModelInstallSocketEvent('model_install_download_progress', { bytes: 50, id: 7, total_bytes: 1000 });+ // Too soon for a second sample: the rate stays unknown rather than spiking.+ expect(store.getInstallProgress(7)?.bytesPerSecond).toBeNull();++ vi.advanceTimersByTime(900);+ store.handleModelInstallSocketEvent('model_install_download_progress', { bytes: 500, id: 7, total_bytes: 1000 });+ expect(store.getInstallProgress(7)?.bytesPerSecond).toBe(500);++ vi.advanceTimersByTime(1000);+ store.handleModelInstallSocketEvent('model_install_download_progress', { bytes: 600, id: 7, total_bytes: 1000 });+ expect(store.getInstallProgress(7)?.bytesPerSecond).toBe(500 * 0.7 + 100 * 0.3);+ });++ it('keeps dismissed jobs hidden only while the backend still lists them', async () => {+ const store = await import('./installsStore');++ dependencies.listModelInstalls.mockResolvedValue([+ { id: 1, source: 'a', status: 'completed' },+ { id: 2, source: 'b', status: 'error' },+ ]);+ await store.refreshInstalls();+ store.dismissInstallJob(1);+ store.dismissInstallJob(2);+ expect([...store.getInstallsSnapshot().dismissedJobIds]).toEqual([1, 2]);++ dependencies.listModelInstalls.mockResolvedValue([{ id: 2, source: 'b', status: 'error' }]);+ await store.refreshInstalls();+ expect([...store.getInstallsSnapshot().dismissedJobIds]).toEqual([2]);+ });+});diff --git a/invokeai/frontend/webv2/src/features/models/data/installsStore.ts b/invokeai/frontend/webv2/src/features/models/data/installsStore.tsindex 020d751e02..dba945b8b2 100644--- a/invokeai/frontend/webv2/src/features/models/data/installsStore.ts+++ b/invokeai/frontend/webv2/src/features/models/data/installsStore.ts@@ -24,11 +24,15 @@ export interface InstallsSnapshot {jobs: ModelInstallJob[];status: 'idle' | 'loading' | 'loaded' | 'error';error: string | null;+ /** Settled jobs hidden locally; the backend only prunes all finished jobs at once. */+ dismissedJobIds: ReadonlySet<number>;}export interface InstallDownloadProgress {bytes: number;totalBytes: number;+ /** Smoothed transfer rate; null until two spaced samples exist. */+ bytesPerSecond: number | null;}/** A just-settled install, surfaced so the UI can toast success/failure. */@@ -68,8 +72,16 @@ export const getInstallSourceLabel = (source: unknown): string => {const REFRESH_COALESCE_MS = 250;// Bound display history with room for completion bursts between toast flushes.const OUTCOME_LIMIT = 64;--const EMPTY_INSTALLS_SNAPSHOT: InstallsSnapshot = { error: null, jobs: [], status: 'idle' };+const RATE_SAMPLE_MS = 500;+const RATE_SMOOTHING = 0.3;++const EMPTY_DISMISSED_IDS: ReadonlySet<number> = new Set();+const EMPTY_INSTALLS_SNAPSHOT: InstallsSnapshot = {+ dismissedJobIds: EMPTY_DISMISSED_IDS,+ error: null,+ jobs: [],+ status: 'idle',+};const EMPTY_INSTALL_OUTCOMES: { outcomes: InstallOutcome[] } = { outcomes: [] };const store = createExternalStore<InstallsSnapshot>(EMPTY_INSTALLS_SNAPSHOT);@@ -77,6 +89,7 @@ const outcomesStore = createExternalStore<{ outcomes: InstallOutcome[] }>(EMPTY_let nextOutcomeId = 1;const progressByJobId = createKeyedTransientStore<number, InstallDownloadProgress>();+const rateSamplesByJobId = new Map<number, { bytes: number; at: number }>();const refreshFlight = createTrailingSingleFlight();let refreshTimer: ReturnType<typeof setTimeout> | null = null;@@ -97,6 +110,7 @@ registerAccountOwnedResource({refreshFlight.reset();nextOutcomeId = 1;progressByJobId.clear();+ rateSamplesByJobId.clear();outcomesStore.setSnapshot(EMPTY_INSTALL_OUTCOMES);store.setSnapshot(EMPTY_INSTALLS_SNAPSHOT);},@@ -118,10 +132,20 @@ export const refreshInstalls = (owner: AccountScope = captureAccountScope()): Prfor (const [jobId] of progressByJobId.entries()) {if (!activeJobIds.has(jobId)) {progressByJobId.delete(jobId);+ rateSamplesByJobId.delete(jobId);}}- store.patchSnapshot({ error: null, jobs, status: 'loaded' });+ const { dismissedJobIds } = store.getSnapshot();+ const retainedDismissed = [...dismissedJobIds].filter((jobId) => activeJobIds.has(jobId));++ store.patchSnapshot({+ dismissedJobIds:+ retainedDismissed.length === dismissedJobIds.size ? dismissedJobIds : new Set(retainedDismissed),+ error: null,+ jobs,+ status: 'loaded',+ });}).catch((error: unknown) => {if (!isAccountScopeCurrent(owner)) {@@ -180,6 +204,15 @@ export const replaceInstallJob = (job: ModelInstallJob): void => {});};+/** Hide a settled job locally until the backend stops listing it. */+export const dismissInstallJob = (jobId: number): void => {+ const { dismissedJobIds } = store.getSnapshot();++ if (!dismissedJobIds.has(jobId)) {+ store.patchSnapshot({ dismissedJobIds: new Set([...dismissedJobIds, jobId]) });+ }+};+/** Optimistically add a freshly created job so the queue updates instantly. */export const addInstallJob = (job: ModelInstallJob): void => {if (store.getSnapshot().jobs.some((existing) => existing.id === job.id)) {@@ -218,6 +251,30 @@ const recordOutcome = (outcome: Omit<InstallOutcome, 'id'>): void => {nextOutcomeId += 1;};+/** Exponential smoothing over spaced samples keeps the rate readable through bursty progress ticks. */+const sampleTransferRate = (jobId: number, bytes: number): number | null => {+ const now = Date.now();+ const previous = rateSamplesByJobId.get(jobId);+ const current = progressByJobId.get(jobId)?.bytesPerSecond ?? null;++ if (!previous) {+ rateSamplesByJobId.set(jobId, { at: now, bytes });+ return current;+ }++ const elapsedMs = now - previous.at;++ if (elapsedMs < RATE_SAMPLE_MS) {+ return current;+ }++ rateSamplesByJobId.set(jobId, { at: now, bytes });++ const instant = Math.max(0, ((bytes - previous.bytes) * 1000) / elapsedMs);++ return current === null ? instant : current * (1 - RATE_SMOOTHING) + instant * RATE_SMOOTHING;+};+interface ModelInstallSocketPayload {id: number;bytes?: number;@@ -257,7 +314,13 @@ export const handleModelInstallSocketEvent = (}if (event === 'model_install_download_progress') {- progressByJobId.set(data.id, { bytes: data.bytes ?? 0, totalBytes: data.total_bytes ?? 0 });+ const bytes = data.bytes ?? 0;++ progressByJobId.set(data.id, {+ bytes,+ bytesPerSecond: sampleTransferRate(data.id, bytes),+ totalBytes: data.total_bytes ?? 0,+ });const job = store.getSnapshot().jobs.find((candidate) => candidate.id === data.id);@@ -277,6 +340,7 @@ export const handleModelInstallSocketEvent = (if (event === 'model_install_complete' || event === 'model_install_error' || event === 'model_install_cancelled') {// Retain settled jobs until cleared, but release their inactive byte-progress state.progressByJobId.delete(data.id);+ rateSamplesByJobId.delete(data.id);}if (event === 'model_install_complete') {diff --git a/invokeai/frontend/webv2/src/features/models/ui/uiStore.ts b/invokeai/frontend/webv2/src/features/models/ui/uiStore.tsindex 04733c9a8c..6771671f19 100644--- a/invokeai/frontend/webv2/src/features/models/ui/uiStore.ts+++ b/invokeai/frontend/webv2/src/features/models/ui/uiStore.ts@@ -37,6 +37,8 @@ export interface ModelsUiSnapshot {selectedBundleName: string | null;/** Whether the always-visible install queue footer is expanded. */queueExpanded: boolean;+ /** Whether the expanded queue fills the detail pane instead of docking as a footer. */+ queueMaximized: boolean;/** Scroll offsets per library-list instance, restored on remount. */libraryScrollOffsets: Record<string, number>;/** Compact/full row density per picker id, remembered across opens. */@@ -57,6 +59,7 @@ const createInitialModelsUiSnapshot = (): ModelsUiSnapshot => ({pickerBaseFilters: {},pickerCompactViews: {},queueExpanded: false,+ queueMaximized: false,scan: null,selectedBundleName: null,selectedKeys: new Set(),@@ -96,19 +99,21 @@ export const pruneModelsUiKeys = (deletedKeys: string[]): void => {});};+// Revealing a tab must also restore the pane a maximized queue is covering.+/** Jump the model manager's detail pane to a specific tab. */export const openModelManagerTab = (activeTab: ModelManagerTab): void => {- updateModelsUi({ activeTab });+ updateModelsUi({ activeTab, queueMaximized: false });};/** Focus a model and reveal it in the detail tab (e.g. from a library row). */export const openModelDetail = (modelKey: string): void => {- updateModelsUi({ activeModelKey: modelKey, activeTab: 'details' });+ updateModelsUi({ activeModelKey: modelKey, activeTab: 'details', queueMaximized: false });};/** Name the requested provider so its possibly offscreen key card can reveal itself. */export const openExternalProviderKeys = (providerId: string): void => {- updateModelsUi({ activeTab: 'keys', highlightProviderId: providerId });+ updateModelsUi({ activeTab: 'keys', highlightProviderId: providerId, queueMaximized: false });};/** Consumes the pending highlight so it fires once per request. */@@ -118,7 +123,13 @@ export const clearHighlightedProvider = (): void => {/** Clear scan/repo results when opening a bundle because those panels otherwise hide it. */export const openAddModelsWithBundle = (bundleName: string): void => {- updateModelsUi({ activeTab: 'add', hfLookup: null, scan: null, selectedBundleName: bundleName });+ updateModelsUi({+ activeTab: 'add',+ hfLookup: null,+ queueMaximized: false,+ scan: null,+ selectedBundleName: bundleName,+ });};/**@@ -131,6 +142,7 @@ export const requestAddModelsSearch = (query: string): void => {addModelsSeed: query,addModelsTypeSeed: null,hfLookup: null,+ queueMaximized: false,scan: null,selectedBundleName: null,});@@ -143,6 +155,7 @@ export const requestAddModelsTypeFilter = (typeFilter: ModelTaxonomyType): voidaddModelsSeed: null,addModelsTypeSeed: typeFilter,hfLookup: null,+ queueMaximized: false,scan: null,selectedBundleName: null,});@@ -172,6 +185,10 @@ export const setQueueExpanded = (queueExpanded: boolean): void => {updateModelsUi({ queueExpanded });};+export const setQueueMaximized = (queueMaximized: boolean): void => {+ updateModelsUi({ queueMaximized });+};+export const saveLibraryScrollOffset = (instanceId: string, offset: number): void => {const snapshot = store.getSnapshot();