Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: keep a fal.ai render that completes on the final status poll (#12053)
[._.]/ Adam Eivy554be892a521
diff --git a/server/services/falQueue.js b/server/services/falQueue.jsindex d835163606..ae4ecfa0f6 100644--- a/server/services/falQueue.js+++ b/server/services/falQueue.js@@ -213,6 +213,11 @@ export async function awaitFalCompletion({}statusFailures = 0;if (status.status === 'COMPLETED') {+ // A poll that started inside the budget and returned COMPLETED is a+ // finished paid render. `remoteTerminal` is set before the break so the+ // post-loop deadline check cannot discard it when the round trip+ // straddles `deadline` (#12053). Cancel still wins if the caller aborted+ // while this read was in flight.entry.remoteTerminal = true;break;}@@ -228,6 +233,9 @@ export async function awaitFalCompletion({await cancelFalRequest(entry);return { outcome: 'canceled' };}+ // Reaching here with remoteTerminal means the COMPLETED branch broke out.+ // ERROR returns inside the loop, so this is not a failed render.+ if (entry.remoteTerminal) return { outcome: 'completed' };if (Date.now() >= deadline) {await cancelFalRequest(entry);return { outcome: 'failed', reason: `fal.ai did not finish within ${Math.round(timeoutMs / 1000)}s` };diff --git a/server/services/falQueue.test.js b/server/services/falQueue.test.jsindex b690d6f9d8..aba926f8dc 100644--- a/server/services/falQueue.test.js+++ b/server/services/falQueue.test.js@@ -1,7 +1,10 @@import { describe, it, expect, vi, afterEach } from 'vitest';import { cancelFalRequest, submitFalRequest, awaitFalCompletion, createFalRequestEntry } from './falQueue.js';-afterEach(() => vi.unstubAllGlobals());+afterEach(() => {+ vi.unstubAllGlobals();+ vi.useRealTimers();+});describe('awaitFalCompletion', () => {it.each(['COMPLETED', 'ERROR'])('waits for cancellation transport when concurrent status reports %s', async remoteStatus => {@@ -87,4 +90,32 @@ describe('awaitFalCompletion', () => {expect(fetchMock.mock.calls[0][0]).toBe(entry.cancelUrl);expect(fetchMock.mock.calls[0][1].method).toBe('PUT');});++ // The status read is allowed to start in the last moments of the budget.+ // COMPLETED that arrives after `deadline` is still a finished render (#12053).+ it('keeps a COMPLETED status that resolves after the deadline', async () => {+ vi.useFakeTimers();+ const start = Date.now();+ let releaseStatus;+ vi.stubGlobal('fetch', vi.fn(() => new Promise((resolve) => {+ releaseStatus = resolve;+ })));+ const entry = createFalRequestEntry('test-key');+ entry.cancelUrl = 'https://queue.fal.run/example/requests/abc/cancel';+ const pending = awaitFalCompletion({+ entry,+ statusUrl: 'https://queue.fal.run/example/status',+ apiKey: 'test-key',+ deadline: start + 50,+ timeoutMs: 50,+ });++ await vi.advanceTimersByTimeAsync(0);+ await vi.advanceTimersByTimeAsync(200);+ releaseStatus({ ok: true, json: async () => ({ status: 'COMPLETED' }) });++ await expect(pending).resolves.toEqual({ outcome: 'completed' });+ expect(entry.remoteTerminal).toBe(true);+ expect(entry.canceledRemote).toBeFalsy();+ });});