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: converge every pre-wiring video render failure on one terminal path (#4617)
[._.]/ Adam Eivyab21dc559540
diff --git a/server/services/videoGen/local.js b/server/services/videoGen/local.jsindex 7f267cfd6f..fea97d9a0f 100644--- a/server/services/videoGen/local.js+++ b/server/services/videoGen/local.js@@ -1738,7 +1738,6 @@ export async function generateVideo({ pythonPath, prompt, negativePrompt = '', mvoid cleanupTempFiles({ includeUploads: true, includeUntrackedAudio: true });closeJobAfterDelay(jobs, jobId);};- proc.on('error', handleChildError);let missingPyModule = null;// Rolling tail of this child's stderr. The Metal abort text is the only@@ -1910,6 +1909,12 @@ export async function generateVideo({ pythonPath, prompt, negativePrompt = '', mcloseJobAfterDelay(jobs, jobId);}};+ // Both real subscriptions land here, at the very end. Nothing in this+ // function awaits, so no event can fire before them — and a throw anywhere+ // above (a stream handle that vanished) therefore leaves the child with NO+ // real listeners, so the caller's exit buffer stays its only sink instead of+ // a half-wired handler reporting the job twice.+ proc.on('error', handleChildError);proc.on('close', handleChildClose);return { handleChildClose, handleChildError };};@@ -1924,13 +1929,16 @@ export async function generateVideo({ pythonPath, prompt, negativePrompt = '', m// that already owns the job must never be mistaken for an abandoned one by// the failure path that would otherwise kill it.const wireSpawnedChild = (proc, takeEarlyExit) => {- // The buffer is the primary catch. Reading the corpse's exit state is the- // backstop for a handle that recorded its exit without emitting anything.+ // Wire first, then read the buffer: wireRenderChild() never awaits, so+ // nothing can fire between the two — and if it throws, the buffer is still+ // attached and keeps absorbing this child's events while the caller kills+ // it. The buffer is the primary catch; reading the corpse's exit state is+ // the backstop for a handle that recorded its exit without emitting.+ const { handleChildClose, handleChildError } = wireRenderChild(proc);const earlyExit = takeEarlyExit()|| (proc.exitCode !== null || proc.signalCode !== null? { type: 'close', code: proc.exitCode, signal: proc.signalCode }: null);- const { handleChildClose, handleChildError } = wireRenderChild(proc);const replayEarlyExit = async () => {if (!earlyExit) return;console.log(`⚠️ video render child exited before it was wired [${jobId.slice(0, 8)}]`);@@ -2059,6 +2067,25 @@ export async function generateVideo({ pythonPath, prompt, negativePrompt = '', m}};+ // Every failure before this render child is wired converges here. Nothing+ // is listening yet, so the child can never report its own terminal event —+ // without this the job would sit `running` in the jobs map forever, holding+ // the accelerator claim and its staged temp files, exactly the way #4617's+ // lost 'close' did. Mirrors the buildArgs failure path above so every+ // pre-wiring failure looks the same to the client and to the media queue.+ const abandonBeforeWiring = async (err) => {+ stopAbandonedChild(firstProc);+ if (activeProcess === firstProc) activeProcess = null;+ await releaseHeavyClaim();+ job.status = 'error';+ const reason = err.message || 'Video generation failed before the render child was wired';+ console.log(`❌ Video generation setup error [${jobId.slice(0, 8)}]: ${reason}`);+ broadcastSse(job, { type: 'error', error: reason });+ videoGenEvents.emit('failed', { generationId: jobId, error: reason });+ void cleanupTempFiles({ includeUploads: true, includeUntrackedAudio: true });+ closeJobAfterDelay(jobs, jobId);+ };+try {const memoryReport = await prepareLocalMemory();if (memoryReport.unloaded.length) console.log(`🧹 Video generation [${jobId.slice(0, 8)}] freed ${memoryReport.unloaded.length} resident model(s)`);@@ -2138,20 +2165,23 @@ export async function generateVideo({ pythonPath, prompt, negativePrompt = '', mactiveProcess = firstProc;await heavyClaim.handoffTo?.(firstProc.pid);} catch (err) {- // Nothing is wired, so this child can never report a terminal event and- // nothing would reap it — and once the handoff pointed the claim at its PID,- // nothing would release the claim either. Stop it and release unconditionally- // (release() is idempotent and still ours after a handoff).- stopAbandonedChild(firstProc);- if (activeProcess === firstProc) activeProcess = null;- await releaseHeavyClaim();+ await abandonBeforeWiring(err);throw err;}// Terminal listeners go on here, and the buffer hands over anything the child// already emitted — so a child that died during the handoff still drives the// job to a terminal state and gives the accelerator claim back.- const replayEarlyExit = wireSpawnedChild(firstProc, takeEarlyExit);+ let replayEarlyExit;+ try {+ replayEarlyExit = wireSpawnedChild(firstProc, takeEarlyExit);+ } catch (err) {+ // Wiring itself threw (a stream handle that vanished under us), so this+ // child has no terminal handler and never will — the same dead end the+ // relaunch path guards with `retryWired`.+ await abandonBeforeWiring(err);+ throw err;+ }await replayEarlyExit();return { jobId, generationId: jobId, filename, mode: 'local', model: modelId };diff --git a/server/services/videoGen/local.test.js b/server/services/videoGen/local.test.jsindex 1cd57ad1d3..c382dd3ac4 100644--- a/server/services/videoGen/local.test.js+++ b/server/services/videoGen/local.test.js@@ -4277,14 +4277,14 @@ describe('generateVideo — Gemma prompt-encode watchdog relaunch', () => {describe('generateVideo — first render child dies during the accelerator handoff', () => {// A child that never exits on its own, so the test decides exactly when — and// from where — its terminal event fires.- const makeSilentProc = (pid) => {+ const makeSilentProc = (pid, { failWiring = false } = {}) => {const listeners = {};const proc = {pid,exitCode: null,signalCode: null,killed: false,- stdout: { on: vi.fn() },+ stdout: { on: vi.fn(() => { if (failWiring) throw new Error('stdout stream vanished'); }) },stderr: { on: vi.fn() },on(event, fn) { listeners[event] = fn; return proc; },off(event, fn) { if (listeners[event] === fn) delete listeners[event]; return proc; },@@ -4384,5 +4384,32 @@ describe('generateVideo — first render child dies during the accelerator hando// running, and the claim it may already have been handed has to come back.expect(child.proc.kill).toHaveBeenCalledWith('SIGTERM');expect(heavyClaimRelease).toHaveBeenCalled();+ // …and the job converges instead of sitting `running` in the jobs map with+ // its staged temp files, which is the same stranding #4617 is about.+ expect(failures).toHaveLength(1);+ expect(failures[0].error).toMatch(/claim file vanished/);+ });++ it('stops the child and fails the job when the wiring itself throws', async () => {+ const child = makeSilentProc(204, { failWiring: true });+ const { spawnDetached } = await import('../../lib/detachedSpawn.js');+ vi.mocked(spawnDetached).mockClear();+ vi.mocked(spawnDetached).mockResolvedValueOnce(child.proc);++ await expect(generateVideo({+ jobId: 'first-child-wiring-throws',+ pythonPath: '/usr/bin/python3',+ modelId: 'ltx2_unified',+ prompt: 'a lighthouse in fog',+ width: 512,+ height: 512,+ numFrames: 25,+ fps: 24,+ seed: 987654,+ })).rejects.toThrow('stdout stream vanished');++ expect(child.proc.kill).toHaveBeenCalledWith('SIGTERM');+ expect(heavyClaimRelease).toHaveBeenCalled();+ expect(failures).toHaveLength(1);});});