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
refactor(canvas): let the engine own filter commit teardown
joshistoast1096b9c56a56
diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.test.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.test.tsindex a4eaacfb2b..fcbdab9c2a 100644--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.test.ts+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.test.ts@@ -10013,6 +10013,33 @@ describe('guarded filter previews', () => {engine.dispose();});+ it('clears the session and ends the operation after a committed filter commit', async () => {+ const source = guardableLayer('commit-clear');+ const document = { ...emptyDoc(), layers: [source], selectedLayerId: source.id };+ const { projectId, store } = createReducerBackedStore(document);+ const engine = createCanvasEngine({+ backend: filterBitmapBackend(),+ bitmapStore: createSpyBitmapStore(),+ filterDeps: {+ runGraph: () => Promise.resolve({ height: 10, imageName: 'out.png', origin: 'test', output: {}, width: 10 }),+ uploadIntermediate: () => Promise.resolve({ imageName: 'input.png' }),+ },+ imageResolver: () => Promise.resolve(new Blob()),+ projectId,+ store,+ });+ expect((await engine.exportLayerPixels(source.id)).status).toBe('ok');+ expect(engine.startFilterOperation(source.id)).toBe('started');+ await expect(engine.processFilterOperation()).resolves.toBe('completed');++ await expect(engine.commitFilterOperation('apply', () => Promise.resolve())).resolves.toBe('committed');++ expect(engine.stores.filterSession.get()).toBeNull();+ expect(engine.canvasOperations.getSnapshot()).toEqual({ status: 'idle' });+ expect(engine.startFilterOperation(source.id)).toBe('started');+ engine.dispose();+ });+it.each(['apply', 'raster'] as const)('rejects a decoded dimension mismatch for canny %s without scaling, then retries successfully',async (target) => {diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.tsindex 06748b0ba5..071e61e590 100644--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.ts+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/engine.ts@@ -3681,7 +3681,7 @@ export const createCanvasEngine = (opts: CanvasEngineOptions): CanvasEngine => {}filterMakeDurable = makeImageDurable;const result = await session.commit(target);- if (canvasOperations.getSnapshot().status === 'idle' && filterSession === session) {+ if (result === 'committed' && filterSession === session) {clearOwnedFilterSession();}return result;diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/filterOperationSession.test.ts b/invokeai/frontend/webv2/src/workbench/widgets/layers/filterOperationSession.test.tsindex 3c651d30e6..854000c637 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/filterOperationSession.test.ts+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/filterOperationSession.test.ts@@ -167,7 +167,7 @@ describe('createFilterOperationSession', () => {});it.each(['apply', 'raster', 'control'] as const)(- 'promotes, commits to %s, and exits after success',+ 'promotes, commits to %s, and leaves the operation for its owner to end',async (target) => {const calls: string[] = [];const deps = createDeps({@@ -193,6 +193,9 @@ describe('createFilterOperationSession', () => {target,}));+ expect(session.getSnapshot()).toMatchObject({ error: null, preview: null, status: 'ready' });+ expect(deps.controller.getSnapshot()).toMatchObject({ identity: { kind: 'filter' }, status: 'active' });+ session.dispose();expect(deps.controller.getSnapshot()).toEqual({ status: 'idle' });});diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/filterOperationSession.ts b/invokeai/frontend/webv2/src/workbench/widgets/layers/filterOperationSession.tsindex 23a6d8f7a5..ed4f898219 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/filterOperationSession.ts+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/filterOperationSession.ts@@ -83,6 +83,7 @@ export interface FilterOperationSession {process(): Promise<CanvasOperationRunResult>;interruptProcessing(): void;reset(settings: Record<string, unknown>): void;+ /** On 'committed' the canvas operation stays active; the owner must dispose the session to end it. */commit(target: FilterCommitTarget): Promise<'committed' | 'blocked' | 'stale'>;blockCommit(): void;cancel(): void;@@ -281,7 +282,8 @@ export const createFilterOperationSession = (target,});if (result.status === 'committed') {- operation.cancel();+ // The operation stays active: the owner ends it by disposing the+ // session, keeping teardown out of this call stack.publish({ ...state, error: null, preview: null, status: 'ready' });return 'committed';}