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): isolate sam session subscribers
joshistoast0a9758520e8e
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/selectObjectSession.test.ts b/invokeai/frontend/webv2/src/workbench/widgets/layers/selectObjectSession.test.tsindex 1899b82bf1..4f96e656e3 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/selectObjectSession.test.ts+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/selectObjectSession.test.ts@@ -103,6 +103,52 @@ describe('createSelectObjectSession', () => {});});+ it('contains subscriber exceptions so healthy subscribers and processing continue', async () => {+ const harness = createHarness();+ const throwing = vi.fn(() => {+ throw new Error('subscriber failed');+ });+ const healthy = vi.fn();+ harness.session.subscribe(throwing);+ harness.session.subscribe(healthy);++ expect(() => harness.session.update({ model: 'segment-anything-huge' })).not.toThrow();+ await expect(harness.session.process()).resolves.toBe('published');++ expect(throwing).toHaveBeenCalled();+ expect(healthy).toHaveBeenCalled();+ expect(harness.session.getSnapshot()).toMatchObject({ error: null, status: 'ready' });+ });++ it('never publishes error status without an error and returns to ready when update clears it', async () => {+ const harness = createHarness();+ const snapshots: Array<{ error: string | null; status: string }> = [];+ harness.session.subscribe(() => {+ const { error, status } = harness.session.getSnapshot();+ snapshots.push({ error, status });+ });+ harness.session.update({ input: { prompt: ' ', type: 'prompt' } });++ await expect(harness.session.process()).resolves.toBe('invalid');+ expect(harness.session.getSnapshot()).toMatchObject({+ error: 'A Segment Anything input is required.',+ status: 'error',+ });++ harness.session.update({ autoProcess: false });++ expect(harness.session.getSnapshot()).toMatchObject({ error: null, status: 'ready' });+ expect(snapshots.every(({ error, status }) => status !== 'error' || error !== null)).toBe(true);+ });++ it('keeps a non-null error whenever processing fails', async () => {+ const harness = createHarness({ runGraph: vi.fn(() => Promise.reject(new Error('graph failed'))) });++ await expect(harness.session.process()).resolves.toBe('error');++ expect(harness.session.getSnapshot()).toEqual(expect.objectContaining({ error: 'graph failed', status: 'error' }));+ });+it('reuses an uploaded export only while its exact guard remains current', async () => {const harness = createHarness();diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/selectObjectSession.ts b/invokeai/frontend/webv2/src/workbench/widgets/layers/selectObjectSession.tsindex 846dabc6fa..df49b40009 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/selectObjectSession.ts+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/selectObjectSession.ts@@ -124,9 +124,13 @@ export const createSelectObjectSession = <T>(options: CreateSelectObjectSessionOconst listeners = new Set<() => void>();const publishState = (next: SelectObjectSessionState<T>): void => {- state = next;+ state = next.status === 'error' && next.error === null ? { ...next, status: 'ready' } : next;for (const listener of listeners) {- listener();+ try {+ listener();+ } catch {+ // One faulty subscriber must not interrupt session state transitions.+ }}};