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): prune stale saved workflow node state
JPPhoto3e8df3831027
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.browser.test.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.browser.test.tsxindex a09b52fef0..43044667bc 100644--- a/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.browser.test.tsx@@ -220,11 +220,7 @@ describe('CallSavedWorkflowSyncRuntime with an unreachable child workflow', () =});it('refetches an invalidated workflow once for multiple call nodes', async () => {- const { readGraph } = await mountWith([- buildCallNode('call-1'),- buildCallNode('call-2'),- buildCallNode('call-3'),- ]);+ const { readGraph } = await mountWith([buildCallNode('call-1'), buildCallNode('call-2'), buildCallNode('call-3')]);await expectSettled(readGraph, ['error', 'error', 'error'], 1);@@ -237,10 +233,7 @@ describe('CallSavedWorkflowSyncRuntime with an unreachable child workflow', () =it('keeps an invalidation retry available when the first matching node changes', async () => {const attempts = mockWorkflowThatRecoversAfterOneFailure(MISSING_WORKFLOW_ID);- const { readGraph, updateGraph } = await mountWith([- buildCallNode('call-1'),- buildCallNode('call-2'),- ]);+ const { readGraph, updateGraph } = await mountWith([buildCallNode('call-1'), buildCallNode('call-2')]);await settle(60);invalidateWorkflowLibraryCache(MISSING_WORKFLOW_ID);@@ -294,6 +287,39 @@ describe('CallSavedWorkflowSyncRuntime with an unreachable child workflow', () =expect(getLibraryWorkflowRecordMock).toHaveBeenCalledTimes(3);});+ it('does not retain removed-node state when its id is reused', async () => {+ const { readGraph, updateGraph } = await mountWith([buildCallNode('call-1', 'workflow-a')]);+ await settle(60);+ expect(readStatuses(readGraph())).toEqual(['error']);++ updateGraph(+ projectGraphReducer(readGraph(), {+ fieldName: 'workflow_id',+ nodeId: 'call-1',+ type: 'setFieldValue',+ value: 'workflow-b',+ })+ );+ await settle(60);+ expect(readStatuses(readGraph())).toEqual(['error']);+ expect(getLibraryWorkflowRecordMock.mock.calls.map(([workflowId]) => workflowId)).toEqual([+ 'workflow-a',+ 'workflow-b',+ ]);++ updateGraph({ ...readGraph(), nodes: [] });+ await settle(20);++ updateGraph({ ...createProjectGraph('parent'), nodes: [buildCallNode('call-1', 'workflow-a')] });+ await settle(60);++ expect(readStatuses(readGraph())).toEqual(['error']);+ expect(getLibraryWorkflowRecordMock.mock.calls.map(([workflowId]) => workflowId)).toEqual([+ 'workflow-a',+ 'workflow-b',+ ]);+ });+/*** `savedWorkflowDetailQueryOptions` sets `gcTime: Infinity` and `retry: false`,* so an errored cache entry never expires and is never revalidated on its own.diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.test.ts b/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.test.tsindex 60b9df4444..fe04cb6068 100644--- a/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.test.ts+++ b/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.test.ts@@ -5,8 +5,22 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import {createDeferredCallSavedWorkflowReconciler,createSavedWorkflowDocumentParser,+ pruneStaleCallSavedWorkflowNodeState,} from './CallSavedWorkflowSyncRuntime';+describe('pruneStaleCallSavedWorkflowNodeState', () => {+ it('removes state for nodes no longer in the project graph', () => {+ const state = new Map([+ ['present', 'keep'],+ ['removed', 'drop'],+ ]);++ pruneStaleCallSavedWorkflowNodeState(state, new Set(['present']));++ expect(state).toEqual(new Map([['present', 'keep']]));+ });+});+describe('createDeferredCallSavedWorkflowReconciler', () => {beforeEach(() => {vi.useFakeTimers();diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.tsxindex 9c8ed058a8..507c9765e0 100644--- a/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.tsx+++ b/invokeai/frontend/webv2/src/features/workflow/ui/editor/CallSavedWorkflowSyncRuntime.tsx@@ -72,6 +72,17 @@ export const createDeferredCallSavedWorkflowReconciler = (reconcile: () => void)};};+export const pruneStaleCallSavedWorkflowNodeState = <T,>(+ state: Map<string, T>,+ currentNodeIds: ReadonlySet<string>+): void => {+ for (const nodeId of state.keys()) {+ if (!currentNodeIds.has(nodeId)) {+ state.delete(nodeId);+ }+ }+};+const hasSameFieldType = (left: unknown, right: unknown): boolean => {if (!left || !right || typeof left !== 'object' || typeof right !== 'object') {return false;@@ -152,17 +163,9 @@ export const CallSavedWorkflowSyncRuntime = () => {const document = projectPort.getSnapshot().projectGraph;const currentNodeIds = new Set(document.nodes.map((node) => node.id));- for (const nodeId of retryableDetailWorkflowIds.current.keys()) {- if (!currentNodeIds.has(nodeId)) {- retryableDetailWorkflowIds.current.delete(nodeId);- }- }-- for (const nodeId of previousDetailStatuses.current.keys()) {- if (!currentNodeIds.has(nodeId)) {- previousDetailStatuses.current.delete(nodeId);- }- }+ pruneStaleCallSavedWorkflowNodeState(retryableDetailWorkflowIds.current, currentNodeIds);+ pruneStaleCallSavedWorkflowNodeState(previousDetailStatuses.current, currentNodeIds);+ pruneStaleCallSavedWorkflowNodeState(previousDetailWorkflowIds.current, currentNodeIds);const setStatus = (nodeId: string, workflowId: string, status: 'loading' | 'ready' | 'error') => {const currentDocument = projectPort.getSnapshot().projectGraph;