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(queue): translate run failure notices the queue runtime words itself (#10122)
kevin8208b663cd5f
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.jsonindex ae73347687..c8b078f630 100644--- a/invokeai/frontend/webv2/public/locales/en.json+++ b/invokeai/frontend/webv2/public/locales/en.json@@ -391,8 +391,16 @@"failedItems_one": "{{count}} of {{total}} items failed in {{project}}","failedItems_other": "{{count}} of {{total}} items failed in {{project}}","failedMessage": "“{{label}}”: {{reason}}",+ "invalidSubmissionMessage": "“{{label}}” could not be submitted because its queued request is invalid: {{reason}}",+ "invalidSubmissionMessageUnlabeled": "The run could not be submitted because its queued request is invalid: {{reason}}",+ "notAcceptedMessage": "The server queue did not accept “{{label}}”. The queue may be full.",+ "notAcceptedMessageUnlabeled": "The server queue did not accept the run. The queue may be full.",+ "projectNotSavedMessage": "“{{label}}” was not submitted because its project cannot be saved.",+ "projectNotSavedMessageUnlabeled": "The run was not submitted because its project cannot be saved.","removedMessage": "“{{label}}” is no longer on the server queue; it may have been cleared.","removedMessageUnlabeled": "The run is no longer on the server queue; it may have been cleared.",+ "serverErrorMessage": "The server kept failing to queue “{{label}}”: {{reason}}",+ "serverErrorMessageUnlabeled": "The server kept failing to queue the run: {{reason}}","unexplainedMessage": "“{{label}}” failed without a reason from the server.","unexplainedMessageUnlabeled": "The server gave no reason."},diff --git a/invokeai/frontend/webv2/src/features/queue/contracts.ts b/invokeai/frontend/webv2/src/features/queue/contracts.tsindex fecfaa8b9b..2522427940 100644--- a/invokeai/frontend/webv2/src/features/queue/contracts.ts+++ b/invokeai/frontend/webv2/src/features/queue/contracts.ts@@ -5,6 +5,7 @@export type {QueueHistoryItemStatus,QueueItem,+ QueueRunErrorCode,QueueState,QueueSubmissionSnapshot,RunRecord,diff --git a/invokeai/frontend/webv2/src/features/queue/core/historyTypes.ts b/invokeai/frontend/webv2/src/features/queue/core/historyTypes.tsindex eb85fe3715..66bcbd5046 100644--- a/invokeai/frontend/webv2/src/features/queue/core/historyTypes.ts+++ b/invokeai/frontend/webv2/src/features/queue/core/historyTypes.ts@@ -9,6 +9,24 @@ import type {export type QueueHistoryItemStatus = 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';+/**+ * Why a run failed, for failures the queue runtime words itself, so the notice can show translated text. The English+ * `error` stays alongside as diagnostic detail; server and validation text is shown as the notice's reason.+ * - `invalid-submission`: the queued request is missing or malformed, so it was never sent.+ * - `not-accepted`: the server queue took none of the run's items.+ * - `project-not-saved`: the run's project cannot be saved, so it was not sent.+ * - `removed`: the run's backend items vanished from the server queue.+ * - `server-error`: enqueue kept failing with a server error until the runtime gave up.+ * - `unexplained`: the backend failed the run without a reason.+ */+export type QueueRunErrorCode =+ | 'invalid-submission'+ | 'not-accepted'+ | 'project-not-saved'+ | 'removed'+ | 'server-error'+ | 'unexplained';+export interface QueueSubmissionSnapshot {backendSubmission: QueueCompiledSubmission;sourceId: QueueSourceId;diff --git a/invokeai/frontend/webv2/src/features/queue/runtime.test.ts b/invokeai/frontend/webv2/src/features/queue/runtime.test.tsindex 39dde5bcbf..214da84eb1 100644--- a/invokeai/frontend/webv2/src/features/queue/runtime.test.ts+++ b/invokeai/frontend/webv2/src/features/queue/runtime.test.ts@@ -583,7 +583,12 @@ describe('queue runtime', () => {expect(enqueueGenerate).not.toHaveBeenCalled();if (shouldFail) {expect(commands.setStatus).toHaveBeenCalledWith(- expect.objectContaining({ projectId: project.id, queueItemId: queueItem.id, status: 'failed' })+ expect.objectContaining({+ errorCode: 'project-not-saved',+ projectId: project.id,+ queueItemId: queueItem.id,+ status: 'failed',+ }));} else {expect(commands.setStatus).not.toHaveBeenCalled();@@ -592,6 +597,70 @@ describe('queue runtime', () => {vi.useRealTimers();});+ it('fails a run whose queued request is invalid with a code its notice can translate, without enqueueing', async () => {+ vi.useFakeTimers();+ const queueItem = createPendingQueueItem();+ delete (queueItem.snapshot as Partial<QueueItem['snapshot']>).backendSubmission;+ const project = { id: 'project-1', queue: { items: [queueItem] } };+ const enqueueGenerate = vi.fn();+ const commands = createTestCommands();+ const runtime = createQueueRuntime({+ ...runtimeServices,+ backend: createTestBackend({ enqueueGenerate }),+ history: {+ commands,+ getSnapshot: () => ({ connectionStatus: 'connected', isHydrated: true, projects: [project] }),+ subscribe: vi.fn(() => vi.fn()),+ },+ journal: createTestJournal(),+ });++ runtime.start();+ await vi.advanceTimersByTimeAsync(1);++ expect(enqueueGenerate).not.toHaveBeenCalled();+ expect(commands.setStatus).toHaveBeenCalledWith({+ error: 'Queue item is missing a compiled backend submission.',+ errorCode: 'invalid-submission',+ projectId: project.id,+ queueItemId: queueItem.id,+ status: 'failed',+ });+ await runtime.dispose();+ vi.useRealTimers();+ });++ it('fails a run the server queue accepted none of with a code its notice can translate', async () => {+ const queueItem = createPendingQueueItem();+ const project = { id: 'project-1', queue: { items: [queueItem] } };+ const commands = createTestCommands();+ const enqueueGenerate = vi.fn().mockResolvedValue({ batchId: 'batch-1', enqueued: 0, itemIds: [], requested: 1 });+ const runtime = createQueueRuntime({+ ...runtimeServices,+ backend: createTestBackend({ enqueueGenerate }),+ history: {+ commands,+ getSnapshot: () => ({ connectionStatus: 'connected', isHydrated: true, projects: [project] }),+ subscribe: vi.fn(() => vi.fn()),+ },+ journal: createTestJournal(),+ });++ runtime.start();++ await vi.waitFor(() =>+ expect(commands.setStatus).toHaveBeenCalledWith(+ expect.objectContaining({+ errorCode: 'not-accepted',+ projectId: project.id,+ queueItemId: queueItem.id,+ status: 'failed',+ })+ )+ );+ await runtime.dispose();+ });+it('leaves durable enqueue receipt acknowledgement to the durable acknowledgement worker', async () => {const queueItem = createPendingQueueItem();const project = { id: 'project-1', queue: { items: [queueItem] } };@@ -1689,8 +1758,15 @@ describe('queue runtime', () => {runtime.start();await vi.advanceTimersByTimeAsync(20_000);+ // The notice words the give-up itself and quotes the server's error as the reason.expect(commands.setStatus).toHaveBeenCalledWith(- expect.objectContaining({ projectId: project.id, queueItemId: queueItem.id, status: 'failed' })+ expect.objectContaining({+ error: 'graph validation crashed',+ errorCode: 'server-error',+ projectId: project.id,+ queueItemId: queueItem.id,+ status: 'failed',+ }));const attempts = enqueueGenerate.mock.calls.length;expect(attempts).toBeGreaterThanOrEqual(3);diff --git a/invokeai/frontend/webv2/src/features/queue/runtime.ts b/invokeai/frontend/webv2/src/features/queue/runtime.tsindex 594108e08c..9c87a0ec59 100644--- a/invokeai/frontend/webv2/src/features/queue/runtime.ts+++ b/invokeai/frontend/webv2/src/features/queue/runtime.ts@@ -1,4 +1,4 @@-import type { QueueItem } from '@features/queue/core/historyTypes';+import type { QueueItem, QueueRunErrorCode } from '@features/queue/core/historyTypes';import type {QueueBackendPort,QueueEnqueueGenerateRequest,@@ -136,7 +136,7 @@ export interface QueueHistoryCommands {}): void;setStatus(payload: {error?: string;- /** Set when `error` is a stand-in the notice words itself: the backend gave no reason, or the item vanished. */+ /** Set when the notice words the failure itself, in the user's language; `error` stays as English detail. */errorCode?: QueueRunErrorCode;/** The backend items whose failure ended the run, so the failure notice can show and retry them. */failedBackendItemIds?: readonly number[];@@ -147,8 +147,6 @@ export interface QueueHistoryCommands {}): void;}-export type QueueRunErrorCode = 'removed' | 'unexplained';-type QueueItemBackendSubmission =| { kind: 'generate'; request: QueueEnqueueGenerateRequest }| { kind: 'workflow'; request: QueueEnqueueWorkflowRequest }@@ -1857,6 +1855,7 @@ export const createQueueRuntime = ({settleRun(project.id, currentQueueItem.id);commands.setStatus({error: 'This run was not submitted because its project cannot be saved.',+ errorCode: 'project-not-saved',projectId: project.id,queueItemId: currentQueueItem.id,status: 'failed',@@ -1868,6 +1867,7 @@ export const createQueueRuntime = ({if (submission.kind === 'invalid') {commands.setStatus({error: submission.error,+ errorCode: 'invalid-submission',projectId: project.id,queueItemId: currentQueueItem.id,status: 'failed',@@ -1936,6 +1936,7 @@ export const createQueueRuntime = ({settleRun(project.id, currentQueueItem.id);commands.setStatus({error: error.message,+ errorCode: 'not-accepted',projectId: project.id,queueItemId: currentQueueItem.id,status: 'failed',@@ -2290,6 +2291,7 @@ export const createQueueRuntime = ({if (exhaustedServerError !== undefined) {commands.setStatus({error: exhaustedServerError,+ errorCode: 'server-error',projectId: project.id,queueItemId: currentQueueItem.id,status: 'failed',diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.test.tsindex 1af5798087..7679d81fb5 100644--- a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts@@ -32,6 +32,7 @@ import { getDocumentLeaves } from '@workbench/canvas-engine/api';import { stacksFrom } from '@workbench/canvas-engine/document-model/documentFixtures.testStub';import { stackTopAnchor } from '@workbench/canvas-engine/document/insertionAnchors.testStub';import { WIDGET_REGIONS } from '@workbench/layoutContracts';+import { createInstance } from 'i18next';import { afterEach, describe, expect, it, vi } from 'vitest';import type { CanvasProjectMutation } from './canvasProjectMutations';@@ -3982,6 +3983,53 @@ describe('workbenchReducer Phase 5 generation flow', () => {expect(state.notifications[0]).not.toHaveProperty('actions');});+ it.each([+ ['invalid-submission', 'Queue item has malformed workflow seed metadata.', 'invalidSubmissionMessage'],+ ['not-accepted', 'The backend queue did not accept this generation. The queue may be full.', 'notAcceptedMessage'],+ ['project-not-saved', 'This run was not submitted because its project cannot be saved.', 'projectNotSavedMessage'],+ ['server-error', 'graph validation crashed', 'serverErrorMessage'],+ ] as const)(+ 'words a %s failure through a translation key, quoting the error as its reason',+ (errorCode, error, key) => {+ const englishCatalog = import.meta.glob('../../public/locales/en.json', { eager: true, import: 'default' });+ const english = createInstance();+ void english.init({+ initAsync: false,+ interpolation: { escapeValue: false },+ lng: 'en',+ resources: { en: { translation: Object.values(englishCatalog)[0] as Record<string, unknown> } },+ });+ const messageKey = `notifications.runOutcome.${key}`;+ let state = submitGenerate(primeGenerate(undefined, { positivePrompt: 'A lighthouse in a storm' }));+ const project = getActiveProject(state);+ const failRun = (queueItemId: string) =>+ workbenchReducer(state, {+ error,+ errorCode,+ projectId: project.id,+ queueItemId,+ status: 'failed',+ type: 'setQueueItemStatus',+ });++ state = failRun(project.queue.items[0]!.id);+ const labeled = state.notifications[0]!;+ expect(labeled).toMatchObject({+ messageKey,+ messageValues: { label: 'A lighthouse in a storm', reason: error },+ titleKey: 'notifications.runOutcome.failed',+ });+ // The English stand-in is what the catalog says, so the notice reads the same before and after translation.+ expect(english.t(messageKey, labeled.messageValues)).toBe(labeled.message);++ // A run that already left the project's queue has no prompt to name.+ state = failRun('run-no-longer-in-the-queue');+ const unlabeled = state.notifications[0]!;+ expect(unlabeled).toMatchObject({ messageKey: `${messageKey}Unlabeled`, messageValues: { reason: error } });+ expect(english.t(`${messageKey}Unlabeled`, unlabeled.messageValues)).toBe(unlabeled.message);+ }+ );+it('reports a failure no backend item explains without follow-ups it cannot offer', () => {let state = submitGenerate(primeGenerate());const project = getActiveProject(state);diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.tsindex ea085c61b5..e82db6861d 100644--- a/invokeai/frontend/webv2/src/workbench/workbenchState.ts+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.ts@@ -1,6 +1,6 @@import type { GenerateWidgetValues, ImageWithDims } from '@features/generation/contracts';import type { ModelConfig } from '@features/models';-import type { QueueCompiledSubmission, QueueHistoryItemStatus } from '@features/queue/contracts';+import type { QueueCompiledSubmission, QueueHistoryItemStatus, QueueRunErrorCode } from '@features/queue/contracts';import type { ProjectGraphState, ProjectWorkflowSource } from '@features/workflow/contracts';import type { WorkflowSubmissionPlan } from '@features/workflow/graph';import type { LogNamespace } from '@platform/logging/contracts';@@ -467,8 +467,8 @@ type WorkbenchReducerAction =error?: string;/** The backend items whose failure ended the run; its failure notice offers to show and retry them. */failedBackendItemIds?: readonly number[];- /** `error` is a stand-in: the backend gave no reason, or the item vanished from its queue. */- errorCode?: 'removed' | 'unexplained';+ /** Set when the notice words the failure itself, in the user's language; `error` stays as English detail. */+ errorCode?: QueueRunErrorCode;notify?: boolean;}| {@@ -791,12 +791,56 @@ const withRunLabel = (return label ? describe(label) : unlabeled;};-/** Why a run failed, in words: the backend's own error verbatim, or a translated stand-in when it gave none. */+type CodedRunFailure = Exclude<QueueRunErrorCode, 'removed' | 'unexplained'>;++/**+ * Failures the queue runtime words itself, as translation keys with their English. `key` is the message for a run+ * with a prompt or workflow name, `${key}Unlabeled` the one without; `reason` is the server's or validator's text.+ */+const CODED_RUN_FAILURES: Record<+ CodedRunFailure,+ { key: string; labeled: (label: string, reason: string) => string; unlabeled: (reason: string) => string }+> = {+ 'invalid-submission': {+ key: 'notifications.runOutcome.invalidSubmissionMessage',+ labeled: (label, reason) => `“${label}” could not be submitted because its queued request is invalid: ${reason}`,+ unlabeled: (reason) => `The run could not be submitted because its queued request is invalid: ${reason}`,+ },+ 'not-accepted': {+ key: 'notifications.runOutcome.notAcceptedMessage',+ labeled: (label) => `The server queue did not accept “${label}”. The queue may be full.`,+ unlabeled: () => 'The server queue did not accept the run. The queue may be full.',+ },+ 'project-not-saved': {+ key: 'notifications.runOutcome.projectNotSavedMessage',+ labeled: (label) => `“${label}” was not submitted because its project cannot be saved.`,+ unlabeled: () => 'The run was not submitted because its project cannot be saved.',+ },+ 'server-error': {+ key: 'notifications.runOutcome.serverErrorMessage',+ labeled: (label, reason) => `The server kept failing to queue “${label}”: ${reason}`,+ unlabeled: (reason) => `The server kept failing to queue the run: ${reason}`,+ },+};++/**+ * Why a run failed, in words: a translated message for failures the runtime words itself (quoting the server's or+ * validator's text where it has one), the backend's own error verbatim, or a translated stand-in when it gave none.+ */const describeRunFailure = (queueItem: QueueItem | undefined,reason: string,- errorCode: 'removed' | 'unexplained' | undefined+ errorCode: QueueRunErrorCode | undefined): NotificationText => {+ if (errorCode && errorCode !== 'removed' && errorCode !== 'unexplained') {+ const { key, labeled, unlabeled } = CODED_RUN_FAILURES[errorCode];+ return withRunLabel(+ queueItem,+ (label) => ({ message: labeled(label, reason), messageKey: key, messageValues: { label, reason } }),+ { message: unlabeled(reason), messageKey: `${key}Unlabeled`, messageValues: { reason } }+ );+ }+if (errorCode === 'removed') {return withRunLabel(queueItem,@@ -851,7 +895,7 @@ const createRunOutcomeNotification = (status,}: {error?: string;- errorCode?: 'removed' | 'unexplained';+ errorCode?: QueueRunErrorCode;failedBackendItemIds?: readonly number[];status: 'cancelled' | 'failed';}