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(webv2): stop a stale save acknowledgement reporting library work as saved
joshistoast2fdd1750080b
diff --git a/invokeai/frontend/webv2/performance/architecture-baseline.json b/invokeai/frontend/webv2/performance/architecture-baseline.jsonindex 126311ccc2..fb6ca3d769 100644--- a/invokeai/frontend/webv2/performance/architecture-baseline.json+++ b/invokeai/frontend/webv2/performance/architecture-baseline.json@@ -2,10 +2,10 @@"build": {"launchpad": {"baseline": {- "brotliBytes": 832098,+ "brotliBytes": 832122,"cssRawBytes": 2159,"fontRawBytes": 219480,- "gzipBytes": 831918,+ "gzipBytes": 831926,"imageRawBytes": 156376,"initialRawBytes": 1933595,"largestAssetRawBytes": 746305,@@ -280,10 +280,10 @@]},"limits": {- "brotliBytes": 840419,+ "brotliBytes": 840444,"cssRawBytes": 2181,"fontRawBytes": 221675,- "gzipBytes": 840238,+ "gzipBytes": 840246,"imageRawBytes": 157940,"initialRawBytes": 1952931,"largestAssetRawBytes": 753769,@@ -298,10 +298,10 @@},"editor": {"baseline": {- "brotliBytes": 1029170,+ "brotliBytes": 1029263,"cssRawBytes": 2159,"fontRawBytes": 219480,- "gzipBytes": 1026506,+ "gzipBytes": 1026531,"imageRawBytes": 156376,"initialRawBytes": 2524449,"largestAssetRawBytes": 746305,@@ -828,10 +828,10 @@]},"limits": {- "brotliBytes": 1039462,+ "brotliBytes": 1039556,"cssRawBytes": 2181,"fontRawBytes": 221675,- "gzipBytes": 1036772,+ "gzipBytes": 1036797,"imageRawBytes": 157940,"initialRawBytes": 2549694,"largestAssetRawBytes": 753769,diff --git a/invokeai/frontend/webv2/performance/browser-baseline.json b/invokeai/frontend/webv2/performance/browser-baseline.jsonindex 3c55a00bc6..880f29b3cc 100644--- a/invokeai/frontend/webv2/performance/browser-baseline.json+++ b/invokeai/frontend/webv2/performance/browser-baseline.json@@ -25,11 +25,11 @@"scriptRequestCount": 0,"totalRawBytes": 0},- "domContentLoadedMedianMs": 116.10000000149012,+ "domContentLoadedMedianMs": 114.39999999850988,"id": "launchpad","layoutSwitchMedianMs": 0,- "loadMedianMs": 116.10000000149012,- "longestTaskMaxMs": 70,+ "loadMedianMs": 114.39999999850988,+ "longestTaskMaxMs": 74,"owner": "app","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:launchpad",@@ -56,7 +56,7 @@"scriptRequestCount": 32,"totalRawBytes": 1784521},- "routeReadyMedianMs": 250.79999999701977,+ "routeReadyMedianMs": 255.90000000596046,"scriptSourceOwnerSet": "launchpad-static","stateProfile": "empty"},@@ -83,11 +83,11 @@"scriptRequestCount": 0,"totalRawBytes": 0},- "domContentLoadedMedianMs": 115,+ "domContentLoadedMedianMs": 112.10000000149012,"id": "launchpad","layoutSwitchMedianMs": 0,- "loadMedianMs": 115.10000000149012,- "longestTaskMaxMs": 91,+ "loadMedianMs": 112.10000000149012,+ "longestTaskMaxMs": 68,"owner": "app","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:launchpad",@@ -114,7 +114,7 @@"scriptRequestCount": 32,"totalRawBytes": 1784521},- "routeReadyMedianMs": 266.20000000298023,+ "routeReadyMedianMs": 267.40000000596046,"scriptSourceOwnerSet": "launchpad-static","stateProfile": "representative"},@@ -141,13 +141,13 @@"scriptRequestCount": 0,"totalRawBytes": 0},- "domContentLoadedMedianMs": 112.29999999701977,+ "domContentLoadedMedianMs": 114.10000000149012,"id": "editor-minimal","layoutSwitchMedianMs": 0,- "loadMedianMs": 112.29999999701977,- "longestTaskMaxMs": 93,+ "loadMedianMs": 114.10000000149012,+ "longestTaskMaxMs": 106,"owner": "workbench",- "projectSwitchMedianMs": 32.20000000298023,+ "projectSwitchMedianMs": 36.80000000447035,"readyMark": "invokeai:ready:widget:center:preview","remediationTicket": "deepen-widget-registry-loading","resourceBaseline": {@@ -157,9 +157,9 @@"largestAssetRawBytes": 746305,"otherRawBytes": 135938,"requestCount": 113,- "scriptRawBytes": 3366117,+ "scriptRawBytes": 3366154,"scriptRequestCount": 107,- "totalRawBytes": 3699667+ "totalRawBytes": 3699704},"resourceLimits": {"cssRawBytes": 17748,@@ -168,11 +168,11 @@"largestAssetRawBytes": 753769,"otherRawBytes": 137298,"requestCount": 113,- "scriptRawBytes": 3399779,+ "scriptRawBytes": 3399816,"scriptRequestCount": 107,- "totalRawBytes": 3736664+ "totalRawBytes": 3736702},- "routeReadyMedianMs": 627.5,+ "routeReadyMedianMs": 661.7000000029802,"scriptSourceOwnerSet": "editor-minimal-static","stateProfile": "empty"},@@ -199,13 +199,13 @@"scriptRequestCount": 0,"totalRawBytes": 0},- "domContentLoadedMedianMs": 115.79999999701977,+ "domContentLoadedMedianMs": 115,"id": "editor-minimal","layoutSwitchMedianMs": 0,- "loadMedianMs": 115.79999999701977,- "longestTaskMaxMs": 106,+ "loadMedianMs": 115,+ "longestTaskMaxMs": 104,"owner": "workbench",- "projectSwitchMedianMs": 48.899999998509884,+ "projectSwitchMedianMs": 52.29999999701977,"readyMark": "invokeai:ready:widget:center:preview","remediationTicket": "deepen-widget-registry-loading","resourceBaseline": {@@ -215,9 +215,9 @@"largestAssetRawBytes": 746305,"otherRawBytes": 135938,"requestCount": 113,- "scriptRawBytes": 3366117,+ "scriptRawBytes": 3366154,"scriptRequestCount": 107,- "totalRawBytes": 3699667+ "totalRawBytes": 3699704},"resourceLimits": {"cssRawBytes": 17748,@@ -226,11 +226,11 @@"largestAssetRawBytes": 753769,"otherRawBytes": 137298,"requestCount": 113,- "scriptRawBytes": 3399779,+ "scriptRawBytes": 3399816,"scriptRequestCount": 107,- "totalRawBytes": 3736664+ "totalRawBytes": 3736702},- "routeReadyMedianMs": 680.1000000014901,+ "routeReadyMedianMs": 712.7999999970198,"scriptSourceOwnerSet": "editor-minimal-static","stateProfile": "representative"},@@ -257,11 +257,11 @@"scriptRequestCount": 5,"totalRawBytes": 286746},- "domContentLoadedMedianMs": 108.89999999850988,+ "domContentLoadedMedianMs": 116.5,"id": "editor-canvas",- "layoutSwitchMedianMs": 59.5,- "loadMedianMs": 108.89999999850988,- "longestTaskMaxMs": 93,+ "layoutSwitchMedianMs": 62.80000000447035,+ "loadMedianMs": 116.5,+ "longestTaskMaxMs": 94,"owner": "canvas","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:widget:center:canvas",@@ -273,9 +273,9 @@"largestAssetRawBytes": 746305,"otherRawBytes": 135938,"requestCount": 118,- "scriptRawBytes": 3650023,+ "scriptRawBytes": 3650060,"scriptRequestCount": 112,- "totalRawBytes": 3983573+ "totalRawBytes": 3983610},"resourceLimits": {"cssRawBytes": 17748,@@ -284,11 +284,11 @@"largestAssetRawBytes": 753769,"otherRawBytes": 137298,"requestCount": 118,- "scriptRawBytes": 3686524,+ "scriptRawBytes": 3686561,"scriptRequestCount": 112,- "totalRawBytes": 4023409+ "totalRawBytes": 4023447},- "routeReadyMedianMs": 1077.2999999970198,+ "routeReadyMedianMs": 1096.3999999985099,"scriptSourceOwnerSet": "editor-canvas-static","stateProfile": "empty"},@@ -315,11 +315,11 @@"scriptRequestCount": 5,"totalRawBytes": 286746},- "domContentLoadedMedianMs": 115.29999999701977,+ "domContentLoadedMedianMs": 112,"id": "editor-canvas",- "layoutSwitchMedianMs": 185.10000000149012,- "loadMedianMs": 115.29999999701977,- "longestTaskMaxMs": 380,+ "layoutSwitchMedianMs": 195,+ "loadMedianMs": 112,+ "longestTaskMaxMs": 371,"owner": "canvas","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:widget:center:canvas",@@ -331,9 +331,9 @@"largestAssetRawBytes": 746305,"otherRawBytes": 135938,"requestCount": 118,- "scriptRawBytes": 3650023,+ "scriptRawBytes": 3650060,"scriptRequestCount": 112,- "totalRawBytes": 3983573+ "totalRawBytes": 3983610},"resourceLimits": {"cssRawBytes": 17748,@@ -342,11 +342,11 @@"largestAssetRawBytes": 753769,"otherRawBytes": 137298,"requestCount": 118,- "scriptRawBytes": 3686524,+ "scriptRawBytes": 3686561,"scriptRequestCount": 112,- "totalRawBytes": 4023409+ "totalRawBytes": 4023447},- "routeReadyMedianMs": 1242,+ "routeReadyMedianMs": 1263.1000000014901,"scriptSourceOwnerSet": "editor-canvas-static","stateProfile": "representative"},@@ -373,11 +373,11 @@"scriptRequestCount": 0,"totalRawBytes": 0},- "domContentLoadedMedianMs": 113.10000000149012,+ "domContentLoadedMedianMs": 111.59999999403954,"id": "editor-workflow",- "layoutSwitchMedianMs": 58.100000001490116,- "loadMedianMs": 113.10000000149012,- "longestTaskMaxMs": 86,+ "layoutSwitchMedianMs": 55.400000005960464,+ "loadMedianMs": 111.59999999403954,+ "longestTaskMaxMs": 91,"owner": "workflow","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:widget:center:workflow",@@ -389,9 +389,9 @@"largestAssetRawBytes": 746305,"otherRawBytes": 135938,"requestCount": 113,- "scriptRawBytes": 3366117,+ "scriptRawBytes": 3366154,"scriptRequestCount": 107,- "totalRawBytes": 3699667+ "totalRawBytes": 3699704},"resourceLimits": {"cssRawBytes": 17748,@@ -400,11 +400,11 @@"largestAssetRawBytes": 753769,"otherRawBytes": 137298,"requestCount": 113,- "scriptRawBytes": 3399779,+ "scriptRawBytes": 3399816,"scriptRequestCount": 107,- "totalRawBytes": 3736664+ "totalRawBytes": 3736702},- "routeReadyMedianMs": 1054.5,+ "routeReadyMedianMs": 1051.1000000014901,"scriptSourceOwnerSet": "editor-minimal-static","stateProfile": "empty"},@@ -431,11 +431,11 @@"scriptRequestCount": 0,"totalRawBytes": 0},- "domContentLoadedMedianMs": 114.40000000596046,+ "domContentLoadedMedianMs": 114.79999999701977,"id": "editor-workflow",- "layoutSwitchMedianMs": 109.5,- "loadMedianMs": 114.40000000596046,- "longestTaskMaxMs": 379,+ "layoutSwitchMedianMs": 113.60000000149012,+ "loadMedianMs": 114.79999999701977,+ "longestTaskMaxMs": 387,"owner": "workflow","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:widget:center:workflow",@@ -447,9 +447,9 @@"largestAssetRawBytes": 746305,"otherRawBytes": 135938,"requestCount": 113,- "scriptRawBytes": 3366117,+ "scriptRawBytes": 3366154,"scriptRequestCount": 107,- "totalRawBytes": 3699667+ "totalRawBytes": 3699704},"resourceLimits": {"cssRawBytes": 17748,@@ -458,11 +458,11 @@"largestAssetRawBytes": 753769,"otherRawBytes": 137298,"requestCount": 113,- "scriptRawBytes": 3399779,+ "scriptRawBytes": 3399816,"scriptRequestCount": 107,- "totalRawBytes": 3736664+ "totalRawBytes": 3736702},- "routeReadyMedianMs": 1160.8999999985099,+ "routeReadyMedianMs": 1183.2000000029802,"scriptSourceOwnerSet": "editor-minimal-static","stateProfile": "representative"},@@ -489,11 +489,11 @@"scriptRequestCount": 0,"totalRawBytes": 0},- "domContentLoadedMedianMs": 114.69999999552965,+ "domContentLoadedMedianMs": 112.29999999701977,"id": "editor-gallery",- "layoutSwitchMedianMs": 23.799999997019768,- "loadMedianMs": 114.69999999552965,- "longestTaskMaxMs": 89,+ "layoutSwitchMedianMs": 22.80000000447035,+ "loadMedianMs": 112.29999999701977,+ "longestTaskMaxMs": 94,"owner": "gallery","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:widget:center:gallery",@@ -505,9 +505,9 @@"largestAssetRawBytes": 746305,"otherRawBytes": 135938,"requestCount": 113,- "scriptRawBytes": 3366117,+ "scriptRawBytes": 3366154,"scriptRequestCount": 107,- "totalRawBytes": 3699667+ "totalRawBytes": 3699704},"resourceLimits": {"cssRawBytes": 17748,@@ -516,11 +516,11 @@"largestAssetRawBytes": 753769,"otherRawBytes": 137298,"requestCount": 113,- "scriptRawBytes": 3399779,+ "scriptRawBytes": 3399816,"scriptRequestCount": 107,- "totalRawBytes": 3736664+ "totalRawBytes": 3736702},- "routeReadyMedianMs": 1316.7000000029802,+ "routeReadyMedianMs": 1312.2000000029802,"scriptSourceOwnerSet": "editor-minimal-static","stateProfile": "empty"},@@ -547,11 +547,11 @@"scriptRequestCount": 0,"totalRawBytes": 0},- "domContentLoadedMedianMs": 115.39999999850988,+ "domContentLoadedMedianMs": 114,"id": "editor-gallery",- "layoutSwitchMedianMs": 96.19999999552965,- "loadMedianMs": 115.39999999850988,- "longestTaskMaxMs": 165,+ "layoutSwitchMedianMs": 96.30000000447035,+ "loadMedianMs": 114,+ "longestTaskMaxMs": 147,"owner": "gallery","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:widget:center:gallery",@@ -563,9 +563,9 @@"largestAssetRawBytes": 746305,"otherRawBytes": 135938,"requestCount": 113,- "scriptRawBytes": 3366117,+ "scriptRawBytes": 3366154,"scriptRequestCount": 107,- "totalRawBytes": 3699667+ "totalRawBytes": 3699704},"resourceLimits": {"cssRawBytes": 17748,@@ -574,11 +574,11 @@"largestAssetRawBytes": 753769,"otherRawBytes": 137298,"requestCount": 113,- "scriptRawBytes": 3399779,+ "scriptRawBytes": 3399816,"scriptRequestCount": 107,- "totalRawBytes": 3736664+ "totalRawBytes": 3736702},- "routeReadyMedianMs": 1468.8999999985099,+ "routeReadyMedianMs": 1457.3999999985099,"scriptSourceOwnerSet": "editor-minimal-static","stateProfile": "representative"}diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/library/libraryAutosave.test.ts b/invokeai/frontend/webv2/src/features/workflow/ui/library/libraryAutosave.test.tsindex 70c034f6ae..4fafd576d7 100644--- a/invokeai/frontend/webv2/src/features/workflow/ui/library/libraryAutosave.test.ts+++ b/invokeai/frontend/webv2/src/features/workflow/ui/library/libraryAutosave.test.ts@@ -205,6 +205,32 @@ describe('createLibraryAutosaver', () => {expect(h.statuses.at(-1)).toBe('saved');});+ it('does not report saved while an edit made during the save is still unwritten', async () => {+ // The dangerous direction: an older save's acknowledgement lands after a+ // newer edit has already marked the graph dirty. Reporting 'saved' there+ // tells someone their work is safe during the window in which it is not,+ // and that is exactly when they close the tab.+ const h = createHarness();+ let resolveSave: () => void;+ const deferred = new Promise<void>((resolve) => {+ resolveSave = resolve;+ });++ h.save.mockReturnValueOnce(deferred);+ h.autosaver.notifyGraphChanged();+ h.manual.fire();++ h.setCurrent({ libraryWorkflowId: 'wf-1', serialized: { nodes: [2] } });+ h.autosaver.notifyGraphChanged();++ resolveSave!();+ await Promise.resolve();+ await Promise.resolve();++ expect(h.statuses.at(-1)).toBe('dirty');+ expect(h.manual.pendingCount()).toBe(1);+ });+it('an edit that dedupes back to the saved content ends in saved, not dirty', async () => {const h = createHarness();h.autosaver.notifyGraphChanged();diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/library/libraryAutosave.ts b/invokeai/frontend/webv2/src/features/workflow/ui/library/libraryAutosave.tsindex a045aa38af..0beb3b196e 100644--- a/invokeai/frontend/webv2/src/features/workflow/ui/library/libraryAutosave.ts+++ b/invokeai/frontend/webv2/src/features/workflow/ui/library/libraryAutosave.ts@@ -5,6 +5,11 @@* and is retried by the next graph change or an explicit flush(). No automatic* retry loop — persistent failures must not spin (cf. bitmapStore anti-spin).*+ * A save's acknowledgement only reports 'saved' if no edit arrived while it was+ * in flight; otherwise the status stays 'dirty' and the queued write reports+ * for itself. The status is a promise about the person's current work, not a+ * receipt for whichever bytes happened to be in the last request.+ ** dispose() flushes rather than drops: a pending debounced edit is an unsaved* change, so unmount collapses it into one final save (status callbacks stay* muted). Known limitation: a hard tab close inside the debounce window can@@ -39,6 +44,17 @@ export const createLibraryAutosaver = (deps: LibraryAutosaverDeps) => {let inFlight: Promise<void> | null = null;let lastSavedJson: string | null = null;let disposed = false;+ /**+ * Bumped by every graph change. A save captures it after serializing, so a+ * captured value that no longer matches means the person edited again while+ * the write was in flight and the answer we just got is about older content.+ *+ * Only the success path consults it, because the two ways of being wrong are+ * not symmetric: claiming 'saved' over unwritten work invites someone to+ * close the tab, while claiming 'error' or 'dirty' over work that did land+ * costs one redundant save. Failures still report as failures.+ */+ let editGeneration = 0;const clearTimer = (): void => {if (timerHandle !== null) {@@ -73,12 +89,18 @@ export const createLibraryAutosaver = (deps: LibraryAutosaverDeps) => {if (!disposed) {deps.onStatus('saving');}++ const generationAtCapture = editGeneration;+inFlight = deps.save(libraryWorkflowId, serialized).then(() => {+ // `json` did reach the server, so it is still the dedupe baseline even+ // when newer edits exist — the next pass compares against it and saves+ // only the difference.lastSavedJson = json;if (!disposed) {- deps.onStatus('saved');+ deps.onStatus(editGeneration === generationAtCapture ? 'saved' : 'dirty');}}).catch(() => {@@ -123,6 +145,7 @@ export const createLibraryAutosaver = (deps: LibraryAutosaverDeps) => {if (disposed || !deps.read().libraryWorkflowId) {return;}+ editGeneration += 1;deps.onStatus('dirty');clearTimer();timerHandle = timers.setTimeout(() => {