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(webv2): stop re-reporting an already-open bitmap circuit

joshistoastfe229c42c9a2
diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/document/bitmapStore.test.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/document/bitmapStore.test.ts
index c0f20fd24f..9a52f8cc69 100644
--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/document/bitmapStore.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/document/bitmapStore.test.ts
@@ -1270,6 +1270,64 @@ describe('createBitmapStore', () => {
h.store.dispose();
});
+ it('does not re-report when a barrier retries an already-open circuit', async () => {
+ const timers = createManualTimers();
+ const uploadImage = vi.fn(() => Promise.reject(new Error('upload failed')));
+ const onError = vi.fn();
+ const h = createHarness({ maxConsecutiveFailures: 3, maxUploadAttempts: 1, onError, timers, uploadImage });
+
+ h.store.markLayerDirty(LAYER);
+ timers.fireNext(); // failure 1 of 3.
+ await drainUntil(() => timers.scheduledDelays.length === 2);
+ timers.fireNext(); // failure 2 of 3.
+ await drainUntil(() => timers.scheduledDelays.length === 3);
+ timers.fireNext(); // failure 3 of 3 → circuit opens.
+ await drainUntil(() => onError.mock.calls.length === 2);
+ await drainUntil(() => false, 10);
+
+ expect(uploadImage).toHaveBeenCalledTimes(3);
+ expect(onError).toHaveBeenCalledTimes(2);
+
+ // flushPendingUploads() runs before every Generate/export and on
+ // blur/pagehide/visibilitychange; it still attempts a circuit-open layer
+ // (the breaker only gates the AMBIENT reschedule), so a persistently
+ // failing layer must not re-report on every one of those barrier retries.
+ await expect(h.store.flushPendingUploads()).rejects.toThrow('Canvas pixel persistence failed');
+ await expect(h.store.flushPendingUploads()).rejects.toThrow('Canvas pixel persistence failed');
+
+ expect(uploadImage).toHaveBeenCalledTimes(5);
+ expect(onError).toHaveBeenCalledTimes(2);
+
+ h.store.dispose();
+ });
+
+ it('reports exactly once when maxConsecutiveFailures is 1 (opens on the very first failure)', async () => {
+ const timers = createManualTimers();
+ const uploadImage = vi.fn(() => Promise.reject(new Error('upload failed')));
+ const onError = vi.fn();
+ const h = createHarness({ maxConsecutiveFailures: 1, maxUploadAttempts: 1, onError, timers, uploadImage });
+
+ h.store.markLayerDirty(LAYER);
+ timers.fireNext(); // the only ambient attempt: the circuit opens immediately.
+ await drainUntil(() => onError.mock.calls.length === 1);
+ await drainUntil(() => false, 10);
+
+ expect(timers.pendingCount()).toBe(0);
+ expect(onError).toHaveBeenCalledTimes(1);
+ expect(onError).toHaveBeenNthCalledWith(1, expect.any(Error), LAYER, {
+ consecutiveFailures: 1,
+ willRetry: false,
+ });
+
+ // Further barrier retries against the already-open circuit stay silent.
+ await expect(h.store.flushPendingUploads()).rejects.toThrow('Canvas pixel persistence failed');
+ await expect(h.store.flushPendingUploads()).rejects.toThrow('Canvas pixel persistence failed');
+
+ expect(onError).toHaveBeenCalledTimes(1);
+
+ h.store.dispose();
+ });
+
it('a new stroke closes the circuit and resets the failure count', async () => {
const timers = createManualTimers();
let shouldFail = true;
diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/document/bitmapStore.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/document/bitmapStore.ts
index 2b709ed179..1d080504e4 100644
--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/document/bitmapStore.ts
+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/document/bitmapStore.ts
@@ -355,10 +355,16 @@ export const createBitmapStore = (deps: BitmapStoreDeps): BitmapStore => {
dirty.add(layerId);
dirtyReason.set(layerId, 'failure');
// Report only the first failure of a streak and the one that opens the
- // circuit — an unreachable server would otherwise toast once per retry,
- // forever. Intermediate retries stay silent; `runFlush`'s `finally` still
- // bounds them via the same `failureCounts` and growing backoff below.
- if (failures === 1 || !willRetry) {
+ // circuit — an unreachable server would otherwise toast once per retry
+ // (including barrier-driven retries against an already-open circuit,
+ // which `flushPendingUploads` still attempts on every Generate/export/
+ // blur), forever. Everything else stays silent; `runFlush`'s `finally`
+ // still bounds ambient retries via the same `failureCounts` and growing
+ // backoff below. `failures` only grows once the circuit is open (a fresh
+ // stroke is the only way to reset it), so comparing to the exact
+ // transition point — not `!willRetry`, which stays true forever after —
+ // keeps this to exactly one report per streak-open transition.
+ if (failures === 1 || failures === maxConsecutiveFailures) {
try {
reportError(error, layerId, { consecutiveFailures: failures, willRetry });
} catch {