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): harden account-scoped prompt transfers
joshistoast5dc7b337e646
diff --git a/invokeai/frontend/webv2/performance/architecture-baseline.json b/invokeai/frontend/webv2/performance/architecture-baseline.jsonindex 8f8b827a81..3a1f8edfef 100644--- a/invokeai/frontend/webv2/performance/architecture-baseline.json+++ b/invokeai/frontend/webv2/performance/architecture-baseline.json@@ -2,15 +2,15 @@"build": {"launchpad": {"baseline": {- "brotliBytes": 798414,+ "brotliBytes": 798841,"cssRawBytes": 2159,"fontRawBytes": 219480,- "gzipBytes": 798574,+ "gzipBytes": 798924,"imageRawBytes": 156376,- "initialRawBytes": 1832589,+ "initialRawBytes": 1832689,"largestAssetRawBytes": 737748,"otherAssetRawBytes": 0,- "ownedRawBytes": 57782,+ "ownedRawBytes": 57827,"requestCount": 31,"scriptRequestCount": 15,"sourceOwners": [@@ -239,15 +239,15 @@]},"limits": {- "brotliBytes": 806399,+ "brotliBytes": 806830,"cssRawBytes": 2181,"fontRawBytes": 221675,- "gzipBytes": 806560,+ "gzipBytes": 806914,"imageRawBytes": 157940,- "initialRawBytes": 1850915,+ "initialRawBytes": 1851016,"largestAssetRawBytes": 745126,"otherAssetRawBytes": 0,- "ownedRawBytes": 57782,+ "ownedRawBytes": 57827,"requestCount": 31,"scriptRequestCount": 15},@@ -257,17 +257,17 @@},"editor": {"baseline": {- "brotliBytes": 975461,+ "brotliBytes": 978307,"cssRawBytes": 2159,"fontRawBytes": 219480,- "gzipBytes": 974331,+ "gzipBytes": 977008,"imageRawBytes": 156376,- "initialRawBytes": 2370128,+ "initialRawBytes": 2376527,"largestAssetRawBytes": 737748,"otherAssetRawBytes": 0,- "ownedRawBytes": 108460,- "requestCount": 74,- "scriptRequestCount": 58,+ "ownedRawBytes": 110018,+ "requestCount": 73,+ "scriptRequestCount": 57,"sourceOwners": ["package:@ark-ui/react","package:@chakra-ui/react",@@ -382,6 +382,7 @@"source:src/app/App.tsx","source:src/app/AppProviders.tsx","source:src/app/GalleryUiAdapter.tsx",+ "source:src/app/GenerateWidgetSyncRuntime.tsx","source:src/app/GenerationUiAdapter.tsx","source:src/app/I18nController.tsx","source:src/app/ModelsUiAdapter.tsx",@@ -393,6 +394,7 @@"source:src/app/WorkbenchApp.tsx","source:src/app/WorkflowUiAdapter.tsx","source:src/app/accountLifecycle.ts",+ "source:src/app/generateWidgetSyncRuntime.ts","source:src/app/main.tsx","source:src/app/router.tsx","source:src/app/workbenchPorts.tsx",@@ -429,11 +431,14 @@"source:src/features/generation/core/promptHistory.ts","source:src/features/generation/core/promptTemplates.ts","source:src/features/generation/core/referenceImage.ts",+ "source:src/features/generation/core/resolveGenerateWidgetValues.ts","source:src/features/generation/core/settings.ts","source:src/features/generation/data/dynamicPromptsQueries.ts",+ "source:src/features/generation/data/promptTemplates.ts","source:src/features/generation/data/promptUtilities.ts","source:src/features/generation/graph.ts","source:src/features/generation/prompts.ts",+ "source:src/features/generation/queries.ts","source:src/features/generation/react.ts","source:src/features/generation/settings.ts","source:src/features/generation/ui/GenerationUiContext.tsx",@@ -537,6 +542,7 @@"source:src/features/workflow/widget.ts","source:src/platform/browser/downloadBlob.ts","source:src/platform/browser/knownBrowserIssues.ts",+ "source:src/platform/core/json.ts","source:src/platform/i18n/client.ts","source:src/platform/i18n/languages.ts","source:src/platform/performance/semanticReady.ts",@@ -734,24 +740,24 @@]},"limits": {- "brotliBytes": 985216,+ "brotliBytes": 988091,"cssRawBytes": 2181,"fontRawBytes": 221675,- "gzipBytes": 984075,+ "gzipBytes": 986779,"imageRawBytes": 157940,- "initialRawBytes": 2393830,+ "initialRawBytes": 2400293,"largestAssetRawBytes": 745126,"otherAssetRawBytes": 0,- "ownedRawBytes": 108460,- "requestCount": 74,- "scriptRequestCount": 58+ "ownedRawBytes": 110018,+ "requestCount": 73,+ "scriptRequestCount": 57},"owner": "workbench","remediationTicket": "deepen-widget-registry-loading","source": "src/app/WorkbenchApp.tsx"}},- "capturedAt": "2026-07-28",+ "capturedAt": "2026-07-29","developmentInvalidation": {"platformUiBarrel": {"specifier": "@platform/ui",diff --git a/invokeai/frontend/webv2/performance/browser-baseline.json b/invokeai/frontend/webv2/performance/browser-baseline.jsonindex 2afd1660fc..66e96a91a1 100644--- a/invokeai/frontend/webv2/performance/browser-baseline.json+++ b/invokeai/frontend/webv2/performance/browser-baseline.json@@ -1,6 +1,6 @@{"browserExecutable": "/home/toast/.cache/ms-playwright/chromium-1228/chrome-linux64/chrome",- "capturedAt": "2026-07-28",+ "capturedAt": "2026-07-29","routes": [{"activatedResourceBaseline": {@@ -25,11 +25,11 @@"scriptRequestCount": 0,"totalRawBytes": 0},- "domContentLoadedMedianMs": 105.09999999962747,+ "domContentLoadedMedianMs": 104.70000000298023,"id": "launchpad","layoutSwitchMedianMs": 0,- "loadMedianMs": 105.09999999962747,- "longestTaskMaxMs": 67,+ "loadMedianMs": 104.70000000298023,+ "longestTaskMaxMs": 63,"owner": "app","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:launchpad",@@ -39,24 +39,24 @@"fontRawBytes": 23664,"imageRawBytes": 0,"largestAssetRawBytes": 737748,- "otherRawBytes": 95443,+ "otherRawBytes": 95490,"requestCount": 19,- "scriptRawBytes": 1454574,+ "scriptRawBytes": 1454674,"scriptRequestCount": 15,- "totalRawBytes": 1575840+ "totalRawBytes": 1575987},"resourceLimits": {"cssRawBytes": 2181,"fontRawBytes": 23901,"imageRawBytes": 0,"largestAssetRawBytes": 745126,- "otherRawBytes": 96398,+ "otherRawBytes": 96445,"requestCount": 19,- "scriptRawBytes": 1469120,+ "scriptRawBytes": 1469221,"scriptRequestCount": 15,- "totalRawBytes": 1591599+ "totalRawBytes": 1591747},- "routeReadyMedianMs": 213.3999999994412,+ "routeReadyMedianMs": 213.5,"scriptSourceOwnerSet": "launchpad-static","stateProfile": "empty"},@@ -83,11 +83,11 @@"scriptRequestCount": 0,"totalRawBytes": 0},- "domContentLoadedMedianMs": 105.1000000005588,+ "domContentLoadedMedianMs": 104.20000000298023,"id": "launchpad","layoutSwitchMedianMs": 0,- "loadMedianMs": 105.1000000005588,- "longestTaskMaxMs": 66,+ "loadMedianMs": 104.20000000298023,+ "longestTaskMaxMs": 65,"owner": "app","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:launchpad",@@ -97,24 +97,24 @@"fontRawBytes": 23664,"imageRawBytes": 0,"largestAssetRawBytes": 737748,- "otherRawBytes": 95443,+ "otherRawBytes": 95490,"requestCount": 19,- "scriptRawBytes": 1454574,+ "scriptRawBytes": 1454674,"scriptRequestCount": 15,- "totalRawBytes": 1575840+ "totalRawBytes": 1575987},"resourceLimits": {"cssRawBytes": 2181,"fontRawBytes": 23901,"imageRawBytes": 0,"largestAssetRawBytes": 745126,- "otherRawBytes": 96398,+ "otherRawBytes": 96445,"requestCount": 19,- "scriptRawBytes": 1469120,+ "scriptRawBytes": 1469221,"scriptRequestCount": 15,- "totalRawBytes": 1591599+ "totalRawBytes": 1591747},- "routeReadyMedianMs": 265.40000000037253,+ "routeReadyMedianMs": 267.1000000014901,"scriptSourceOwnerSet": "launchpad-static","stateProfile": "representative"},@@ -141,13 +141,13 @@"scriptRequestCount": 0,"totalRawBytes": 0},- "domContentLoadedMedianMs": 105.29999999981374,+ "domContentLoadedMedianMs": 105.19999999552965,"id": "editor-minimal","layoutSwitchMedianMs": 0,- "loadMedianMs": 105.29999999981374,- "longestTaskMaxMs": 106,+ "loadMedianMs": 105.19999999552965,+ "longestTaskMaxMs": 105,"owner": "workbench",- "projectSwitchMedianMs": 49.612936000000445,+ "projectSwitchMedianMs": 63.73331999999937,"readyMark": "invokeai:ready:widget:center:preview","remediationTicket": "deepen-widget-registry-loading","resourceBaseline": {@@ -155,24 +155,24 @@"fontRawBytes": 23664,"imageRawBytes": 156376,"largestAssetRawBytes": 737748,- "otherRawBytes": 95443,- "requestCount": 94,- "scriptRawBytes": 3006528,- "scriptRequestCount": 88,- "totalRawBytes": 3299583+ "otherRawBytes": 95490,+ "requestCount": 93,+ "scriptRawBytes": 3013324,+ "scriptRequestCount": 87,+ "totalRawBytes": 3306426},"resourceLimits": {"cssRawBytes": 17748,"fontRawBytes": 23901,"imageRawBytes": 157940,"largestAssetRawBytes": 745126,- "otherRawBytes": 96398,- "requestCount": 94,- "scriptRawBytes": 3036594,- "scriptRequestCount": 88,- "totalRawBytes": 3332579+ "otherRawBytes": 96445,+ "requestCount": 93,+ "scriptRawBytes": 3043458,+ "scriptRequestCount": 87,+ "totalRawBytes": 3339491},- "routeReadyMedianMs": 598.2999999998137,+ "routeReadyMedianMs": 597,"scriptSourceOwnerSet": "editor-minimal-static","stateProfile": "empty"},@@ -199,13 +199,13 @@"scriptRequestCount": 0,"totalRawBytes": 0},- "domContentLoadedMedianMs": 106,+ "domContentLoadedMedianMs": 105,"id": "editor-minimal","layoutSwitchMedianMs": 0,- "loadMedianMs": 106,- "longestTaskMaxMs": 114,+ "loadMedianMs": 105,+ "longestTaskMaxMs": 117,"owner": "workbench",- "projectSwitchMedianMs": 78.12321800000063,+ "projectSwitchMedianMs": 83.5817019999995,"readyMark": "invokeai:ready:widget:center:preview","remediationTicket": "deepen-widget-registry-loading","resourceBaseline": {@@ -213,24 +213,24 @@"fontRawBytes": 23664,"imageRawBytes": 156376,"largestAssetRawBytes": 737748,- "otherRawBytes": 95443,- "requestCount": 94,- "scriptRawBytes": 3006528,- "scriptRequestCount": 88,- "totalRawBytes": 3299583+ "otherRawBytes": 95490,+ "requestCount": 93,+ "scriptRawBytes": 3013324,+ "scriptRequestCount": 87,+ "totalRawBytes": 3306426},"resourceLimits": {"cssRawBytes": 17748,"fontRawBytes": 23901,"imageRawBytes": 157940,"largestAssetRawBytes": 745126,- "otherRawBytes": 96398,- "requestCount": 94,- "scriptRawBytes": 3036594,- "scriptRequestCount": 88,- "totalRawBytes": 3332579+ "otherRawBytes": 96445,+ "requestCount": 93,+ "scriptRawBytes": 3043458,+ "scriptRequestCount": 87,+ "totalRawBytes": 3339491},- "routeReadyMedianMs": 636.5,+ "routeReadyMedianMs": 642.1000000014901,"scriptSourceOwnerSet": "editor-minimal-static","stateProfile": "representative"},@@ -242,9 +242,9 @@"largestAssetRawBytes": 136446,"otherRawBytes": 0,"requestCount": 7,- "scriptRawBytes": 290429,+ "scriptRawBytes": 290427,"scriptRequestCount": 7,- "totalRawBytes": 290429+ "totalRawBytes": 290427},"activatedResourceLimits": {"cssRawBytes": 0,@@ -253,14 +253,14 @@"largestAssetRawBytes": 137811,"otherRawBytes": 0,"requestCount": 7,- "scriptRawBytes": 293334,+ "scriptRawBytes": 293332,"scriptRequestCount": 7,- "totalRawBytes": 293334+ "totalRawBytes": 293332},- "domContentLoadedMedianMs": 105.20000000018626,+ "domContentLoadedMedianMs": 104,"id": "editor-canvas",- "layoutSwitchMedianMs": 71.59999999962747,- "loadMedianMs": 105.20000000018626,+ "layoutSwitchMedianMs": 74.20000000298023,+ "loadMedianMs": 104,"longestTaskMaxMs": 103,"owner": "canvas","projectSwitchMedianMs": 0,@@ -271,24 +271,24 @@"fontRawBytes": 23664,"imageRawBytes": 156376,"largestAssetRawBytes": 737748,- "otherRawBytes": 95443,- "requestCount": 98,- "scriptRawBytes": 3282722,- "scriptRequestCount": 92,- "totalRawBytes": 3575777+ "otherRawBytes": 95490,+ "requestCount": 97,+ "scriptRawBytes": 3289517,+ "scriptRequestCount": 91,+ "totalRawBytes": 3582619},"resourceLimits": {"cssRawBytes": 17748,"fontRawBytes": 23901,"imageRawBytes": 157940,"largestAssetRawBytes": 745126,- "otherRawBytes": 96398,- "requestCount": 98,- "scriptRawBytes": 3315550,- "scriptRequestCount": 92,- "totalRawBytes": 3611535+ "otherRawBytes": 96445,+ "requestCount": 97,+ "scriptRawBytes": 3322413,+ "scriptRequestCount": 91,+ "totalRawBytes": 3618446},- "routeReadyMedianMs": 716.6999999992549,+ "routeReadyMedianMs": 762.3000000044703,"scriptSourceOwnerSet": "editor-canvas-static","stateProfile": "empty"},@@ -300,9 +300,9 @@"largestAssetRawBytes": 136446,"otherRawBytes": 0,"requestCount": 7,- "scriptRawBytes": 290429,+ "scriptRawBytes": 290427,"scriptRequestCount": 7,- "totalRawBytes": 290429+ "totalRawBytes": 290427},"activatedResourceLimits": {"cssRawBytes": 0,@@ -311,15 +311,15 @@"largestAssetRawBytes": 137811,"otherRawBytes": 0,"requestCount": 7,- "scriptRawBytes": 293334,+ "scriptRawBytes": 293332,"scriptRequestCount": 7,- "totalRawBytes": 293334+ "totalRawBytes": 293332},- "domContentLoadedMedianMs": 104.29999999981374,+ "domContentLoadedMedianMs": 105.5,"id": "editor-canvas",- "layoutSwitchMedianMs": 294.1000000005588,- "loadMedianMs": 104.29999999981374,- "longestTaskMaxMs": 334,+ "layoutSwitchMedianMs": 286.6000000014901,+ "loadMedianMs": 105.60000000149012,+ "longestTaskMaxMs": 337,"owner": "canvas","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:widget:center:canvas",@@ -329,24 +329,24 @@"fontRawBytes": 23664,"imageRawBytes": 156376,"largestAssetRawBytes": 737748,- "otherRawBytes": 95443,- "requestCount": 98,- "scriptRawBytes": 3282722,- "scriptRequestCount": 92,- "totalRawBytes": 3575777+ "otherRawBytes": 95490,+ "requestCount": 97,+ "scriptRawBytes": 3289517,+ "scriptRequestCount": 91,+ "totalRawBytes": 3582619},"resourceLimits": {"cssRawBytes": 17748,"fontRawBytes": 23901,"imageRawBytes": 157940,"largestAssetRawBytes": 745126,- "otherRawBytes": 96398,- "requestCount": 98,- "scriptRawBytes": 3315550,- "scriptRequestCount": 92,- "totalRawBytes": 3611535+ "otherRawBytes": 96445,+ "requestCount": 97,+ "scriptRawBytes": 3322413,+ "scriptRequestCount": 91,+ "totalRawBytes": 3618446},- "routeReadyMedianMs": 1091,+ "routeReadyMedianMs": 1026.2000000029802,"scriptSourceOwnerSet": "editor-canvas-static","stateProfile": "representative"},@@ -355,28 +355,28 @@"cssRawBytes": 0,"fontRawBytes": 0,"imageRawBytes": 0,- "largestAssetRawBytes": 13253,+ "largestAssetRawBytes": 13252,"otherRawBytes": 0,"requestCount": 3,- "scriptRawBytes": 14235,+ "scriptRawBytes": 14234,"scriptRequestCount": 3,- "totalRawBytes": 14235+ "totalRawBytes": 14234},"activatedResourceLimits": {"cssRawBytes": 0,"fontRawBytes": 0,"imageRawBytes": 0,- "largestAssetRawBytes": 13386,+ "largestAssetRawBytes": 13385,"otherRawBytes": 0,"requestCount": 3,- "scriptRawBytes": 14378,+ "scriptRawBytes": 14377,"scriptRequestCount": 3,- "totalRawBytes": 14378+ "totalRawBytes": 14377},- "domContentLoadedMedianMs": 104,+ "domContentLoadedMedianMs": 103.5,"id": "editor-workflow",- "layoutSwitchMedianMs": 64.59999999962747,- "loadMedianMs": 104,+ "layoutSwitchMedianMs": 64.60000000149012,+ "loadMedianMs": 103.5,"longestTaskMaxMs": 103,"owner": "workflow","projectSwitchMedianMs": 0,@@ -387,24 +387,24 @@"fontRawBytes": 23664,"imageRawBytes": 156376,"largestAssetRawBytes": 737748,- "otherRawBytes": 95443,- "requestCount": 94,- "scriptRawBytes": 3006528,- "scriptRequestCount": 88,- "totalRawBytes": 3299583+ "otherRawBytes": 95490,+ "requestCount": 93,+ "scriptRawBytes": 3013324,+ "scriptRequestCount": 87,+ "totalRawBytes": 3306426},"resourceLimits": {"cssRawBytes": 17748,"fontRawBytes": 23901,"imageRawBytes": 157940,"largestAssetRawBytes": 745126,- "otherRawBytes": 96398,- "requestCount": 94,- "scriptRawBytes": 3036594,- "scriptRequestCount": 88,- "totalRawBytes": 3332579+ "otherRawBytes": 96445,+ "requestCount": 93,+ "scriptRawBytes": 3043458,+ "scriptRequestCount": 87,+ "totalRawBytes": 3339491},- "routeReadyMedianMs": 742.7000000001863,+ "routeReadyMedianMs": 721.7000000029802,"scriptSourceOwnerSet": "editor-minimal-static","stateProfile": "empty"},@@ -413,29 +413,29 @@"cssRawBytes": 0,"fontRawBytes": 0,"imageRawBytes": 0,- "largestAssetRawBytes": 13253,+ "largestAssetRawBytes": 13252,"otherRawBytes": 0,"requestCount": 3,- "scriptRawBytes": 14235,+ "scriptRawBytes": 14234,"scriptRequestCount": 3,- "totalRawBytes": 14235+ "totalRawBytes": 14234},"activatedResourceLimits": {"cssRawBytes": 0,"fontRawBytes": 0,"imageRawBytes": 0,- "largestAssetRawBytes": 13386,+ "largestAssetRawBytes": 13385,"otherRawBytes": 0,"requestCount": 3,- "scriptRawBytes": 14378,+ "scriptRawBytes": 14377,"scriptRequestCount": 3,- "totalRawBytes": 14378+ "totalRawBytes": 14377},- "domContentLoadedMedianMs": 105,+ "domContentLoadedMedianMs": 104.89999999850988,"id": "editor-workflow",- "layoutSwitchMedianMs": 117.70000000018626,- "loadMedianMs": 105,- "longestTaskMaxMs": 389,+ "layoutSwitchMedianMs": 111.19999999552965,+ "loadMedianMs": 104.89999999850988,+ "longestTaskMaxMs": 362,"owner": "workflow","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:widget:center:workflow",@@ -445,24 +445,24 @@"fontRawBytes": 23664,"imageRawBytes": 156376,"largestAssetRawBytes": 737748,- "otherRawBytes": 95443,- "requestCount": 94,- "scriptRawBytes": 3006528,- "scriptRequestCount": 88,- "totalRawBytes": 3299583+ "otherRawBytes": 95490,+ "requestCount": 93,+ "scriptRawBytes": 3013324,+ "scriptRequestCount": 87,+ "totalRawBytes": 3306426},"resourceLimits": {"cssRawBytes": 17748,"fontRawBytes": 23901,"imageRawBytes": 157940,"largestAssetRawBytes": 745126,- "otherRawBytes": 96398,- "requestCount": 94,- "scriptRawBytes": 3036594,- "scriptRequestCount": 88,- "totalRawBytes": 3332579+ "otherRawBytes": 96445,+ "requestCount": 93,+ "scriptRawBytes": 3043458,+ "scriptRequestCount": 87,+ "totalRawBytes": 3339491},- "routeReadyMedianMs": 918.4000000003725,+ "routeReadyMedianMs": 875.6999999955297,"scriptSourceOwnerSet": "editor-minimal-static","stateProfile": "representative"},@@ -471,29 +471,29 @@"cssRawBytes": 0,"fontRawBytes": 0,"imageRawBytes": 0,- "largestAssetRawBytes": 13253,+ "largestAssetRawBytes": 13252,"otherRawBytes": 0,"requestCount": 3,- "scriptRawBytes": 14235,+ "scriptRawBytes": 14234,"scriptRequestCount": 3,- "totalRawBytes": 14235+ "totalRawBytes": 14234},"activatedResourceLimits": {"cssRawBytes": 0,"fontRawBytes": 0,"imageRawBytes": 0,- "largestAssetRawBytes": 13386,+ "largestAssetRawBytes": 13385,"otherRawBytes": 0,"requestCount": 3,- "scriptRawBytes": 14378,+ "scriptRawBytes": 14377,"scriptRequestCount": 3,- "totalRawBytes": 14378+ "totalRawBytes": 14377},- "domContentLoadedMedianMs": 106.1000000005588,+ "domContentLoadedMedianMs": 107.39999999850988,"id": "editor-gallery",- "layoutSwitchMedianMs": 25.09999999962747,- "loadMedianMs": 106.1000000005588,- "longestTaskMaxMs": 103,+ "layoutSwitchMedianMs": 25.5,+ "loadMedianMs": 107.39999999850988,+ "longestTaskMaxMs": 113,"owner": "gallery","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:widget:center:gallery",@@ -503,24 +503,24 @@"fontRawBytes": 23664,"imageRawBytes": 156376,"largestAssetRawBytes": 737748,- "otherRawBytes": 95443,- "requestCount": 94,- "scriptRawBytes": 3006528,- "scriptRequestCount": 88,- "totalRawBytes": 3299583+ "otherRawBytes": 95490,+ "requestCount": 93,+ "scriptRawBytes": 3013324,+ "scriptRequestCount": 87,+ "totalRawBytes": 3306426},"resourceLimits": {"cssRawBytes": 17748,"fontRawBytes": 23901,"imageRawBytes": 157940,"largestAssetRawBytes": 745126,- "otherRawBytes": 96398,- "requestCount": 94,- "scriptRawBytes": 3036594,- "scriptRequestCount": 88,- "totalRawBytes": 3332579+ "otherRawBytes": 96445,+ "requestCount": 93,+ "scriptRawBytes": 3043458,+ "scriptRequestCount": 87,+ "totalRawBytes": 3339491},- "routeReadyMedianMs": 682.9000000003725,+ "routeReadyMedianMs": 700.9000000059605,"scriptSourceOwnerSet": "editor-minimal-static","stateProfile": "empty"},@@ -529,28 +529,28 @@"cssRawBytes": 0,"fontRawBytes": 0,"imageRawBytes": 0,- "largestAssetRawBytes": 13253,+ "largestAssetRawBytes": 13252,"otherRawBytes": 0,"requestCount": 3,- "scriptRawBytes": 14235,+ "scriptRawBytes": 14234,"scriptRequestCount": 3,- "totalRawBytes": 14235+ "totalRawBytes": 14234},"activatedResourceLimits": {"cssRawBytes": 0,"fontRawBytes": 0,"imageRawBytes": 0,- "largestAssetRawBytes": 13386,+ "largestAssetRawBytes": 13385,"otherRawBytes": 0,"requestCount": 3,- "scriptRawBytes": 14378,+ "scriptRawBytes": 14377,"scriptRequestCount": 3,- "totalRawBytes": 14378+ "totalRawBytes": 14377},- "domContentLoadedMedianMs": 105.5,+ "domContentLoadedMedianMs": 103.60000000149012,"id": "editor-gallery",- "layoutSwitchMedianMs": 35.5,- "loadMedianMs": 105.5,+ "layoutSwitchMedianMs": 35,+ "loadMedianMs": 103.60000000149012,"longestTaskMaxMs": 112,"owner": "gallery","projectSwitchMedianMs": 0,@@ -561,24 +561,24 @@"fontRawBytes": 23664,"imageRawBytes": 156376,"largestAssetRawBytes": 737748,- "otherRawBytes": 95443,- "requestCount": 94,- "scriptRawBytes": 3006528,- "scriptRequestCount": 88,- "totalRawBytes": 3299583+ "otherRawBytes": 95490,+ "requestCount": 93,+ "scriptRawBytes": 3013324,+ "scriptRequestCount": 87,+ "totalRawBytes": 3306426},"resourceLimits": {"cssRawBytes": 17748,"fontRawBytes": 23901,"imageRawBytes": 157940,"largestAssetRawBytes": 745126,- "otherRawBytes": 96398,- "requestCount": 94,- "scriptRawBytes": 3036594,- "scriptRequestCount": 88,- "totalRawBytes": 3332579+ "otherRawBytes": 96445,+ "requestCount": 93,+ "scriptRawBytes": 3043458,+ "scriptRequestCount": 87,+ "totalRawBytes": 3339491},- "routeReadyMedianMs": 826.2000000001863,+ "routeReadyMedianMs": 809.2999999970198,"scriptSourceOwnerSet": "editor-minimal-static","stateProfile": "representative"}@@ -940,6 +940,7 @@"source:src/app/AppProviders.tsx","source:src/app/GalleryImageActionsBridge.tsx","source:src/app/GalleryUiAdapter.tsx",+ "source:src/app/GenerateWidgetSyncRuntime.tsx","source:src/app/GenerationUiAdapter.tsx","source:src/app/I18nController.tsx","source:src/app/ModelsUiAdapter.tsx",@@ -951,6 +952,7 @@"source:src/app/WorkbenchApp.tsx","source:src/app/WorkflowUiAdapter.tsx","source:src/app/accountLifecycle.ts",+ "source:src/app/generateWidgetSyncRuntime.ts","source:src/app/main.tsx","source:src/app/router.tsx","source:src/app/workbenchPorts.tsx",@@ -1001,8 +1003,10 @@"source:src/features/generation/core/prompt/dynamicPromptSyntax.ts","source:src/features/generation/core/prompt/highlight.ts","source:src/features/generation/core/promptHistory.ts",+ "source:src/features/generation/core/promptTemplateOwnership.ts","source:src/features/generation/core/promptTemplates.ts","source:src/features/generation/core/referenceImage.ts",+ "source:src/features/generation/core/resolveGenerateWidgetValues.ts","source:src/features/generation/core/settings.ts","source:src/features/generation/core/wildcardCatalog.ts","source:src/features/generation/core/wildcardTransfer.ts",@@ -1013,6 +1017,7 @@"source:src/features/generation/data/wildcards.ts","source:src/features/generation/graph.ts","source:src/features/generation/prompts.ts",+ "source:src/features/generation/queries.ts","source:src/features/generation/react.ts","source:src/features/generation/settings.ts","source:src/features/generation/ui/GenerateAdvancedFields.tsx",@@ -1039,6 +1044,7 @@"source:src/features/generation/ui/promptFields/PromptLineNumbers.tsx","source:src/features/generation/ui/promptFields/PromptPanelHeader.tsx","source:src/features/generation/ui/promptFields/PromptTemplateEditor.tsx",+ "source:src/features/generation/ui/promptFields/PromptTemplateImage.tsx","source:src/features/generation/ui/promptFields/PromptTemplatesButton.tsx","source:src/features/generation/ui/promptFields/PromptTemplatesPanel.tsx","source:src/features/generation/ui/promptFields/PromptTextarea.tsx",@@ -1052,6 +1058,7 @@"source:src/features/generation/ui/promptFields/promptFocus.ts","source:src/features/generation/ui/promptFields/promptHistoryNavigation.ts","source:src/features/generation/ui/promptFields/promptTriggerOptions.ts",+ "source:src/features/generation/ui/promptFields/useDismissOnViewportChange.ts","source:src/features/generation/ui/promptFields/usePromptTriggerAutocomplete.tsx","source:src/features/generation/ui/promptFields/usePromptTriggerPicker.ts","source:src/features/generation/ui/promptTemplateDraftStore.ts",@@ -1237,6 +1244,7 @@"source:src/features/workflow/widget.ts","source:src/platform/browser/downloadBlob.ts","source:src/platform/browser/knownBrowserIssues.ts",+ "source:src/platform/core/json.ts","source:src/platform/i18n/client.ts","source:src/platform/i18n/languages.ts","source:src/platform/performance/semanticReady.ts",@@ -1743,6 +1751,7 @@"source:src/app/AppProviders.tsx","source:src/app/GalleryImageActionsBridge.tsx","source:src/app/GalleryUiAdapter.tsx",+ "source:src/app/GenerateWidgetSyncRuntime.tsx","source:src/app/GenerationUiAdapter.tsx","source:src/app/I18nController.tsx","source:src/app/ModelsUiAdapter.tsx",@@ -1754,6 +1763,7 @@"source:src/app/WorkbenchApp.tsx","source:src/app/WorkflowUiAdapter.tsx","source:src/app/accountLifecycle.ts",+ "source:src/app/generateWidgetSyncRuntime.ts","source:src/app/main.tsx","source:src/app/router.tsx","source:src/app/workbenchPorts.tsx",@@ -1805,8 +1815,10 @@"source:src/features/generation/core/prompt/dynamicPromptSyntax.ts","source:src/features/generation/core/prompt/highlight.ts","source:src/features/generation/core/promptHistory.ts",+ "source:src/features/generation/core/promptTemplateOwnership.ts","source:src/features/generation/core/promptTemplates.ts","source:src/features/generation/core/referenceImage.ts",+ "source:src/features/generation/core/resolveGenerateWidgetValues.ts","source:src/features/generation/core/settings.ts","source:src/features/generation/core/wildcardCatalog.ts","source:src/features/generation/core/wildcardTransfer.ts",@@ -1817,6 +1829,7 @@"source:src/features/generation/data/wildcards.ts","source:src/features/generation/graph.ts","source:src/features/generation/prompts.ts",+ "source:src/features/generation/queries.ts","source:src/features/generation/react.ts","source:src/features/generation/settings.ts","source:src/features/generation/ui/GenerateAdvancedFields.tsx",@@ -1843,6 +1856,7 @@"source:src/features/generation/ui/promptFields/PromptLineNumbers.tsx","source:src/features/generation/ui/promptFields/PromptPanelHeader.tsx","source:src/features/generation/ui/promptFields/PromptTemplateEditor.tsx",+ "source:src/features/generation/ui/promptFields/PromptTemplateImage.tsx","source:src/features/generation/ui/promptFields/PromptTemplatesButton.tsx","source:src/features/generation/ui/promptFields/PromptTemplatesPanel.tsx","source:src/features/generation/ui/promptFields/PromptTextarea.tsx",@@ -1856,6 +1870,7 @@"source:src/features/generation/ui/promptFields/promptFocus.ts","source:src/features/generation/ui/promptFields/promptHistoryNavigation.ts","source:src/features/generation/ui/promptFields/promptTriggerOptions.ts",+ "source:src/features/generation/ui/promptFields/useDismissOnViewportChange.ts","source:src/features/generation/ui/promptFields/usePromptTriggerAutocomplete.tsx","source:src/features/generation/ui/promptFields/usePromptTriggerPicker.ts","source:src/features/generation/ui/promptTemplateDraftStore.ts",@@ -2041,6 +2056,7 @@"source:src/features/workflow/widget.ts","source:src/platform/browser/downloadBlob.ts","source:src/platform/browser/knownBrowserIssues.ts",+ "source:src/platform/core/json.ts","source:src/platform/i18n/client.ts","source:src/platform/i18n/languages.ts","source:src/platform/performance/semanticReady.ts",diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryActions.ts b/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryActions.tsindex deb11bd21f..7f7a58a600 100644--- a/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryActions.ts+++ b/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryActions.ts@@ -25,10 +25,6 @@ const ACCEPTED_UPLOAD_TYPES = new Set(['image/png', 'image/jpeg', 'image/webp'])const toErrorMessage = (error: unknown): string => (error instanceof Error ? error.message : String(error));-const saveBlobToDisk = (blob: Blob, fileName: string): void => {- downloadBlob(blob, fileName);-};-export const useGalleryActions = ({boards,loadMore,@@ -130,7 +126,7 @@ export const useGalleryActions = ({const { blob, fileName } = await downloadGalleryArchive({ boardId, signal: owner.signal });assertAccountScopeCurrent(owner);- saveBlobToDisk(blob, fileName);+ downloadBlob(blob, fileName);recordSuccess('Download ready');} catch (error: unknown) {if (!isAccountScopeCurrent(owner)) {diff --git a/invokeai/frontend/webv2/src/features/generation/core/resolveGenerateWidgetValues.ts b/invokeai/frontend/webv2/src/features/generation/core/resolveGenerateWidgetValues.tsindex 2003ddf5b3..fc8bd06ae4 100644--- a/invokeai/frontend/webv2/src/features/generation/core/resolveGenerateWidgetValues.ts+++ b/invokeai/frontend/webv2/src/features/generation/core/resolveGenerateWidgetValues.ts@@ -1,3 +1,5 @@+import { areJsonValuesStructurallyEqual } from '@platform/core/json';+import type { GenerationModelCatalogItem } from './contracts';import type { PromptTemplateSnapshot } from './promptTemplates';import type { GenerateWidgetValues } from './types';@@ -37,40 +39,13 @@ export interface ResolvedGenerateWidgetValues {const isRecord = (value: unknown): value is Record<string, unknown> => Boolean(value) && typeof value === 'object';-const areValuesEqual = (left: unknown, right: unknown): boolean => {- if (Object.is(left, right)) {- return true;- }-- if (Array.isArray(left) || Array.isArray(right)) {- return (- Array.isArray(left) &&- Array.isArray(right) &&- left.length === right.length &&- left.every((value, index) => areValuesEqual(value, right[index]))- );- }-- if (!isRecord(left) || !isRecord(right)) {- return false;- }-- const leftKeys = Object.keys(left);- const rightKeys = Object.keys(right);-- return (- leftKeys.length === rightKeys.length &&- leftKeys.every((key) => Object.hasOwn(right, key) && areValuesEqual(left[key], right[key]))- );-};-const hasSystemDifference = (storedValues: unknown, values: GenerateWidgetValues): boolean => {if (!isRecord(storedValues)) {return true;}return Object.entries(values).some(- ([key, value]) => key !== 'batchCount' && !areValuesEqual(storedValues[key], value)+ ([key, value]) => key !== 'batchCount' && !areJsonValuesStructurallyEqual(storedValues[key], value));};diff --git a/invokeai/frontend/webv2/src/features/generation/data/promptTemplates.ts b/invokeai/frontend/webv2/src/features/generation/data/promptTemplates.tsindex 83315cdbac..dc002d788f 100644--- a/invokeai/frontend/webv2/src/features/generation/data/promptTemplates.ts+++ b/invokeai/frontend/webv2/src/features/generation/data/promptTemplates.ts@@ -12,6 +12,7 @@*/import type { PromptTemplateSnapshot } from '@features/generation/core/promptTemplates';+import type { AccountScope } from '@platform/state/accountLifecycle';import type { QueryClient } from '@tanstack/react-query';import { assertAccountScopeCurrent, captureAccountScope } from '@platform/state/accountLifecycle';@@ -188,11 +189,13 @@ export const deletePromptTemplate = async (id: string): Promise<void> => {};/** Accepts the CSV and JSON shapes documented by the backend's importer. */-export const importPromptTemplates = async (file: File): Promise<void> => {+export const importPromptTemplates = async (file: File, owner: AccountScope): Promise<void> => {const body = new FormData();body.append('file', file);- await apiFetch(`${PROMPT_TEMPLATES_BASE}/import`, { body, method: 'POST' });+ assertAccountScopeCurrent(owner);+ await apiFetch(`${PROMPT_TEMPLATES_BASE}/import`, { body, method: 'POST', signal: owner.signal });+ assertAccountScopeCurrent(owner);};/**@@ -200,10 +203,13 @@ export const importPromptTemplates = async (file: File): Promise<void> => {* `apiFetchJson`. It also cannot be an anchor download: the URL alone carries no* `Authorization` header, and only the transport injects one.*/-export const exportPromptTemplates = async (): Promise<Blob> => {- const response = await apiFetch(`${PROMPT_TEMPLATES_BASE}/export`);+export const exportPromptTemplates = async (owner: AccountScope): Promise<Blob> => {+ const response = await apiFetch(`${PROMPT_TEMPLATES_BASE}/export`, { signal: owner.signal });+ assertAccountScopeCurrent(owner);+ const blob = await response.blob();- return await response.blob();+ assertAccountScopeCurrent(owner);+ return blob;};export const invalidatePromptTemplates = async (queryClient: QueryClient, id?: string): Promise<void> => {diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplateImage.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplateImage.tsxindex e18eb3bba3..f6a9bc8b4b 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplateImage.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplateImage.tsx@@ -52,7 +52,7 @@ export const PromptTemplateImage = ({return localPreviewUrl ? <Image {...IMAGE_OUTLINE_PROPS} {...imageProps} src={localPreviewUrl} /> : fallback;}- if (!query.data) {+ if (!template.hasImage || !query.data) {return fallback;}diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplates.browser.test.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplates.browser.test.tsxindex 5a59c58b8c..b01db1eeba 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplates.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplates.browser.test.tsx@@ -3,10 +3,11 @@ import type { PromptTemplateRecord } from '@features/generation/data/promptTemplimport type { PromptTemplateCatalog } from '@features/generation/ui/usePromptTemplates';import { Box, ChakraProvider } from '@chakra-ui/react';-import { promptTemplateKeys } from '@features/generation/data/promptTemplates';+import { exportPromptTemplates, promptTemplateKeys } from '@features/generation/data/promptTemplates';import { PromptTemplateEditor } from '@features/generation/ui/promptFields/PromptTemplateEditor';import { PromptTemplateImage } from '@features/generation/ui/promptFields/PromptTemplateImage';import { PromptTemplatesPanel } from '@features/generation/ui/promptFields/PromptTemplatesPanel';+import { accountLifecycle } from '@platform/state/accountLifecycle';import { QueryClient, QueryClientProvider } from '@tanstack/react-query';import { system } from '@theme/system';import i18next from 'i18next';@@ -16,16 +17,29 @@ import { I18nextProvider, initReactI18next } from 'react-i18next';import { afterEach, describe, expect, it, vi } from 'vitest';import { userEvent } from 'vitest/browser';+const dependencies = vi.hoisted(() => ({+ apiFetch: vi.fn(),+ canManagePromptTemplates: false,+ downloadBlob: vi.fn(),+}));+// Both panels report failures through Generation's UI port and read the// import/export capability from it; only the app composes that. The rest is real.vi.mock('@features/generation/ui/GenerationUiContext', async (importOriginal) => ({...(await importOriginal<object>()),useGenerationUi: () => ({- capabilities: { canManagePromptTemplates: false },+ capabilities: { canManagePromptTemplates: dependencies.canManagePromptTemplates },notifications: { error: vi.fn(), info: vi.fn(), reportError: vi.fn() },}),}));+vi.mock('@platform/browser/downloadBlob', () => ({ downloadBlob: dependencies.downloadBlob }));++vi.mock('@platform/transport/http', async (importOriginal) => ({+ ...(await importOriginal<object>()),+ apiFetch: dependencies.apiFetch,+}));+// The subtree of `public/locales/en.json` these panels read, copied verbatim so// the assertions below can name the strings a user actually sees. Importing the// catalogue itself is not an option — Vite does not serve `public/` to modules.@@ -210,6 +224,10 @@ afterEach(async () => {host = null;root = null;vi.restoreAllMocks();+ dependencies.apiFetch.mockReset();+ dependencies.canManagePromptTemplates = false;+ dependencies.downloadBlob.mockReset();+ accountLifecycle.invalidate();document.documentElement.className = '';delete document.documentElement.dataset.theme;});@@ -674,6 +692,80 @@ it('keeps the fetched image URL live through StrictMode replay and revokes everyexpect(revokedUrls.has(liveUrl)).toBe(true);});+it('removes a cached fetched image when the authoritative template no longer has one', async () => {+ let sequence = 0;+ const revokedUrls = new Set<string>();+ vi.spyOn(URL, 'createObjectURL').mockImplementation(() => `blob:removed-template-preview-${++sequence}`);+ vi.spyOn(URL, 'revokeObjectURL').mockImplementation((url) => revokedUrls.add(url));++ const RemovedImageProbe = () => {+ const [hasImage, setHasImage] = useState(true);++ return (+ <>+ <button onClick={() => setHasImage(false)}>Remove stored image</button>+ <PromptTemplateImage+ alt="Fetched preview"+ fallback={IMAGE_FALLBACK}+ template={hasImage ? templateWithImage : userTemplate}+ />+ </>+ );+ };++ await render(<RemovedImageProbe />, (queryClient) =>+ queryClient.setQueryData(promptTemplateKeys.image(templateWithImage.id), new Blob(['image']))+ );++ const liveUrl = host!.querySelector<HTMLImageElement>('img[alt="Fetched preview"]')!.src;++ await act(async () => {+ await userEvent.click(buttonWithText('Remove stored image'));+ });++ expect(host!.querySelector('img[alt="Fetched preview"]')).toBeNull();+ expect(host!.textContent).toContain('fallback');+ expect(revokedUrls.has(liveUrl)).toBe(true);+});++it('does not download a prompt-template export whose body finishes after account rotation', async () => {+ let resolveBody!: (blob: Blob) => void;+ const body = new Promise<Blob>((resolve) => {+ resolveBody = resolve;+ });+ const owner = accountLifecycle.activate('prompt-export-a', ':user:prompt-export-a');++ dependencies.canManagePromptTemplates = true;+ dependencies.apiFetch.mockResolvedValue({ blob: () => body });++ await render(+ <PromptTemplatesPanel+ activeTemplate={null}+ catalog={createCatalog({ exportCsv: exportPromptTemplates })}+ isActiveTemplateMissing={false}+ onApply={vi.fn()}+ onCreate={vi.fn()}+ onDetach={vi.fn()}+ onEdit={vi.fn()}+ />+ );++ await act(async () => {+ await userEvent.click(buttonWithText('Export'));+ await vi.waitFor(() => expect(dependencies.apiFetch).toHaveBeenCalledOnce());+ });++ expect(dependencies.apiFetch).toHaveBeenCalledWith('/api/v1/style_presets/export', { signal: owner.signal });++ await act(async () => {+ accountLifecycle.activate('prompt-export-b', ':user:prompt-export-b');+ resolveBody(new Blob(['name,prompt']));+ await body;+ });++ expect(dependencies.downloadBlob).not.toHaveBeenCalled();+});+describe('prompt template image outlines', () => {const modes = [['light', 'light', 'oklch(0 0 0 / 0.1)'],diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplatesPanel.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplatesPanel.tsxindex 83e020fd7f..115b3fc2f4 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplatesPanel.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplatesPanel.tsx@@ -11,6 +11,11 @@ import { useGenerationUi } from '@features/generation/ui/GenerationUiContext';import { PANEL_HEADER_CONTROL_HEIGHT, PromptPanelHeader } from '@features/generation/ui/promptFields/PromptPanelHeader';import { PromptTemplateImage } from '@features/generation/ui/promptFields/PromptTemplateImage';import { downloadBlob } from '@platform/browser/downloadBlob';+import {+ assertAccountScopeCurrent,+ captureAccountScope,+ isAccountScopeCurrent,+} from '@platform/state/accountLifecycle';import { getApiErrorMessage } from '@platform/transport/http';import { Button, IconButton } from '@platform/ui/Button';import { ConfirmDialog } from '@platform/ui/ConfirmDialog';@@ -232,11 +237,16 @@ const PromptTemplateTransferActions = ({ catalog }: { catalog: PromptTemplateCatconst runImport = useCallback(async (file: File) => {+ const owner = captureAccountScope();setIsBusy(true);try {- await catalog.importFile(file);+ await catalog.importFile(file, owner);} catch (caught) {+ if (!isAccountScopeCurrent(owner)) {+ return;+ }+reportError('import-prompt-templates', caught, t('widgets.generate.promptTemplates.couldNotImport'));} finally {setIsBusy(false);@@ -246,11 +256,19 @@ const PromptTemplateTransferActions = ({ catalog }: { catalog: PromptTemplateCat);const runExport = useCallback(async () => {+ const owner = captureAccountScope();setIsBusy(true);try {- downloadBlob(await catalog.exportCsv(), 'prompt_templates.csv');+ const blob = await catalog.exportCsv(owner);++ assertAccountScopeCurrent(owner);+ downloadBlob(blob, 'prompt_templates.csv');} catch (caught) {+ if (!isAccountScopeCurrent(owner)) {+ return;+ }+reportError('export-prompt-templates', caught, t('widgets.generate.promptTemplates.couldNotExport'));} finally {setIsBusy(false);diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/WildcardTransferActions.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/WildcardTransferActions.tsxindex fef08ac9c4..26c004e9f2 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/WildcardTransferActions.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/WildcardTransferActions.tsx@@ -1,6 +1,7 @@import type { WildcardImportEntry, WildcardImportResolution } from '@features/generation/core/wildcardTransfer';import type { WildcardCatalog } from '@features/generation/ui/useWildcards';import type { WildcardExportFormat, WildcardFileSource } from '@features/generation/ui/wildcardFiles';+import type { AccountScope } from '@platform/state/accountLifecycle';import type { ChangeEvent } from 'react';import { HStack, Menu, Portal } from '@chakra-ui/react';@@ -16,6 +17,11 @@ import {WILDCARD_IMPORT_ACCEPT,WildcardFileError,} from '@features/generation/ui/wildcardFiles';+import {+ assertAccountScopeCurrent,+ captureAccountScope,+ isAccountScopeCurrent,+} from '@platform/state/accountLifecycle';import { getApiErrorMessage } from '@platform/transport/http';import { Button } from '@platform/ui/Button';import { MenuContent } from '@platform/ui/Menu';@@ -42,7 +48,10 @@ export const WildcardTransferActions = ({ catalog }: { catalog: WildcardCatalogconst fileInputRef = useRef<HTMLInputElement | null>(null);const directoryInputRef = useRef<HTMLInputElement | null>(null);const [isBusy, setIsBusy] = useState(false);- const [pendingEntries, setPendingEntries] = useState<WildcardImportEntry[] | null>(null);+ const [pendingImport, setPendingImport] = useState<{+ entries: WildcardImportEntry[];+ owner: AccountScope;+ } | null>(null);const reportError = useCallback((area: string, caught: unknown, fallback: string) =>@@ -55,16 +64,27 @@ export const WildcardTransferActions = ({ catalog }: { catalog: WildcardCatalog);const applyImport = useCallback(- async (entries: readonly WildcardImportEntry[], resolutions: Record<string, WildcardImportResolution>) => {- const actions = getWildcardImportActions(entries, resolutions, new Set(catalog.wildcards.map((w) => w.name)));-+ async (+ entries: readonly WildcardImportEntry[],+ resolutions: Record<string, WildcardImportResolution>,+ owner: AccountScope+ ) => {+ let actionCount = 0;setIsBusy(true);try {+ assertAccountScopeCurrent(owner);+ const actions = getWildcardImportActions(entries, resolutions, new Set(catalog.wildcards.map((w) => w.name)));++ actionCount = actions.length;notifications.info(- t('widgets.generate.dynamicPrompts.importedCount', { count: await catalog.applyWrites(actions) })+ t('widgets.generate.dynamicPrompts.importedCount', { count: await catalog.applyWrites(actions, owner) }));} catch (caught) {+ if (!isAccountScopeCurrent(owner)) {+ return;+ }+// Writes go one at a time, so a failure part-way leaves real wildcards// behind. Saying only that the import failed sent people back for a// second run that then clashed with everything the first one had made.@@ -74,12 +94,12 @@ export const WildcardTransferActions = ({ catalog }: { catalog: WildcardCatalog'import-wildcards',caught,done > 0- ? t('widgets.generate.dynamicPrompts.couldNotImportAfter', { done, total: actions.length })+ ? t('widgets.generate.dynamicPrompts.couldNotImportAfter', { done, total: actionCount }): t('widgets.generate.dynamicPrompts.couldNotImport'));} finally {setIsBusy(false);- setPendingEntries(null);+ setPendingImport(null);}},[catalog, notifications, reportError, t]@@ -87,21 +107,30 @@ export const WildcardTransferActions = ({ catalog }: { catalog: WildcardCatalogconst startImport = useCallback(async (files: readonly File[], source: WildcardFileSource) => {+ const owner = captureAccountScope();setIsBusy(true);try {- const entries = planWildcardImport(await readWildcardFiles(files, source), catalog.wildcards);+ const parsed = await readWildcardFiles(files, source, owner);++ assertAccountScopeCurrent(owner);+ const entries = planWildcardImport(parsed, catalog.wildcards);+ assertAccountScopeCurrent(owner);// Nothing to decide and nothing to explain — the file pick was the// confirmation, so a dialog with only an Import button would be a click// that tells the user what they already know.if (entries.every((entry) => entry.rejection === null && entry.conflictId === null)) {- await applyImport(entries, {});+ await applyImport(entries, {}, owner);return;}- setPendingEntries(entries);+ setPendingImport({ entries, owner });} catch (caught) {+ if (!isAccountScopeCurrent(owner)) {+ return;+ }+reportError('import-wildcards',caught,@@ -118,9 +147,15 @@ export const WildcardTransferActions = ({ catalog }: { catalog: WildcardCatalogconst runExport = useCallback(async (format: WildcardExportFormat) => {+ const owner = captureAccountScope();+try {- await downloadWildcards(catalog.wildcards, format);+ await downloadWildcards(catalog.wildcards, format, owner);} catch (caught) {+ if (!isAccountScopeCurrent(owner)) {+ return;+ }+reportError('export-wildcards', caught, t('widgets.generate.dynamicPrompts.couldNotExport'));}},@@ -168,11 +203,12 @@ export const WildcardTransferActions = ({ catalog }: { catalog: WildcardCatalog[runExport]);- const cancelImport = useCallback(() => setPendingEntries(null), []);+ const cancelImport = useCallback(() => setPendingImport(null), []);const confirmImport = useCallback(- (resolutions: Record<string, WildcardImportResolution>) => applyImport(pendingEntries ?? [], resolutions),- [applyImport, pendingEntries]+ (resolutions: Record<string, WildcardImportResolution>) =>+ pendingImport ? applyImport(pendingImport.entries, resolutions, pendingImport.owner) : Promise.resolve(),+ [applyImport, pendingImport]);return (@@ -230,8 +266,8 @@ export const WildcardTransferActions = ({ catalog }: { catalog: WildcardCatalogwildcards in folders, and only a directory pick supplies the relativepath that turns `animals/dogs.txt` into `animals/dogs`. */}<input {...DIRECTORY_INPUT_PROPS} hidden ref={directoryInputRef} type="file" onChange={handleDirectoryChange} />- {pendingEntries ? (- <WildcardImportDialog entries={pendingEntries} onCancel={cancelImport} onConfirm={confirmImport} />+ {pendingImport ? (+ <WildcardImportDialog entries={pendingImport.entries} onCancel={cancelImport} onConfirm={confirmImport} />) : null}</HStack>);diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/WildcardsPanel.browser.test.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/WildcardsPanel.browser.test.tsxindex fc267d2eb0..d0755d9cba 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/WildcardsPanel.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/WildcardsPanel.browser.test.tsx@@ -2,6 +2,8 @@ import type { WildcardCatalog } from '@features/generation/ui/useWildcards';import { ChakraProvider } from '@chakra-ui/react';import { WildcardsPanel } from '@features/generation/ui/promptFields/WildcardsPanel';+import { WILDCARD_COLLECTION_FORMATS } from '@features/generation/ui/wildcardFiles';+import { accountLifecycle } from '@platform/state/accountLifecycle';import { system } from '@theme/system';import { act } from 'react';import { createRoot, type Root } from 'react-dom/client';@@ -68,6 +70,69 @@ afterEach(async () => {host?.remove();host = null;root = null;+ accountLifecycle.invalidate();+ vi.restoreAllMocks();+});++it('does not automatically write a YAML import whose parser finishes after account rotation', async () => {+ let resolveParse!: (value: unknown) => void;+ const parsed = new Promise<unknown>((resolve) => {+ resolveParse = resolve;+ });+ const yaml = WILDCARD_COLLECTION_FORMATS.find((format) => format.id === 'yaml')!;+ const parse = vi.spyOn(yaml, 'parse').mockReturnValue(parsed);+ const applyWrites = vi.fn(() => Promise.resolve(1));++ accountLifecycle.activate('wildcard-import-a', ':user:wildcard-import-a');+ await renderPanel(true, { ...catalog, applyWrites, knownNames: new Set(), wildcards: [] });++ const input = host!.querySelector<HTMLInputElement>(+ `input[accept="${'.txt,.yaml,.yml,.json,text/plain,application/json'}"]`+ )!;+ await act(async () => {+ await userEvent.upload(input, new File(['colors:\\n - red\\n'], 'wildcards.yaml', { type: 'text/yaml' }));+ await vi.waitFor(() => expect(parse).toHaveBeenCalledOnce());+ });++ await act(async () => {+ accountLifecycle.activate('wildcard-import-b', ':user:wildcard-import-b');+ resolveParse({ colors: ['red'] });+ await parsed;+ await new Promise<void>((resolve) => {+ globalThis.setTimeout(resolve, 50);+ });+ });++ expect(applyWrites).not.toHaveBeenCalled();+});++it('quietly refuses a conflict-dialog import after its originating account rotates', async () => {+ const applyWrites = vi.fn(() => Promise.resolve(1));++ accountLifecycle.activate('wildcard-dialog-a', ':user:wildcard-dialog-a');+ await renderPanel(true, { ...catalog, applyWrites });++ const input = host!.querySelector<HTMLInputElement>(+ `input[accept="${'.txt,.yaml,.yml,.json,text/plain,application/json'}"]`+ )!;+ await act(async () => {+ await userEvent.upload(input, new File(['blue'], 'colors.txt', { type: 'text/plain' }));+ });+ await vi.waitFor(() => expect(document.querySelector('[role="alertdialog"]')).not.toBeNull());++ accountLifecycle.activate('wildcard-dialog-b', ':user:wildcard-dialog-b');+ const confirm = [...document.querySelectorAll<HTMLButtonElement>('[role="alertdialog"] button')].find((button) =>+ button.textContent?.includes('import')+ )!;++ await act(async () => {+ await userEvent.click(confirm);+ await new Promise<void>((resolve) => {+ globalThis.setTimeout(resolve, 50);+ });+ });++ expect(applyWrites).not.toHaveBeenCalled();});describe('wildcard values editor', () => {diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptTemplateDraftStore.browser.test.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptTemplateDraftStore.browser.test.tsxindex c21f11b3c2..5c0f2741b4 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/promptTemplateDraftStore.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptTemplateDraftStore.browser.test.tsx@@ -1,3 +1,4 @@+import { accountLifecycle } from '@platform/state/accountLifecycle';import { act, useLayoutEffect } from 'react';import { createRoot, type Root } from 'react-dom/client';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';@@ -56,6 +57,7 @@ beforeEach(() => {afterEach(async () => {await act(() => root.unmount());host.remove();+ accountLifecycle.invalidate();});describe('useOnPendingPromptTemplateDraft', () => {@@ -99,6 +101,17 @@ describe('useOnPendingPromptTemplateDraft', () => {expect(onDraft).toHaveBeenCalledOnce();});+ it('does not deliver account A draft after account B becomes active', async () => {+ const onDraft = vi.fn();+ accountLifecycle.activate('draft-a', ':user:draft-a');+ setPendingPromptTemplateDraft(beforeMountDraft);++ accountLifecycle.activate('draft-b', ':user:draft-b');+ await act(() => root.render(<Probe onDraft={onDraft} />));++ expect(onDraft).not.toHaveBeenCalled();+ });+it('stops delivering after cleanup', async () => {const onDraft = vi.fn();await act(() => root.render(<Probe onDraft={onDraft} />));diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptTemplateDraftStore.ts b/invokeai/frontend/webv2/src/features/generation/ui/promptTemplateDraftStore.tsindex 77410ade77..2a821294c6 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/promptTemplateDraftStore.ts+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptTemplateDraftStore.ts@@ -12,6 +12,7 @@*/import { useMountEffect } from '@platform/react/useMountEffect';+import { registerAccountOwnedResource } from '@platform/state/accountLifecycle';import { createExternalStore } from '@platform/state/externalStore';import { useEffectEvent } from 'react';@@ -26,6 +27,11 @@ interface PendingPromptTemplateDraftState {const store = createExternalStore<PendingPromptTemplateDraftState>({ draft: null });+registerAccountOwnedResource({+ clear: () => store.setSnapshot({ draft: null }),+ name: 'pending-prompt-template-draft',+});+export const setPendingPromptTemplateDraft = (draft: PendingPromptTemplateDraft): void => store.setSnapshot({ draft });const takePendingPromptTemplateDraft = (): PendingPromptTemplateDraft | null => {diff --git a/invokeai/frontend/webv2/src/features/generation/ui/usePromptTemplates.browser.test.tsx b/invokeai/frontend/webv2/src/features/generation/ui/usePromptTemplates.browser.test.tsxindex e3df53d304..7e7c6bfc78 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/usePromptTemplates.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/usePromptTemplates.browser.test.tsx@@ -2,6 +2,7 @@ import type { PromptTemplateRecord } from '@features/generation/data/promptTemplimport { promptTemplateKeys } from '@features/generation/data/promptTemplates';import { usePromptTemplates, type PromptTemplateCatalog } from '@features/generation/ui/usePromptTemplates';+import { captureAccountScope } from '@platform/state/accountLifecycle';import { QueryClient, QueryClientProvider } from '@tanstack/react-query';import { act, createRef, type Ref, useImperativeHandle } from 'react';import { createRoot, type Root } from 'react-dom/client';@@ -133,7 +134,10 @@ describe('prompt template mutation invalidation', () => {const invalidateQueries = vi.spyOn(queryClient, 'invalidateQueries');await act(async () => {- await catalogRef.current!.importFile(new File(['name,prompt'], 'templates.csv', { type: 'text/csv' }));+ await catalogRef.current!.importFile(+ new File(['name,prompt'], 'templates.csv', { type: 'text/csv' }),+ captureAccountScope()+ );});expect(invalidateQueries).toHaveBeenCalledTimes(1);diff --git a/invokeai/frontend/webv2/src/features/generation/ui/usePromptTemplates.ts b/invokeai/frontend/webv2/src/features/generation/ui/usePromptTemplates.tsindex ae830e7969..b0ea33f94b 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/usePromptTemplates.ts+++ b/invokeai/frontend/webv2/src/features/generation/ui/usePromptTemplates.ts@@ -4,6 +4,7 @@ import type {PromptTemplateRecord,PromptTemplateUpdateDraft,} from '@features/generation/data/promptTemplates';+import type { AccountScope } from '@platform/state/accountLifecycle';import { classifyPromptTemplates, requireOwnedPromptTemplate } from '@features/generation/core/promptTemplateOwnership';import {@@ -42,8 +43,8 @@ export interface PromptTemplateCatalog {create: (draft: PromptTemplateCreateDraft) => Promise<PromptTemplateRecord>;update: (template: PromptTemplateRecord, draft: PromptTemplateUpdateDraft) => Promise<PromptTemplateRecord>;remove: (template: PromptTemplateRecord) => Promise<void>;- importFile: (file: File) => Promise<void>;- exportCsv: () => Promise<Blob>;+ importFile: (file: File, owner: AccountScope) => Promise<void>;+ exportCsv: (owner: AccountScope) => Promise<Blob>;}/**@@ -61,8 +62,7 @@ export const usePromptTemplates = ({ isEnabled = true }: { isEnabled?: boolean }const classified = useMemo(() => classifyPromptTemplates(query.data ?? [], account), [account, query.data]);const runAndInvalidate = useCallback(- async <T>(run: () => Promise<T>, imageId?: string): Promise<T> => {- const owner = captureAccountScope();+ async <T>(run: () => Promise<T>, imageId?: string, owner: AccountScope = captureAccountScope()): Promise<T> => {const result = await run();assertAccountScopeCurrent(owner);@@ -96,7 +96,7 @@ export const usePromptTemplates = ({ isEnabled = true }: { isEnabled?: boolean });const importFile = useCallback(- (file: File) => runAndInvalidate(() => importPromptTemplates(file)),+ (file: File, owner: AccountScope) => runAndInvalidate(() => importPromptTemplates(file, owner), undefined, owner),[runAndInvalidate]);diff --git a/invokeai/frontend/webv2/src/features/generation/ui/useWildcards.browser.test.tsx b/invokeai/frontend/webv2/src/features/generation/ui/useWildcards.browser.test.tsxindex 8f9a2636d4..45de08ad17 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/useWildcards.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/useWildcards.browser.test.tsx@@ -1,4 +1,5 @@import { useWildcards, WildcardWriteError } from '@features/generation/ui/useWildcards';+import { captureAccountScope } from '@platform/state/accountLifecycle';import { QueryClient, QueryClientProvider } from '@tanstack/react-query';import { act, createRef, type Ref, useImperativeHandle } from 'react';import { createRoot, type Root } from 'react-dom/client';@@ -64,7 +65,7 @@ describe('applyWrites', () => {// times over.it('invalidates once for the whole run, not once per write', async () => {await act(async () => {- await catalogRef.current!.applyWrites(WRITES);+ await catalogRef.current!.applyWrites(WRITES, captureAccountScope());});expect(createWildcard).toHaveBeenCalledTimes(2);@@ -76,7 +77,7 @@ describe('applyWrites', () => {let done = 0;await act(async () => {- done = await catalogRef.current!.applyWrites(WRITES);+ done = await catalogRef.current!.applyWrites(WRITES, captureAccountScope());});expect(done).toBe(3);@@ -91,7 +92,7 @@ describe('applyWrites', () => {let caught: unknown;await act(async () => {- caught = await catalogRef.current!.applyWrites(WRITES).catch((error: unknown) => error);+ caught = await catalogRef.current!.applyWrites(WRITES, captureAccountScope()).catch((error: unknown) => error);});expect(caught).toBeInstanceOf(WildcardWriteError);@@ -104,7 +105,7 @@ describe('applyWrites', () => {createWildcard.mockImplementationOnce(() => Promise.reject(new Error('nope')));await act(async () => {- await catalogRef.current!.applyWrites(WRITES).catch(() => undefined);+ await catalogRef.current!.applyWrites(WRITES, captureAccountScope()).catch(() => undefined);});expect(invalidateWildcardDependents).not.toHaveBeenCalled();diff --git a/invokeai/frontend/webv2/src/features/generation/ui/useWildcards.ts b/invokeai/frontend/webv2/src/features/generation/ui/useWildcards.tsindex 34b8e9c662..191bb22941 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/useWildcards.ts+++ b/invokeai/frontend/webv2/src/features/generation/ui/useWildcards.ts@@ -1,4 +1,5 @@import type { WildcardRecord } from '@features/generation/data/wildcards';+import type { AccountScope } from '@platform/state/accountLifecycle';import {createWildcard,@@ -53,7 +54,7 @@ export interface WildcardCatalog {* at a time meant re-fetching the whole catalog, plus every dynamic-prompt* expansion, between each write and the next.*/- applyWrites: (writes: readonly WildcardWrite[]) => Promise<number>;+ applyWrites: (writes: readonly WildcardWrite[], owner: AccountScope) => Promise<number>;}/**@@ -100,19 +101,21 @@ export const useWildcards = (): WildcardCatalog => {const remove = useCallback((id: string) => runAndInvalidate(() => deleteWildcard(id)), [runAndInvalidate]);const applyWrites = useCallback(- async (writes: readonly WildcardWrite[]): Promise<number> => {- const owner = captureAccountScope();+ async (writes: readonly WildcardWrite[], owner: AccountScope): Promise<number> => {let done = 0;let failure: unknown;try {for (const write of writes) {+ assertAccountScopeCurrent(owner);+if (write.id === undefined) {await createWildcard({ name: write.name, values: write.values });} else {await updateWildcard(write.id, { name: write.name, values: write.values });}+ assertAccountScopeCurrent(owner);done++;}} catch (caught) {diff --git a/invokeai/frontend/webv2/src/features/generation/ui/wildcardFiles.browser.test.ts b/invokeai/frontend/webv2/src/features/generation/ui/wildcardFiles.browser.test.tsindex caa8112030..f37bcec5e2 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/wildcardFiles.browser.test.ts+++ b/invokeai/frontend/webv2/src/features/generation/ui/wildcardFiles.browser.test.ts@@ -1,7 +1,20 @@-import { isSupportedWildcardFile, readWildcardFiles, WildcardFileError } from '@features/generation/ui/wildcardFiles';-import { describe, expect, it } from 'vitest';+import {+ downloadWildcards,+ isSupportedWildcardFile,+ readWildcardFiles,+ WILDCARD_COLLECTION_FORMATS,+ WildcardFileError,+} from '@features/generation/ui/wildcardFiles';+import { accountLifecycle } from '@platform/state/accountLifecycle';+import { afterEach, describe, expect, it, vi } from 'vitest';++const downloadText = vi.hoisted(() => vi.fn());++vi.mock('@platform/browser/downloadBlob', () => ({ downloadText }));const file = (name: string, contents: string) => new File([contents], name, { type: 'text/plain' });+const read = (files: readonly File[], source: 'files' | 'folder') =>+ readWildcardFiles(files, source, accountLifecycle.capture());/** What a directory pick hands over: a name plus the path relative to the root. */const inFolder = (path: string, contents: string): File => {@@ -12,42 +25,46 @@ const inFolder = (path: string, contents: string): File => {return picked;};+afterEach(() => {+ accountLifecycle.invalidate();+ downloadText.mockReset();+ vi.restoreAllMocks();+});+describe('readWildcardFiles', () => {it('reads a text file as one wildcard named after it', async () => {- await expect(readWildcardFiles([file('colours.txt', 'red\n# a note\n\ngreen')], 'files')).resolves.toEqual([+ await expect(read([file('colours.txt', 'red\n# a note\n\ngreen')], 'files')).resolves.toEqual([{ name: 'colours', values: ['red', 'green'] },]);});it('reads a nested yaml collection', async () => {- await expect(readWildcardFiles([file('all.yaml', 'animals:\n dogs:\n - corgi\n')], 'files')).resolves.toEqual([+ await expect(read([file('all.yaml', 'animals:\n dogs:\n - corgi\n')], 'files')).resolves.toEqual([{ name: 'animals/dogs', values: ['corgi'] },]);});it('reads a json collection', async () => {- await expect(readWildcardFiles([file('all.json', '{"moods":["calm"]}')], 'files')).resolves.toEqual([+ await expect(read([file('all.json', '{"moods":["calm"]}')], 'files')).resolves.toEqual([{ name: 'moods', values: ['calm'] },]);});it('takes an extensionless file as text', async () => {- await expect(readWildcardFiles([file('colours', 'red')], 'files')).resolves.toEqual([- { name: 'colours', values: ['red'] },- ]);+ await expect(read([file('colours', 'red')], 'files')).resolves.toEqual([{ name: 'colours', values: ['red'] }]);});// `accept` on a file input is a hint, not a rule, and a wildcard folder// routinely has a readme sitting in it. Read as text, that imported as a// wildcard named `README` whose values were the markdown.it('refuses a file that is not a supported format', async () => {- await expect(readWildcardFiles([file('README.md', '# Wildcards\n\nSome notes.')], 'files')).rejects.toBeInstanceOf(+ await expect(read([file('README.md', '# Wildcards\n\nSome notes.')], 'files')).rejects.toBeInstanceOf(WildcardFileError);});it('names the file it could not read', async () => {- await expect(readWildcardFiles([file('broken.json', '{ nope')], 'files')).rejects.toMatchObject({+ await expect(read([file('broken.json', '{ nope')], 'files')).rejects.toMatchObject({fileName: 'broken.json',});});@@ -58,7 +75,7 @@ describe('readWildcardFiles', () => {it('refuses a collection too large to import instead of overflowing', async () => {const huge = JSON.stringify(Object.fromEntries(Array.from({ length: 25_000 }, (_, i) => [`w${i}`, ['v']])));- await expect(readWildcardFiles([file('huge.json', huge)], 'files')).rejects.toBeInstanceOf(WildcardFileError);+ await expect(read([file('huge.json', huge)], 'files')).rejects.toBeInstanceOf(WildcardFileError);});// The whole point of picking a folder: a1111 nests wildcards in directories,@@ -67,7 +84,7 @@ describe('readWildcardFiles', () => {it('turns a folder`s nesting into `/` names', async () => {const picked = [inFolder('wildcards/animals/dogs.txt', 'corgi'), inFolder('wildcards/moods/dogs.txt', 'sleepy')];- await expect(readWildcardFiles(picked, 'folder')).resolves.toEqual([+ await expect(read(picked, 'folder')).resolves.toEqual([{ name: 'animals/dogs', values: ['corgi'] },{ name: 'moods/dogs', values: ['sleepy'] },]);@@ -76,7 +93,7 @@ describe('readWildcardFiles', () => {it('retains direct file names even when a relative path is present', async () => {const picked = inFolder('ignored/animals/dogs.txt', 'corgi');- await expect(readWildcardFiles([picked], 'files')).resolves.toEqual([{ name: 'dogs', values: ['corgi'] }]);+ await expect(read([picked], 'files')).resolves.toEqual([{ name: 'dogs', values: ['corgi'] }]);});});@@ -100,3 +117,21 @@ describe('isSupportedWildcardFile', () => {]);});});++it('does not download a wildcard export whose YAML serializer finishes after account rotation', async () => {+ let resolveStringify!: (value: string) => void;+ const serialized = new Promise<string>((resolve) => {+ resolveStringify = resolve;+ });+ const yaml = WILDCARD_COLLECTION_FORMATS.find((format) => format.id === 'yaml')!;+ vi.spyOn(yaml, 'stringify').mockReturnValue(serialized);+ const owner = accountLifecycle.activate('wildcard-export-a', ':user:wildcard-export-a');++ const exportPromise = downloadWildcards([{ name: 'colors', values: ['red'] }], 'yaml', owner);+ accountLifecycle.activate('wildcard-export-b', ':user:wildcard-export-b');+ resolveStringify('colors:\\n - red\\n');++ await exportPromise.catch(() => undefined);++ expect(downloadText).not.toHaveBeenCalled();+});diff --git a/invokeai/frontend/webv2/src/features/generation/ui/wildcardFiles.ts b/invokeai/frontend/webv2/src/features/generation/ui/wildcardFiles.tsindex 68f3733a1b..5f04ad3959 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/wildcardFiles.ts+++ b/invokeai/frontend/webv2/src/features/generation/ui/wildcardFiles.ts@@ -9,6 +9,7 @@*/import type { ParsedWildcard } from '@features/generation/core/wildcardTransfer';+import type { AccountScope } from '@platform/state/accountLifecycle';import {parseWildcardTextFile,@@ -16,6 +17,7 @@ import {wildcardsToNestedRecord,} from '@features/generation/core/wildcardTransfer';import { downloadText } from '@platform/browser/downloadBlob';+import { assertAccountScopeCurrent } from '@platform/state/accountLifecycle';/*** Every collection format, stated once.@@ -130,7 +132,8 @@ export const isSupportedWildcardFile = (file: File): boolean => {export const readWildcardFiles = async (files: readonly File[],- source: WildcardFileSource+ source: WildcardFileSource,+ owner: AccountScope): Promise<ParsedWildcard[]> => {const parsed: ParsedWildcard[] = [];@@ -154,12 +157,23 @@ export const readWildcardFiles = async (}const contents = await file.text();+ assertAccountScopeCurrent(owner);const collectionFormat = WILDCARD_COLLECTION_FORMATS.find((format) => hasExtension(path, ...format.extensions));if (collectionFormat) {+ let collection: unknown;++ try {+ collection = await collectionFormat.parse(contents);+ } catch {+ throw new WildcardFileError(file.name);+ }++ assertAccountScopeCurrent(owner);+try {- collect(wildcardsFromNestedRecord(await collectionFormat.parse(contents)), file.name);+ collect(wildcardsFromNestedRecord(collection), file.name);} catch {throw new WildcardFileError(file.name);}@@ -190,7 +204,8 @@ export const readWildcardFiles = async (*/export const downloadWildcards = async (wildcards: readonly ParsedWildcard[],- formatId: WildcardExportFormat+ formatId: WildcardExportFormat,+ owner: AccountScope): Promise<void> => {const format = WILDCARD_COLLECTION_FORMATS.find((candidate) => candidate.id === formatId);@@ -198,5 +213,8 @@ export const downloadWildcards = async (throw new Error(`Unknown wildcard export format: ${formatId}`);}- downloadText(await format.stringify(wildcardsToNestedRecord(wildcards)), `wildcards.${format.id}`, format.mimeType);+ const contents = await format.stringify(wildcardsToNestedRecord(wildcards));++ assertAccountScopeCurrent(owner);+ downloadText(contents, `wildcards.${format.id}`, format.mimeType);};diff --git a/invokeai/frontend/webv2/src/platform/core/json.test.ts b/invokeai/frontend/webv2/src/platform/core/json.test.tsnew file mode 100644index 0000000000..6bc96b5b51--- /dev/null+++ b/invokeai/frontend/webv2/src/platform/core/json.test.ts@@ -0,0 +1,46 @@+import { describe, expect, it } from 'vitest';++import { areJsonValuesStructurallyEqual } from './json';++describe('areJsonValuesStructurallyEqual', () => {+ it.each([+ [null, null, true],+ [true, true, true],+ [true, false, false],+ [3, 3, true],+ [3, 4, false],+ ['prompt', 'prompt', true],+ ['prompt', 'other', false],+ ])('compares primitive values (%j, %j)', (left, right, expected) => {+ expect(areJsonValuesStructurallyEqual(left, right)).toBe(expected);+ });++ it('compares arrays recursively and in order', () => {+ expect(areJsonValuesStructurallyEqual([1, { nested: ['a', null] }], [1, { nested: ['a', null] }])).toBe(true);+ expect(areJsonValuesStructurallyEqual([1, 2], [2, 1])).toBe(false);+ expect(areJsonValuesStructurallyEqual([1], [1, 2])).toBe(false);+ });++ it('compares object values independently of key insertion order', () => {+ expect(areJsonValuesStructurallyEqual({ a: 1, nested: { b: true } }, { nested: { b: true }, a: 1 })).toBe(true);+ expect(areJsonValuesStructurallyEqual({ a: 1 }, { a: 2 })).toBe(false);+ });++ it('distinguishes a missing key from a present key', () => {+ expect(areJsonValuesStructurallyEqual({ value: null }, {})).toBe(false);+ expect(areJsonValuesStructurallyEqual({}, { value: null })).toBe(false);+ });++ it('rejects distinct non-JSON objects while preserving object identity', () => {+ const same = new Date(0);++ expect(areJsonValuesStructurallyEqual(new Date(0), new Date(0))).toBe(false);+ expect(areJsonValuesStructurallyEqual(same, same)).toBe(true);+ expect(+ areJsonValuesStructurallyEqual(+ () => undefined,+ () => undefined+ )+ ).toBe(false);+ });+});diff --git a/invokeai/frontend/webv2/src/platform/core/json.ts b/invokeai/frontend/webv2/src/platform/core/json.tsnew file mode 100644index 0000000000..3adbcd5f63--- /dev/null+++ b/invokeai/frontend/webv2/src/platform/core/json.ts@@ -0,0 +1,42 @@+const isJsonObject = (value: unknown): value is Record<string, unknown> => {+ if (value === null || typeof value !== 'object' || Array.isArray(value)) {+ return false;+ }++ const prototype = Object.getPrototypeOf(value) as unknown;+ return prototype === Object.prototype || prototype === null;+};++/**+ * Structural equality for JSON-safe values.+ *+ * Unknown inputs are accepted at integration boundaries. Distinct non-JSON+ * objects are unequal; the same value or object identity still follows+ * `Object.is`.+ */+export const areJsonValuesStructurallyEqual = (left: unknown, right: unknown): boolean => {+ if (Object.is(left, right)) {+ return true;+ }++ if (Array.isArray(left) || Array.isArray(right)) {+ return (+ Array.isArray(left) &&+ Array.isArray(right) &&+ left.length === right.length &&+ left.every((value, index) => areJsonValuesStructurallyEqual(value, right[index]))+ );+ }++ if (!isJsonObject(left) || !isJsonObject(right)) {+ return false;+ }++ const leftKeys = Object.keys(left);+ const rightKeys = Object.keys(right);++ return (+ leftKeys.length === rightKeys.length &&+ leftKeys.every((key) => Object.hasOwn(right, key) && areJsonValuesStructurallyEqual(left[key], right[key]))+ );+};diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.tsindex 8f176740a5..aa16f04d47 100644--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.ts+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.ts@@ -106,6 +106,7 @@ import type { LayerTransform } from '@workbench/canvas-engine/transform/transforimport type { Rect, RenderFlags, ToolId, Vec2 } from '@workbench/canvas-engine/types';import type { CanvasProjectMutationPort } from '@workbench/canvasProjectMutationPort';+import { areJsonValuesStructurallyEqual } from '@platform/core/json';import { ControlPixelController } from '@workbench/canvas-engine/controllers/controlPixelController';import { EditingController } from '@workbench/canvas-engine/controllers/editingController';import { FilterResultController } from '@workbench/canvas-engine/controllers/filterResultController';@@ -178,7 +179,7 @@ import { createBitmapStore, type BitmapStore } from './document/bitmapStore';import { createDocumentMirror, type DocumentMirror } from './document/documentMirror';import { decideLayerChange } from './document/layerChangeDecision';import { getSourceBounds, getSourceContentRect, isRenderableLayer, renderableSourceOf } from './document/sources';-import { createLayerExportGuards, isDeeplyEqual, isSupportedExportSource } from './layerExportGuards';+import { createLayerExportGuards, isSupportedExportSource } from './layerExportGuards';import { createLayerRasterizer } from './layerRasterizer';import { createPreviewPublisher } from './previewPublisher';import { createRasterSnapshotCapture } from './rasterSnapshotCapture';@@ -1853,7 +1854,7 @@ export const createCanvasEngine = (opts: CanvasEngineOptions): CanvasEngineCoreCexpected: CanvasLayerContract): boolean => {const current = document?.layers.find((candidate) => candidate.id === expected.id);- return current !== undefined && isDeeplyEqual(current, expected);+ return current !== undefined && areJsonValuesStructurallyEqual(current, expected);};controlPixelController = new ControlPixelController({diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/layerExportGuards.test.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/layerExportGuards.test.tsindex d453d6c03e..ed0b99f9fc 100644--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/layerExportGuards.test.ts+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/layerExportGuards.test.ts@@ -10,7 +10,6 @@ import { beforeEach, describe, expect, it } from 'vitest';import {createLayerExportGuards,- isDeeplyEqual,isSupportedExportSource,type CreateLayerExportGuardsDeps,type LayerExportGuards,@@ -76,22 +75,6 @@ describe('isSupportedExportSource', () => {});});-describe('isDeeplyEqual', () => {- it('compares nested contract shapes structurally, not by identity', () => {- expect(isDeeplyEqual({ a: [1, { b: 2 }] }, { a: [1, { b: 2 }] })).toBe(true);- expect(isDeeplyEqual({ a: [1, { b: 2 }] }, { a: [1, { b: 3 }] })).toBe(false);- });-- it('does not treat an object as equal to a superset of itself', () => {- expect(isDeeplyEqual({ a: 1 }, { a: 1, b: 2 })).toBe(false);- expect(isDeeplyEqual({ a: 1, b: 2 }, { a: 1 })).toBe(false);- });-- it('distinguishes an array from a plain object with the same keys', () => {- expect(isDeeplyEqual([1, 2], { 0: 1, 1: 2 })).toBe(false);- });-});-describe('isCurrentRasterizationJob', () => {const jobFor = (overrides: Partial<RasterizationJob> = {}): RasterizationJob =>({ documentGeneration: 3, source: imageSource(), version: 7, ...overrides }) as RasterizationJob;diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/layerExportGuards.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/layerExportGuards.tsindex 6ad89cf6f2..4d272c0518 100644--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/layerExportGuards.ts+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/layerExportGuards.ts@@ -7,38 +7,10 @@ import type {import type { RasterizationJob } from '@workbench/canvas-engine/controllers/rasterController';import type { LayerCacheEntry, LayerCacheStore } from '@workbench/canvas-engine/render/layerCache';+import { areJsonValuesStructurallyEqual } from '@platform/core/json';import { getSourceContentRect, renderableSourceOf } from '@workbench/canvas-engine/document/sources';import { isEmpty } from '@workbench/canvas-engine/math/rect';-/** Structural equality for JSON-safe canvas contracts (including synthetic mask paint sources). */-export const isDeeplyEqual = (left: unknown, right: unknown): boolean => {- if (Object.is(left, right)) {- return true;- }- if (typeof left !== 'object' || left === null || typeof right !== 'object' || right === null) {- return false;- }- if (Array.isArray(left) || Array.isArray(right)) {- return (- Array.isArray(left) &&- Array.isArray(right) &&- left.length === right.length &&- left.every((value, index) => isDeeplyEqual(value, right[index]))- );- }- const leftRecord = left as Record<string, unknown>;- const rightRecord = right as Record<string, unknown>;- const leftKeys = Object.keys(leftRecord);- const rightKeys = Object.keys(rightRecord);- return (- leftKeys.length === rightKeys.length &&- leftKeys.every(- (key) =>- Object.prototype.hasOwnProperty.call(rightRecord, key) && isDeeplyEqual(leftRecord[key], rightRecord[key])- )- );-};-/** Polygon shapes have no raster path, so they can never back an export. */export const isSupportedExportSource = (source: CanvasLayerSourceContract): boolean => {if (source.type === 'shape') {@@ -92,7 +64,7 @@ export const createLayerExportGuards = (deps: CreateLayerExportGuardsDeps): Laye!!source &&job.version === layerCache.version(layer.id) &&job.documentGeneration === deps.getDocumentGeneration() &&- isDeeplyEqual(job.source, source)+ areJsonValuesStructurallyEqual(job.source, source));};diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/layerRasterizer.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/layerRasterizer.tsindex 5a7ee9f604..69c74d9d12 100644--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/layerRasterizer.ts+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/layerRasterizer.ts@@ -8,8 +8,9 @@ import type { LayerCacheStore } from '@workbench/canvas-engine/render/layerCacheimport type { RasterSurface } from '@workbench/canvas-engine/render/raster';import type { RasterizeResult } from '@workbench/canvas-engine/render/rasterizers';+import { areJsonValuesStructurallyEqual } from '@platform/core/json';import { getSourceContentRect, renderableSourceOf } from '@workbench/canvas-engine/document/sources';-import { isDeeplyEqual, isSupportedExportSource } from '@workbench/canvas-engine/layerExportGuards';+import { isSupportedExportSource } from '@workbench/canvas-engine/layerExportGuards';import { isEmpty } from '@workbench/canvas-engine/math/rect';import { textFontString } from '@workbench/canvas-engine/render/rasterizers/textRasterizer';@@ -125,7 +126,7 @@ export const createLayerRasterizer = (deps: CreateLayerRasterizerDeps): LayerRasexisting &&existing.version === version &&existing.documentGeneration === documentGeneration &&- isDeeplyEqual(existing.source, source)+ areJsonValuesStructurallyEqual(existing.source, source)) {if (!signal) {return existing.promise;@@ -150,7 +151,7 @@ export const createLayerRasterizer = (deps: CreateLayerRasterizerDeps): LayerRas!currentLayer ||jobs.getDocumentGeneration() !== documentGeneration ||layerCache.version(layer.id) !== version ||- !isDeeplyEqual(renderableSourceOf(currentLayer), source)+ !areJsonValuesStructurallyEqual(renderableSourceOf(currentLayer), source)) {return;}@@ -186,7 +187,7 @@ export const createLayerRasterizer = (deps: CreateLayerRasterizerDeps): LayerRas!currentLayer ||!currentEntry ||currentEntry.version !== version ||- !isDeeplyEqual(renderableSourceOf(currentLayer), source)+ !areJsonValuesStructurallyEqual(renderableSourceOf(currentLayer), source)) {return 'stale';}@@ -223,7 +224,7 @@ export const createLayerRasterizer = (deps: CreateLayerRasterizerDeps): LayerRasjobs.getDocumentGeneration() !== documentGeneration ||!currentLayer ||layerCache.version(layer.id) !== version ||- !isDeeplyEqual(renderableSourceOf(currentLayer), source)+ !areJsonValuesStructurallyEqual(renderableSourceOf(currentLayer), source)) {// The failure describes a layer that has already moved on; reporting it// would surface an error about work nobody is waiting for.diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/index.ts b/invokeai/frontend/webv2/src/workbench/image-actions/index.tsindex d750f4734b..78e1fb3c59 100644--- a/invokeai/frontend/webv2/src/workbench/image-actions/index.ts+++ b/invokeai/frontend/webv2/src/workbench/image-actions/index.ts@@ -18,4 +18,4 @@ export {export { executeImageRecall, getCurrentGenerateValues } from './executeImageRecall';export { RecallActionButtons } from './RecallActionButtons';export { getSelectedGalleryImage, getSelectedGalleryImageFromValues } from './selectedImage';-export { saveBlobToDisk, useImageActions, type ImageActions } from './useImageActions';+export { useImageActions, type ImageActions } from './useImageActions';diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.ts b/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.tsindex f17133dc6c..102c17cbca 100644--- a/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.ts+++ b/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.ts@@ -66,10 +66,6 @@ export interface ImageActions {useAsReferenceImage: (image: GalleryImage) => void;}-export const saveBlobToDisk = (blob: Blob, fileName: string): void => {- downloadBlob(blob, fileName);-};-const toErrorMessage = (error: unknown): string => (error instanceof Error ? error.message : String(error));const toPngBlob = async (blob: Blob): Promise<Blob> => {@@ -209,7 +205,7 @@ export const useImageActions = ({const { blob, fileName } = await galleryTransfers.downloadArchive({ imageNames, signal: owner.signal });assertAccountScopeCurrent(owner);- saveBlobToDisk(blob, fileName);+ downloadBlob(blob, fileName);recordSuccess('Download ready');} catch (error: unknown) {if (!isAccountScopeCurrent(owner)) {diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewNavigation.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewNavigation.browser.test.tsxindex a774e5bcfd..bbddeb035e 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewNavigation.browser.test.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewNavigation.browser.test.tsx@@ -149,7 +149,6 @@ vi.mock('@workbench/image-actions', () => ({getImageRecallTitle: () => '',getSelectedGalleryImage: () => null,getSelectedGalleryImageFromValues: () => null,- saveBlobToDisk: () => {},useImageActions: () => ({}),}));