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.

fix(intermediates): recover from cleanup status lookup failures

Josh Corbett6b9866fa025d
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.json
index 7c577f3d89..21a4e32d26 100644
--- a/invokeai/frontend/webv2/public/locales/en.json
+++ b/invokeai/frontend/webv2/public/locales/en.json
@@ -4265,6 +4265,7 @@
"retry": "Retry unresolved",
"dismiss": "Dismiss",
"retryFailed": "Could not retry the cleanup.",
+ "lookupFailed": "Could not load cleanup status.",
"pendingDiskNote": "Some files could not be removed yet. They are cleaned up on the next server start and their space is not counted as reclaimed."
},
"empty": {
diff --git a/invokeai/frontend/webv2/src/features/intermediates/data/queries.ts b/invokeai/frontend/webv2/src/features/intermediates/data/queries.ts
index 834e0c2bb1..23883f1926 100644
--- a/invokeai/frontend/webv2/src/features/intermediates/data/queries.ts
+++ b/invokeai/frontend/webv2/src/features/intermediates/data/queries.ts
@@ -2,6 +2,7 @@ import type { IntermediatesOperation, IntermediatesSummary } from '@features/int
import { isOperationSettled } from '@features/intermediates/core/types';
import { assertAccountScopeCurrent, captureAccountScope, type AccountScope } from '@platform/state/accountLifecycle';
+import { ApiError } from '@platform/transport/http';
import { queryOptions } from '@tanstack/react-query';
import type { IntermediatesSummaryParams } from './keys';
@@ -33,6 +34,11 @@ export const intermediatesOperationQueryOptions = (operationId: string, owner =
queryFn: ({ signal }) =>
fenced(owner, (fencedSignal) => getIntermediatesOperation(operationId, fencedSignal), signal),
queryKey: intermediatesKeys.operation(owner, operationId),
- refetchInterval: (query) => (query.state.data && isOperationSettled(query.state.data) ? false : 2_000),
+ retry: (failureCount, error) => !(error instanceof ApiError && error.status === 404) && failureCount < 1,
+ refetchInterval: (query) =>
+ (query.state.error instanceof ApiError && query.state.error.status === 404) ||
+ (query.state.data && isOperationSettled(query.state.data))
+ ? false
+ : 2_000,
staleTime: 1_000,
});
diff --git a/invokeai/frontend/webv2/src/features/intermediates/ui/IntermediatesManager.browser.test.tsx b/invokeai/frontend/webv2/src/features/intermediates/ui/IntermediatesManager.browser.test.tsx
index a4abd9509f..284690c8da 100644
--- a/invokeai/frontend/webv2/src/features/intermediates/ui/IntermediatesManager.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/intermediates/ui/IntermediatesManager.browser.test.tsx
@@ -619,6 +619,40 @@ describe('IntermediatesManager', () => {
);
});
+ it('shows a restored operation lookup failure and retries the lookup without starting cleanup', async () => {
+ const { followIntermediatesOperation } = await import('@features/intermediates/data/operationStore');
+ followIntermediatesOperation('op-1');
+ dependencies.getIntermediatesOperation.mockRejectedValue(new ApiError('Status temporarily unavailable', 503));
+ await renderManager();
+ await vi.waitFor(() => expect(host.textContent).toContain('intermediates.operation.lookupFailed'), {
+ timeout: 4000,
+ });
+ expect(host.textContent).toContain('Status temporarily unavailable');
+ await page.screenshot({ path: '../../../../artifacts/intermediates/operation-lookup-error.png' });
+ dependencies.getIntermediatesOperation.mockResolvedValue(operationOf('completed'));
+ await act(() => buttonWithText('common.retry', host).click());
+ await vi.waitFor(() => expect(host.textContent).toContain('intermediates.operation.status.completed'));
+ expect(dependencies.startIntermediatesOperation).not.toHaveBeenCalled();
+ expect(dependencies.retryIntermediatesOperation).not.toHaveBeenCalled();
+ });
+
+ it('stops polling a missing operation and lets its receipt be dismissed', async () => {
+ const { followIntermediatesOperation, activeOperationStore } =
+ await import('@features/intermediates/data/operationStore');
+ followIntermediatesOperation('missing');
+ dependencies.getIntermediatesOperation.mockRejectedValue(new ApiError('Operation not found', 404));
+ await renderManager();
+ await vi.waitFor(() => expect(host.textContent).toContain('Operation not found'));
+ const calls = dependencies.getIntermediatesOperation.mock.calls.length;
+ await new Promise((resolve) => {
+ setTimeout(resolve, 2200);
+ });
+ expect(dependencies.getIntermediatesOperation).toHaveBeenCalledTimes(calls);
+ await act(() => buttonWithText('intermediates.operation.dismiss', host).click());
+ expect(activeOperationStore.getSnapshot().operationId).toBeNull();
+ expect(sessionStorage.getItem('invokeai:webv2:intermediates-receipt:local')).toBeNull();
+ expect(document.activeElement).toBe(host.querySelector('[aria-label="intermediates.searchLabel"]'));
+ });
it('reconciles excluded rows after refresh across pages without forgetting their identities', async () => {
let currentRows = Array.from({ length: 120 }, (_, index) => row(`p${index}`, `Project ${index}`, 1));
dependencies.getIntermediatesSummary
diff --git a/invokeai/frontend/webv2/src/features/intermediates/ui/IntermediatesManager.tsx b/invokeai/frontend/webv2/src/features/intermediates/ui/IntermediatesManager.tsx
index 1c0f02e18f..04dfb93744 100644
--- a/invokeai/frontend/webv2/src/features/intermediates/ui/IntermediatesManager.tsx
+++ b/invokeai/frontend/webv2/src/features/intermediates/ui/IntermediatesManager.tsx
@@ -535,6 +535,13 @@ export const IntermediatesManager = ({ canClearOthersIntermediates, currentUserI
{activeOperationId ? (
<OperationPanel
isLoading={operationQuery.isPending}
+ isRefetching={operationQuery.isFetching}
+ lookupError={
+ operationQuery.isError
+ ? getApiErrorMessage(operationQuery.error, t('intermediates.operation.lookupFailed'))
+ : null
+ }
+ onRefetch={() => void operationQuery.refetch()}
isRetrying={isRetrying}
operation={operationQuery.data ?? null}
retryError={retryError}
diff --git a/invokeai/frontend/webv2/src/features/intermediates/ui/OperationPanel.tsx b/invokeai/frontend/webv2/src/features/intermediates/ui/OperationPanel.tsx
index 6b0d886741..b6f048a4dd 100644
--- a/invokeai/frontend/webv2/src/features/intermediates/ui/OperationPanel.tsx
+++ b/invokeai/frontend/webv2/src/features/intermediates/ui/OperationPanel.tsx
@@ -15,6 +15,9 @@ import { formatBytes, formatCount } from './format';
export interface OperationPanelProps {
operation: IntermediatesOperation | null;
isLoading: boolean;
+ isRefetching: boolean;
+ lookupError: string | null;
+ onRefetch: () => void;
retryError: string | null;
isRetrying: boolean;
onRetry: () => void;
@@ -35,6 +38,9 @@ const Stat = ({ label, value }: { label: string; value: string }) => (
/** The active or most recent cleanup: progress while it runs, a breakdown once it stops, retry for what failed. */
export const OperationPanel = ({
isLoading,
+ isRefetching,
+ lookupError,
+ onRefetch,
isRetrying,
onDismiss,
onRetry,
@@ -43,6 +49,26 @@ export const OperationPanel = ({
}: OperationPanelProps) => {
const { t } = useTranslation();
+ if (lookupError) {
+ return (
+ <Alert.Root size="sm" status="error" variant="surface">
+ <Alert.Indicator />
+ <Alert.Content>
+ <Alert.Title>{t('intermediates.operation.lookupFailed')}</Alert.Title>
+ <Alert.Description>{lookupError}</Alert.Description>
+ <HStack gap="2" mt="2">
+ <Button loading={isRefetching} size="2xs" variant="outline" onClick={onRefetch}>
+ {t('common.retry')}
+ </Button>
+ <Button size="2xs" variant="ghost" onClick={onDismiss}>
+ {t('intermediates.operation.dismiss')}
+ </Button>
+ </HStack>
+ </Alert.Content>
+ </Alert.Root>
+ );
+ }
+
if (!operation) {
return isLoading ? (
<Text color="fg.muted" fontSize="xs">