Skip to content

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.

feat(workbench): route errors through diagnostics

joshistoastd9c6a72738fc
diff --git a/invokeai/frontend/webv2/src/workbench/persistence.test.ts b/invokeai/frontend/webv2/src/workbench/persistence.test.ts
index f9439fb7a7..f8f1949cc5 100644
--- a/invokeai/frontend/webv2/src/workbench/persistence.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/persistence.test.ts
@@ -41,6 +41,13 @@ describe('workbench persistence migration', () => {
expect(snapshot?.state.projects).toHaveLength(1);
});
+ it('drops legacy error logs from persisted snapshots', () => {
+ const state = { ...createInitialWorkbenchState(), errorLog: ['old error'] };
+ const snapshot = migrateWorkbenchPersistenceSnapshot({ savedAt: '2026-06-09T00:00:00.000Z', state, version: 1 });
+
+ expect(snapshot?.state).not.toHaveProperty('errorLog');
+ });
+
it('rejects unsupported persistence snapshots', () => {
expect(migrateWorkbenchPersistenceSnapshot({ state: createInitialWorkbenchState(), version: 999 })).toBeNull();
expect(migrateWorkbenchPersistenceSnapshot({ state: { projects: [] }, version: 1 })).toBeNull();
diff --git a/invokeai/frontend/webv2/src/workbench/persistence.ts b/invokeai/frontend/webv2/src/workbench/persistence.ts
index 6d498cb49b..ebbb5c6cc8 100644
--- a/invokeai/frontend/webv2/src/workbench/persistence.ts
+++ b/invokeai/frontend/webv2/src/workbench/persistence.ts
@@ -21,10 +21,14 @@ export interface WorkbenchPersistenceService {
const isBrowser = (): boolean => typeof window !== 'undefined' && typeof window.localStorage !== 'undefined';
-export const stripTransientWorkbenchState = (state: WorkbenchState): WorkbenchState => ({
- ...state,
- notifications: [],
-});
+export const stripTransientWorkbenchState = (state: WorkbenchState): WorkbenchState => {
+ const { errorLog: _legacyErrorLog, ...nextState } = state as WorkbenchState & { errorLog?: string[] };
+
+ return {
+ ...nextState,
+ notifications: [],
+ };
+};
const createSnapshot = (state: WorkbenchState): WorkbenchPersistenceSnapshot => ({
savedAt: new Date().toISOString(),
@@ -100,7 +104,11 @@ export const localStorageWorkbenchPersistence: WorkbenchPersistenceService = {
try {
window.localStorage.setItem(
getStorageKey(),
- timeWorkbenchPerf('workbench:persistence-localstorage-stringify', () => JSON.stringify(snapshot))
+ timeWorkbenchPerf(
+ 'workbench:persistence-localstorage-stringify',
+ { area: 'persistence', kind: 'workbench', projectId: state.activeProjectId },
+ () => JSON.stringify(snapshot)
+ )
);
} catch {
// The backend remains the source of truth; localStorage is only an offline cache.
diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
index f7524c8619..91515cc407 100644
--- a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
@@ -847,9 +847,7 @@ describe('workbenchReducer Phase 5 generation flow', () => {
expect(state.notifications).toEqual([]);
- state = workbenchReducer(state, { type: 'clearErrorLog' });
-
- expect(state.errorLog).toEqual([]);
+ expect(state.notifications).toEqual([]);
});
it('accepts the project graph source but does not queue an empty project graph', () => {
diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.ts
index bf97dc30da..a7fe5b31c7 100644
--- a/invokeai/frontend/webv2/src/workbench/workbenchState.ts
+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.ts
@@ -8,6 +8,7 @@ import type {
CenterViewId,
CanvasRasterLayerContract,
CanvasStagingCandidateContract,
+ DeveloperLogNamespace,
GeneratedImageContract,
GraphContract,
GraphHistorySnapshot,
@@ -206,16 +207,21 @@ type WorkbenchAction =
| { type: 'autosaveFailed'; error: string }
| { type: 'markAllNotificationsRead' }
| { type: 'clearNotifications' }
- | { type: 'clearErrorLog' }
| { type: 'recordWidgetFailure'; failure: WidgetFailure }
| { type: 'setActiveProjectSettings'; settings: Partial<ProjectSettings> }
- | { type: 'recordError'; message: string }
+ | {
+ type: 'recordError';
+ message: string;
+ area?: string;
+ context?: Record<string, unknown>;
+ namespace?: DeveloperLogNamespace;
+ projectId?: string;
+ }
| { type: 'setBackendConnectionStatus'; status: WorkbenchState['backendConnection']['status']; error?: string }
| { type: 'refreshBackendData' }
| { type: 'recordNotice'; kind: WorkbenchNotificationKind; title: string; message?: string };
const HISTORY_LIMIT = 40;
-const ERROR_LOG_LIMIT = 5;
const NOTIFICATION_LIMIT = 100;
const MIN_PANEL_SIZE_PX = 180;
const MAX_PANEL_SIZE_PX = 520;
@@ -268,6 +274,17 @@ const areRecordsShallowEqual = (left: Record<string, unknown>, right: Record<str
);
};
+const areProjectSettingValuesEqual = (
+ left: ProjectSettings[keyof ProjectSettings],
+ right: ProjectSettings[keyof ProjectSettings]
+): boolean => {
+ if (Array.isArray(left) && Array.isArray(right)) {
+ return left.length === right.length && left.every((value, index) => value === right[index]);
+ }
+
+ return Object.is(left, right);
+};
+
const patchRecord = <RecordValue extends Record<string, unknown>>(
current: RecordValue,
patch: Partial<RecordValue>
@@ -1416,7 +1433,6 @@ export const createInitialWorkbenchState = (): WorkbenchState => {
activeProjectId: draft.id,
autosave: { status: 'idle' },
backendConnection: { status: 'connecting' },
- errorLog: [],
notifications: [],
projects: [draft],
widgetFailures: [],
@@ -1457,13 +1473,7 @@ export const workbenchReducer = (state: WorkbenchState, action: WorkbenchAction)
if (state.projects.length === 1) {
const message = 'At least one project must remain open.';
- return addNotification(
- {
- ...state,
- errorLog: [message, ...state.errorLog],
- },
- createNotification({ kind: 'error', message, title: 'Project close blocked' })
- );
+ return addNotification(state, createNotification({ kind: 'error', message, title: 'Project close blocked' }));
}
const projectIndex = state.projects.findIndex((project) => project.id === action.projectId);
@@ -2604,9 +2614,6 @@ export const workbenchReducer = (state: WorkbenchState, action: WorkbenchAction)
case 'clearNotifications': {
return { ...state, notifications: [] };
}
- case 'clearErrorLog': {
- return { ...state, errorLog: [] };
- }
case 'recordWidgetFailure': {
const hasFailure = state.widgetFailures.some((failure) => failure.widgetId === action.failure.widgetId);
@@ -2617,7 +2624,6 @@ export const workbenchReducer = (state: WorkbenchState, action: WorkbenchAction)
return addNotification(
{
...state,
- errorLog: [action.failure.details, ...state.errorLog].slice(0, ERROR_LOG_LIMIT),
widgetFailures: [action.failure, ...state.widgetFailures],
},
createNotification({
@@ -2628,10 +2634,7 @@ export const workbenchReducer = (state: WorkbenchState, action: WorkbenchAction)
);
}
case 'recordError': {
- return addNotification(
- { ...state, errorLog: [action.message, ...state.errorLog].slice(0, ERROR_LOG_LIMIT) },
- createNotification({ kind: 'error', message: action.message, title: 'Error' })
- );
+ return addNotification(state, createNotification({ kind: 'error', message: action.message, title: 'Error' }));
}
case 'setBackendConnectionStatus': {
const timestamp = now();
@@ -2663,9 +2666,14 @@ export const workbenchReducer = (state: WorkbenchState, action: WorkbenchAction)
return updateActiveProject(state, (project) => {
const settings = normalizeProjectSettings({ ...project.settings, ...action.settings });
- return Object.entries(settings).every(([key, value]) =>
- Object.is(project.settings[key as keyof ProjectSettings], value)
- )
+ return Object.entries(settings).every(([key, value]) => {
+ const settingKey = key as keyof ProjectSettings;
+
+ return areProjectSettingValuesEqual(
+ project.settings[settingKey],
+ value as ProjectSettings[typeof settingKey]
+ );
+ })
? project
: { ...project, settings };
});
diff --git a/invokeai/frontend/webv2/src/workbench/workbenchStore.test.ts b/invokeai/frontend/webv2/src/workbench/workbenchStore.test.ts
index c208d8932d..2318864b85 100644
--- a/invokeai/frontend/webv2/src/workbench/workbenchStore.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/workbenchStore.test.ts
@@ -1,7 +1,8 @@
-import { describe, expect, it, vi } from 'vitest';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
import type { WorkbenchSnapshot, WorkbenchStore } from './workbenchStore';
+import { clearProjectDiagnostics, configureDiagnostics, getProjectDiagnostics } from './diagnostics/logger';
import { areWidgetPlacementProjectsEqual, getWidgetPlacementProject } from './widgetPlacementMeta';
import { getProjectWidgetValues } from './widgetState';
import { createWorkbenchStore } from './workbenchStore';
@@ -35,6 +36,15 @@ const watchSelector = <Selected>(
};
describe('createWorkbenchStore', () => {
+ beforeEach(() => {
+ configureDiagnostics({
+ enabled: true,
+ level: 'trace',
+ namespaces: ['system', 'queue'],
+ performanceTimingsEnabled: false,
+ });
+ });
+
it('exposes a stable dispatch and initializes snapshot metadata', () => {
const store = createWorkbenchStore();
const snapshot = store.getSnapshot();
@@ -105,6 +115,49 @@ describe('createWorkbenchStore', () => {
expect(store.getPersistedRevision()).toBe(initialPersistedRevision + 1);
});
+ it('records recordError actions into project diagnostics', () => {
+ const store = createWorkbenchStore();
+ const projectId = store.getSnapshot().activeProject.id;
+
+ clearProjectDiagnostics(projectId);
+ store.dispatch({ area: 'queue-runtime', message: 'Queue failed', namespace: 'queue', type: 'recordError' });
+
+ expect(getProjectDiagnostics(projectId)).toMatchObject([
+ {
+ level: 'error',
+ message: 'Queue failed',
+ namespace: 'queue',
+ source: { area: 'queue-runtime', kind: 'workbench', projectId },
+ },
+ ]);
+ expect(store.getSnapshot().state.notifications[0]?.title).toBe('Error');
+ });
+
+ it('records accepted widget failures into diagnostics once', () => {
+ const store = createWorkbenchStore();
+ const projectId = store.getSnapshot().activeProject.id;
+ const failure = {
+ details: 'Widget stack',
+ message: 'Widget failed',
+ occurredAt: '2026-06-29T00:00:00.000Z',
+ widgetId: 'workflow' as const,
+ };
+
+ clearProjectDiagnostics(projectId);
+ store.dispatch({ failure, type: 'recordWidgetFailure' });
+ store.dispatch({ failure, type: 'recordWidgetFailure' });
+
+ expect(getProjectDiagnostics(projectId)).toMatchObject([
+ {
+ context: { widgetId: 'workflow' },
+ level: 'error',
+ message: 'Widget stack',
+ namespace: 'system',
+ source: { area: 'widget-failure', kind: 'workbench', projectId },
+ },
+ ]);
+ });
+
it('stops notifying unsubscribed listeners', () => {
const store = createWorkbenchStore();
const listener = vi.fn();
diff --git a/invokeai/frontend/webv2/src/workbench/workbenchStore.ts b/invokeai/frontend/webv2/src/workbench/workbenchStore.ts
index 0ea52e0c74..5e28e07d19 100644
--- a/invokeai/frontend/webv2/src/workbench/workbenchStore.ts
+++ b/invokeai/frontend/webv2/src/workbench/workbenchStore.ts
@@ -2,6 +2,7 @@ import type { Dispatch } from 'react';
import type { Project, WorkbenchState } from './types';
+import { recordDiagnosticEntry } from './diagnostics/logger';
import { createExternalStore } from './externalStore';
import { createInitialWorkbenchState, workbenchReducer, type WorkbenchAction } from './workbenchState';
@@ -32,10 +33,76 @@ const createSnapshot = (state: WorkbenchState, hasHydrated: boolean): WorkbenchS
const hasPersistedStateChanged = (previous: WorkbenchState, next: WorkbenchState): boolean =>
!Object.is(previous.account, next.account) ||
previous.activeProjectId !== next.activeProjectId ||
- !Object.is(previous.errorLog, next.errorLog) ||
!Object.is(previous.projects, next.projects) ||
!Object.is(previous.widgetFailures, next.widgetFailures);
+const getDiagnosticProjectId = (state: WorkbenchState, projectId?: string): string | undefined =>
+ projectId ?? getActiveProject(state)?.id;
+
+const recordDiagnosticForAction = (
+ action: WorkbenchAction,
+ previousState: WorkbenchState,
+ nextState: WorkbenchState
+): void => {
+ switch (action.type) {
+ case 'recordError': {
+ const projectId = getDiagnosticProjectId(nextState, action.projectId);
+
+ if (!projectId) {
+ return;
+ }
+
+ recordDiagnosticEntry({
+ context: action.context,
+ level: 'error',
+ message: action.message,
+ namespace: action.namespace ?? 'system',
+ source: { area: action.area ?? 'runtime', kind: 'workbench', projectId },
+ });
+ break;
+ }
+ case 'recordWidgetFailure': {
+ if (Object.is(previousState, nextState)) {
+ return;
+ }
+
+ const projectId = getDiagnosticProjectId(nextState);
+
+ if (!projectId) {
+ return;
+ }
+
+ recordDiagnosticEntry({
+ context: { widgetId: action.failure.widgetId },
+ level: 'error',
+ message: action.failure.details,
+ namespace: 'system',
+ source: { area: 'widget-failure', kind: 'workbench', projectId },
+ });
+ break;
+ }
+ case 'closeProject': {
+ if (previousState.projects.length !== 1) {
+ return;
+ }
+
+ const projectId = getDiagnosticProjectId(nextState, action.projectId);
+
+ if (!projectId) {
+ return;
+ }
+
+ recordDiagnosticEntry({
+ level: 'error',
+ message: 'At least one project must remain open.',
+ namespace: 'system',
+ source: { area: 'project-lifecycle', kind: 'workbench', projectId },
+ });
+ break;
+ }
+ }
+};
+
export const createWorkbenchStore = (initialState = createInitialWorkbenchState()): WorkbenchStore => {
let state = initialState;
let hasHydrated = false;
@@ -58,7 +125,11 @@ export const createWorkbenchStore = (initialState = createInitialWorkbenchState(
return {
dispatch(action) {
- setSnapshotState(workbenchReducer(state, action));
+ const previousState = state;
+ const nextState = workbenchReducer(state, action);
+
+ setSnapshotState(nextState);
+ recordDiagnosticForAction(action, previousState, nextState);
},
getPersistedRevision: () => persistedRevision,
getSnapshot: snapshotStore.getSnapshot,