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(canvas): harden canvas operation lifecycle
joshistoast2cee0317d121
diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/canvasOperationController.test.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/canvasOperationController.test.tsindex 3be63215dd..72aebce511 100644--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/canvasOperationController.test.ts+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/canvasOperationController.test.ts@@ -163,6 +163,113 @@ describe('createCanvasOperationController', () => {expect(publishNewer).toHaveBeenCalledWith('newer');});+ it('rechecks freshness after synchronous preview commit', async () => {+ const replacementCleanup = vi.fn();+ const controller = createCanvasOperationController({ isGuardCurrent: () => true });+ const session = controller.start({ cleanupPreview: vi.fn(), guard, identity: filterIdentity })!;++ const result = await session.run(+ () => Promise.resolve('prepared'),+ () => {+ controller.start({ cleanupPreview: replacementCleanup, guard, identity: selectObjectIdentity });+ }+ );++ expect(result).toBe('stale');+ expect(controller.getSnapshot()).toMatchObject({ identity: selectObjectIdentity, status: 'active' });+ expect(replacementCleanup).not.toHaveBeenCalled();+ });++ it('requires preview commit callbacks to be synchronous', () => {+ const controller = createCanvasOperationController({ isGuardCurrent: () => true });+ const session = controller.start({ cleanupPreview: vi.fn(), guard, identity: filterIdentity })!;++ if (Date.now() < 0) {+ const asyncCommit = (): Promise<void> => Promise.resolve();+ // @ts-expect-error Preview commit must not yield after the final freshness check.+ void session.run(() => Promise.resolve('prepared'), asyncCommit);+ }+ });++ it('treats AbortError from a superseded request as stale without publishing an error', async () => {+ const controller = createCanvasOperationController({ isGuardCurrent: () => true });+ const session = controller.start({ cleanupPreview: vi.fn(), guard, identity: filterIdentity })!;+ const commitOlder = vi.fn();+ const older = session.run(+ (signal) =>+ new Promise<string>((_resolve, reject) => {+ signal.addEventListener('abort', () => reject(new DOMException('superseded', 'AbortError')), { once: true });+ }),+ commitOlder+ );++ const commitNewer = vi.fn();+ const newer = session.run(() => Promise.resolve('newer'), commitNewer);++ await expect(older).resolves.toBe('stale');+ await expect(newer).resolves.toBe('published');+ expect(commitOlder).not.toHaveBeenCalled();+ expect(commitNewer).toHaveBeenCalledWith('newer');+ expect(controller.getSnapshot()).toMatchObject({ error: null, phase: 'ready', status: 'active' });+ });++ it.each(['replacement', 'reset', 'cancel'] as const)(+ 'preserves an operation started reentrantly during %s cleanup',+ (lifecycle) => {+ const controller = createCanvasOperationController({ isGuardCurrent: () => true });+ const replacementCleanup = vi.fn();+ const cleanupPreview = vi.fn(() => {+ controller.start({ cleanupPreview: replacementCleanup, guard, identity: selectObjectIdentity });+ });+ const session = controller.start({ cleanupPreview, guard, identity: filterIdentity })!;++ if (lifecycle === 'replacement') {+ controller.start({ cleanupPreview: vi.fn(), guard, identity: filterIdentity });+ } else if (lifecycle === 'reset') {+ session.reset();+ } else {+ session.cancel();+ }++ expect(cleanupPreview).toHaveBeenCalledOnce();+ expect(replacementCleanup).not.toHaveBeenCalled();+ expect(controller.getSnapshot()).toMatchObject({ identity: selectObjectIdentity, status: 'active' });+ }+ );++ it('preserves an operation started reentrantly during request cleanup', async () => {+ const controller = createCanvasOperationController({ isGuardCurrent: () => true });+ const replacementCleanup = vi.fn();+ const cleanupPreview = vi.fn(() => {+ controller.start({ cleanupPreview: replacementCleanup, guard, identity: selectObjectIdentity });+ });+ const session = controller.start({ cleanupPreview, guard, identity: filterIdentity })!;+ const work = vi.fn(() => Promise.resolve('prepared'));++ await expect(session.run(work, vi.fn())).resolves.toBe('stale');++ expect(cleanupPreview).toHaveBeenCalledOnce();+ expect(work).not.toHaveBeenCalled();+ expect(replacementCleanup).not.toHaveBeenCalled();+ expect(controller.getSnapshot()).toMatchObject({ identity: selectObjectIdentity, status: 'active' });+ });++ it('contains subscriber exceptions during start and request state transitions', async () => {+ const controller = createCanvasOperationController({ isGuardCurrent: () => true });+ const healthyListener = vi.fn();+ controller.subscribe(() => {+ throw new Error('listener failed');+ });+ controller.subscribe(healthyListener);++ const session = controller.start({ cleanupPreview: vi.fn(), guard, identity: filterIdentity });++ expect(session).not.toBeNull();+ await expect(session!.run(() => Promise.resolve('ready'), vi.fn())).resolves.toBe('published');+ expect(healthyListener).toHaveBeenCalledTimes(3);+ expect(controller.getSnapshot()).toMatchObject({ phase: 'ready', status: 'active' });+ });+it('rejects an invalid or mismatched export guard without replacing the active operation', () => {const isGuardCurrent = vi.fn((candidate: LayerExportGuard) => candidate === guard);const controller = createCanvasOperationController({ isGuardCurrent });diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/canvasOperationController.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/canvasOperationController.tsindex 1e920b8231..73012e18eb 100644--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/canvasOperationController.ts+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/canvasOperationController.ts@@ -16,9 +16,14 @@ export type CanvasOperationState =export type CanvasOperationRunResult = 'published' | 'stale' | 'error';export interface CanvasOperationSession {- run<T>(+ /**+ * Prepares a preview asynchronously, then commits it synchronously only while+ * this request and its export guard are still current.+ */+ run<T, CommitResult>(work: (signal: AbortSignal) => Promise<T>,- publish: (result: T) => void | Promise<void>+ commitPreview: (result: T) => CommitResult,+ ...asyncCommitNotAllowed: CommitResult extends PromiseLike<unknown> ? [never] : []): Promise<CanvasOperationRunResult>;reset(): void;cancel(): void;@@ -66,7 +71,11 @@ export const createCanvasOperationController = (deps: CanvasOperationControllerDreturn;}for (const listener of listeners) {- listener();+ try {+ listener();+ } catch {+ // One faulty subscriber must not strand the controller mid-transition.+ }}};@@ -83,11 +92,16 @@ export const createCanvasOperationController = (deps: CanvasOperationControllerDreturn;}operation.requestToken += 1;- operation.requestController?.abort();+ const requestController = operation.requestController;operation.requestController = null;- cleanupPreview(operation);active = null;- publishState({ status: 'idle' });+ const idleState: CanvasOperationState = { status: 'idle' };+ state = idleState;+ requestController?.abort();+ cleanupPreview(operation);+ if (active === null && state === idleState) {+ publishState(idleState);+ }};const reset = (operation: ActiveOperation): void => {@@ -95,10 +109,17 @@ export const createCanvasOperationController = (deps: CanvasOperationControllerDreturn;}operation.requestToken += 1;- operation.requestController?.abort();+ const requestController = operation.requestController;operation.requestController = null;+ active = null;+ const idleState: CanvasOperationState = { status: 'idle' };+ state = idleState;+ requestController?.abort();cleanupPreview(operation);- publishState({ error: null, identity: operation.identity, phase: 'ready', status: 'active' });+ if (!disposed && active === null && state === idleState) {+ active = operation;+ publishState({ error: null, identity: operation.identity, phase: 'ready', status: 'active' });+ }};const isGuardCurrent = (operation: ActiveOperation): boolean => {@@ -116,10 +137,10 @@ export const createCanvasOperationController = (deps: CanvasOperationControllerDoperation.requestController === controller &&!controller.signal.aborted;- const run = async <T>(+ const run = async <T, CommitResult>(operation: ActiveOperation,work: (signal: AbortSignal) => Promise<T>,- publish: (result: T) => void | Promise<void>+ commitPreview: (result: T) => CommitResult): Promise<CanvasOperationRunResult> => {if (disposed || active !== operation) {return 'stale';@@ -131,11 +152,24 @@ export const createCanvasOperationController = (deps: CanvasOperationControllerDoperation.requestToken += 1;const token = operation.requestToken;- operation.requestController?.abort();+ const previousController = operation.requestController;+ operation.requestController = null;+ active = null;+ const idleState: CanvasOperationState = { status: 'idle' };+ state = idleState;+ previousController?.abort();+ cleanupPreview(operation);+ if (disposed || active !== null || state !== idleState) {+ return 'stale';+ }+const controller = new AbortController();operation.requestController = controller;- cleanupPreview(operation);+ active = operation;publishState({ error: null, identity: operation.identity, phase: 'running', status: 'active' });+ if (!isCurrentRequest(operation, token, controller)) {+ return 'stale';+ }try {const result = await work(controller.signal);@@ -147,7 +181,7 @@ export const createCanvasOperationController = (deps: CanvasOperationControllerDreturn 'stale';}- await publish(result);+ commitPreview(result);if (!isCurrentRequest(operation, token, controller)) {return 'stale';}@@ -187,6 +221,9 @@ export const createCanvasOperationController = (deps: CanvasOperationControllerDif (active) {close(active);+ if (active) {+ return null;+ }}const operation: ActiveOperation = {...options,@@ -199,7 +236,11 @@ export const createCanvasOperationController = (deps: CanvasOperationControllerDreturn {cancel: () => close(operation),reset: () => reset(operation),- run: (work, publish) => run(operation, work, publish),+ run: <T, CommitResult>(+ work: (signal: AbortSignal) => Promise<T>,+ commitPreview: (result: T) => CommitResult,+ ..._asyncCommitNotAllowed: CommitResult extends PromiseLike<unknown> ? [never] : []+ ) => run(operation, work, commitPreview),};};diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.test.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.test.tsindex a4aaa3afb8..e467fd12b2 100644--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.test.ts+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.test.ts@@ -23,7 +23,7 @@ import { createInitialWorkbenchState, workbenchReducer } from '@workbench/workbeimport { afterEach, describe, expect, it, type Mock, vi } from 'vitest';import type { BitmapStore } from './document/bitmapStore';-import type { EngineStore } from './engine';+import type { CanvasEngine, EngineStore } from './engine';import type { StrokeCommittedEvent } from './tools/tool';import { createBitmapStore } from './document/bitmapStore';@@ -1939,7 +1939,7 @@ describe('ensureLayerCaches: edit-during-rasterize race', () => {await flushMicrotasks();raf.flush();expect(thumbnailListener).toHaveBeenCalledTimes(1);- expect(engine.stores.thumbnailVersion.get('a')).toBe(1);+ expect(engine.stores.thumbnailVersion.get('a')).toBe(2);// The older decode resolves afterwards. It may finish its isolated scratch// draw, but it must neither publish nor notify subscribers.@@ -5858,6 +5858,13 @@ describe('commitRasterFilterResult', () => {if (exported.status !== 'ok') {throw new Error('expected a filterable export');}+ const invalidateSource = vi.spyOn(engine.canvasOperations, 'invalidateSource');+ const cleanupPreview = vi.fn(() => invalidateSource.mockClear());+ engine.canvasOperations.start({+ cleanupPreview,+ guard: exported.guard,+ identity: { kind: 'filter', layerId: layer.id, projectId },+ });const result = await engine.commitRasterFilterResult({guard: exported.guard,@@ -5867,6 +5874,9 @@ describe('commitRasterFilterResult', () => {});expect(result).toEqual({ layerId: layer.id, status: 'committed' });+ expect(cleanupPreview).toHaveBeenCalledOnce();+ expect(invalidateSource).toHaveBeenCalledWith(projectId, layer.id);+ expect(engine.canvasOperations.getSnapshot()).toEqual({ status: 'idle' });const after = engine.getDocument()!.layers[0]!;const { adjustments: _adjustments, ...beforeWithoutAdjustments } = before as CanvasRasterLayerContractV2;expect(after).toEqual({@@ -11209,6 +11219,31 @@ describe('engine selection: fill / erase', () => {engine.dispose();});+ it.each([+ ['paint', (engine: CanvasEngine) => engine.fillSelection()],+ ['cache clear', (engine: CanvasEngine) => engine.clearCaches()],+ ] as const)('%s cancels a guarded operation and cleans its preview', async (_label, mutate) => {+ const { engine } = makeEngine(paintDoc());+ engine.selectAll();+ engine.fillSelection();+ const exported = await engine.exportLayerPixels('paint1');+ if (exported.status !== 'ok') {+ throw new Error('expected published paint pixels');+ }+ const cleanupPreview = vi.fn();+ engine.canvasOperations.start({+ cleanupPreview,+ guard: exported.guard,+ identity: { kind: 'select-object', layerId: 'paint1', projectId: 'p1' },+ });++ await mutate(engine);++ expect(cleanupPreview).toHaveBeenCalledOnce();+ expect(engine.canvasOperations.getSnapshot()).toEqual({ status: 'idle' });+ engine.dispose();+ });+it('eraseSelection records one undoable edit (on existing content)', () => {const { engine } = makeEngine(paintDoc());engine.selectAll();diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.tsindex 34922da2c1..d973c56eab 100644--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.ts+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.ts@@ -728,7 +728,10 @@ export const createCanvasEngine = (opts: CanvasEngineOptions): CanvasEngine => {const backend = opts.backend ?? createDomRasterBackend();const viewport = createViewport();- const layerCache: LayerCacheStore = createLayerCacheStore(backend);+ let canvasOperations: CanvasOperationController;+ const layerCache: LayerCacheStore = createLayerCacheStore(backend, {+ onVersionChange: (layerId) => canvasOperations?.invalidateSource(projectId, layerId),+ });const stores = createEngineStores();// Web-font readiness for text layers: re-rasterizes a text layer once its font// resolves (a no-op in node / when `document.fonts` is absent). `undefined`@@ -984,10 +987,8 @@ export const createCanvasEngine = (opts: CanvasEngineOptions): CanvasEngine => {/** Bumps a layer's cache version after a direct paint (pixels stay fresh) and recomposites. */const notifyLayerPainted = (layerId: string): void => {- const entry = layerCache.get(layerId);+ const entry = layerCache.publishPixels(layerId);if (entry) {- entry.hasPublishedPixels = true;- entry.version += 1;stores.thumbnailVersion.set(layerId, entry.version);stores.thumbnailStatus.set(layerId, 'ready');}@@ -1335,11 +1336,13 @@ export const createCanvasEngine = (opts: CanvasEngineOptions): CanvasEngine => {ctx.drawImage(result.surface.canvas, 0, 0);}currentEntry.rect = { ...result.rect };- currentEntry.hasPublishedPixels = true;- currentEntry.stale = false;+ const publishedEntry = layerCache.publishPixels(layer.id);+ if (!publishedEntry) {+ return 'stale';+ }trackPublishedLayerImage(currentLayer);published = true;- stores.thumbnailVersion.set(layer.id, currentEntry.version);+ stores.thumbnailVersion.set(layer.id, publishedEntry.version);stores.thumbnailStatus.set(layer.id, 'ready');scheduler.invalidate({ layers: [layer.id] });return 'published';@@ -1427,7 +1430,7 @@ export const createCanvasEngine = (opts: CanvasEngineOptions): CanvasEngine => {return !!entry && liveLayer === guard.layer && entry.version === guard.cacheVersion;};- const canvasOperations = createCanvasOperationController({ isGuardCurrent: isLayerExportGuardCurrent });+ canvasOperations = createCanvasOperationController({ isGuardCurrent: isLayerExportGuardCurrent });const ensureLayerCaches = (doc: CanvasDocumentContractV2): void => {for (const layer of doc.layers) {diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/render/layerCache.test.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/render/layerCache.test.tsindex da90388eb6..a37f421513 100644--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/render/layerCache.test.ts+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/render/layerCache.test.ts@@ -11,6 +11,37 @@ const makeBitmap = () => {};describe('createLayerCacheStore', () => {+ it('notifies version changes for pixel publication, invalidation, replacement, growth, and deletion', () => {+ const backend = createTestStubRasterBackend();+ const onVersionChange = vi.fn();+ const store = createLayerCacheStore(backend, { onVersionChange });++ store.getOrCreate('layer-1', 10, 10);+ expect(onVersionChange).not.toHaveBeenCalled();++ store.publishPixels('layer-1');+ store.growToRect('layer-1', { height: 20, width: 20, x: 0, y: 0 });+ store.invalidate('layer-1');+ store.installReplacement(+ store.prepareReplacement('layer-1', { height: 5, width: 5, x: 0, y: 0 }, backend.createSurface(5, 5))+ );+ store.delete('layer-1');++ expect(onVersionChange).toHaveBeenCalledTimes(5);+ expect(onVersionChange).toHaveBeenCalledWith('layer-1');+ });++ it('does not notify for ordinary fresh or stale allocation', () => {+ const onVersionChange = vi.fn();+ const store = createLayerCacheStore(createTestStubRasterBackend(), { onVersionChange });++ store.getOrCreate('origin', 10, 10);+ store.getOrCreateRect('rect', { height: 10, width: 10, x: 2, y: 3 });+ store.growToRect('grown', { height: 10, width: 10, x: 2, y: 3 });++ expect(onVersionChange).not.toHaveBeenCalled();+ });+it('returns a stable entry identity for the same layer + size', () => {const store = createLayerCacheStore(createTestStubRasterBackend());const a = store.getOrCreate('layer-1', 100, 50);diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/render/layerCache.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/render/layerCache.tsindex 54c2828d80..f3233bf7ae 100644--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/render/layerCache.ts+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/render/layerCache.ts@@ -60,6 +60,11 @@ export interface PreparedLayerCacheReplacement {readonly surface: RasterSurface;}+export interface LayerCacheStoreOptions {+ /** Called after a cache identity or pixels change; fresh allocations stay silent. */+ onVersionChange?(layerId: string): void;+}+/** The imperative store returned by {@link createLayerCacheStore}. */export interface LayerCacheStore {/** Returns the existing cache entry for a layer, or `undefined`. Touches LRU order. */@@ -92,6 +97,8 @@ export interface LayerCacheStore {prepareReplacement(layerId: string, rect: Rect, pixels: RasterSurface): PreparedLayerCacheReplacement;/** Publishes a detached replacement without allocating, resizing, or drawing. */installReplacement(prepared: PreparedLayerCacheReplacement): LayerCacheEntry;+ /** Marks directly-written pixels current, bumps the version, and notifies observers. */+ publishPixels(layerId: string): LayerCacheEntry | undefined;/** Marks a layer's cache stale and bumps its `version`. */invalidate(layerId: string): void;/** Drops a layer's cache entry entirely. */@@ -119,7 +126,10 @@ export interface LayerCacheStore {const surfaceBytes = (surface: RasterSurface): number => surface.width * surface.height * BYTES_PER_PIXEL;/** Creates a per-layer raster cache store backed by the given {@link RasterBackend}. */-export const createLayerCacheStore = (backend: RasterBackend): LayerCacheStore => {+export const createLayerCacheStore = (+ backend: RasterBackend,+ options: LayerCacheStoreOptions = {}+): LayerCacheStore => {const entries = new Map<string, LayerCacheEntry>();const bitmaps = new Map<string, ImageBitmap>();// Per-id version FLOOR: the highest version each layer id has ever reached,@@ -131,6 +141,14 @@ export const createLayerCacheStore = (backend: RasterBackend): LayerCacheStore =const versionFloors = new Map<string, number>();let tick = 0;+ const notifyVersionChange = (layerId: string): void => {+ try {+ options.onVersionChange?.(layerId);+ } catch {+ // Cache mutation is already complete; observers cannot roll it back.+ }+ };+const touch = (entry: LayerCacheEntry): void => {tick += 1;entry.lastUsed = tick;@@ -161,6 +179,12 @@ export const createLayerCacheStore = (backend: RasterBackend): LayerCacheStore =const getOrCreate = (layerId: string, width: number, height: number): LayerCacheEntry => {const existing = entries.get(layerId);if (existing) {+ const changed =+ existing.surface.width !== width ||+ existing.surface.height !== height ||+ existing.rect.x !== 0 ||+ existing.rect.y !== 0;+ const hadPublishedPixels = existing.hasPublishedPixels;if (existing.surface.width !== width || existing.surface.height !== height) {existing.surface.resize(width, height);existing.hasPublishedPixels = false;@@ -169,6 +193,10 @@ export const createLayerCacheStore = (backend: RasterBackend): LayerCacheStore =// Origin-anchored: this variant always places the surface at (0, 0).existing.rect = { height, width, x: 0, y: 0 };touch(existing);+ if (changed && hadPublishedPixels) {+ existing.version += 1;+ notifyVersionChange(layerId);+ }return existing;}const entry: LayerCacheEntry = {@@ -260,6 +288,10 @@ export const createLayerCacheStore = (backend: RasterBackend): LayerCacheStore =}existing.rect = newRect;touch(existing);+ if (existing.hasPublishedPixels) {+ existing.version += 1;+ notifyVersionChange(layerId);+ }return existing;};@@ -296,6 +328,19 @@ export const createLayerCacheStore = (backend: RasterBackend): LayerCacheStore =};touch(entry);entries.set(prepared.layerId, entry);+ notifyVersionChange(prepared.layerId);+ return entry;+ };++ const publishPixels = (layerId: string): LayerCacheEntry | undefined => {+ const entry = entries.get(layerId);+ if (!entry) {+ return undefined;+ }+ entry.hasPublishedPixels = true;+ entry.stale = false;+ entry.version += 1;+ notifyVersionChange(layerId);return entry;};@@ -304,6 +349,7 @@ export const createLayerCacheStore = (backend: RasterBackend): LayerCacheStore =if (entry) {entry.version += 1;entry.stale = true;+ notifyVersionChange(layerId);}};@@ -312,6 +358,7 @@ export const createLayerCacheStore = (backend: RasterBackend): LayerCacheStore =if (entry) {rememberFloor(entry);entries.delete(layerId);+ notifyVersionChange(layerId);}};@@ -347,6 +394,7 @@ export const createLayerCacheStore = (backend: RasterBackend): LayerCacheStore =entries.delete(entry.layerId);evicted.push(entry.layerId);total -= surfaceBytes(entry.surface);+ notifyVersionChange(entry.layerId);}return evicted;};@@ -391,6 +439,7 @@ export const createLayerCacheStore = (backend: RasterBackend): LayerCacheStore =installReplacement,invalidate,prepareReplacement,+ publishPixels,setBitmap,version,};diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/tools/strokeSession.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/tools/strokeSession.tsindex 1a4b22f0d8..0fd407885c 100644--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/tools/strokeSession.ts+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/tools/strokeSession.ts@@ -228,7 +228,7 @@ export const createStrokeSession = (config: StrokeSessionConfig): StrokeSession// raster layer until pointer-up (and jump on rect growth). This does NOT// touch `thumbnailVersion` (only `notifyLayerPainted`/rasterize do), so// thumbnails don't churn mid-stroke.- entry.version += 1;+ layers.publishPixels(layerId);ctx.invalidate({ layers: [layerId] });};@@ -246,7 +246,7 @@ export const createStrokeSession = (config: StrokeSessionConfig): StrokeSession// Bump the version so the adjusted-surface memo (which recomputed over the// live stroke) re-derives from the RESTORED pixels — otherwise an adjusted// raster layer would keep showing the cancelled stroke's adjusted preview.- entry.version += 1;+ layers.publishPixels(layerId);ctx.invalidate({ layers: [layerId] });}},