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 finished-but-hung render's output when the idle timer kills it
[._.]/ Adam Eivy0a0578ef5d9b
diff --git a/server/services/videoGen/generateVideoHelpers.js b/server/services/videoGen/generateVideoHelpers.jsindex 8eab670924..cf2bda81af 100644--- a/server/services/videoGen/generateVideoHelpers.js+++ b/server/services/videoGen/generateVideoHelpers.js@@ -222,13 +222,22 @@ export function makeVideoGenLineHandler({ job, jobId, pythonNoiseRe }) {}/**- * Whether a watchdog-triggered SIGKILL should be treated as success: the- * render emitted its completion marker (so the watchdog armed + fired) and- * the output file is actually on disk and non-empty. A marker without a real- * output (malformed runtime) still fails loudly.+ * Whether a PortOS-fired SIGKILL should be treated as success rather than a+ * failure. Two Node-side watchdogs can SIGKILL a render:+ * - the completion watchdog (armed after a completion marker, guards a+ * post-completion teardown hang), and+ * - the pre-output idle-stall deadline (fires when a render goes silent).+ * Either kill is a SUCCESS when a real output file is already on disk and+ * non-empty — e.g. a runtime that wrote its .mp4 but never printed a+ * recognized completion marker (so the completion watchdog never armed) and+ * then hung: the idle timer kills it, but the finished video must still be+ * kept, not discarded as "no output". A kill with no output on disk (a genuine+ * pre-output stall, or a marker from a malformed runtime that wrote nothing)+ * still fails loudly. `idleStallFired` defaults false so existing callers that+ * only track the completion watchdog keep their exact prior behavior.*/-export function isWatchdogSuccess({ completionWatchdogFired, signal, outputPath }) {- return completionWatchdogFired && signal === 'SIGKILL'+export function isWatchdogSuccess({ completionWatchdogFired, idleStallFired = false, signal, outputPath }) {+ return (completionWatchdogFired || idleStallFired) && signal === 'SIGKILL'&& existsSync(outputPath) && statSync(outputPath).size > 0;}diff --git a/server/services/videoGen/local.js b/server/services/videoGen/local.jsindex c4633d82e4..ab44e60870 100644--- a/server/services/videoGen/local.js+++ b/server/services/videoGen/local.js@@ -1062,12 +1062,14 @@ export async function generateVideo({ pythonPath, prompt, negativePrompt = '', mawait unlink(audioFilePath).catch(() => {});}- // A watchdog-triggered SIGKILL means the render already emitted its- // completion marker and only the python teardown hung — the output file is- // on disk, so treat it as success (not the generic "killed, likely OOM"- // failure). Guard on the file actually existing + being non-empty so a- // marker without a real output (a malformed runtime) still fails loudly.- const watchdogSuccess = isWatchdogSuccess({ completionWatchdogFired, signal, outputPath });+ // A PortOS-fired SIGKILL (completion-teardown watchdog OR idle-stall+ // deadline) is a SUCCESS when the output file is already on disk and+ // non-empty — e.g. a runtime that wrote its .mp4 but never printed a+ // recognized completion marker, then hung: the idle timer kills it, but+ // the finished video must be kept, not discarded as "no output". A kill+ // with no output on disk (a genuine pre-output stall, or a marker from a+ // malformed runtime that wrote nothing) still fails loudly below.+ const watchdogSuccess = isWatchdogSuccess({ completionWatchdogFired, idleStallFired, signal, outputPath });if (code !== 0 && !watchdogSuccess) {job.status = 'error';@@ -1100,7 +1102,8 @@ export async function generateVideo({ pythonPath, prompt, negativePrompt = '', mvideoGenEvents.emit('failed', { generationId: jobId, error: reason });} else {if (watchdogSuccess) {- console.log(`⚠️ video child force-killed after completion teardown hang — output is intact [${jobId.slice(0, 8)}]`);+ const killCause = idleStallFired ? 'idle-stall deadline' : 'completion teardown hang';+ console.log(`⚠️ video child force-killed (${killCause}) — output is intact [${jobId.slice(0, 8)}]`);}await finalizeGeneratedVideo({ job, jobId, outputPath, filename, meta, actualSeed, mutateHistory: mutateVideoHistory });}diff --git a/server/services/videoGen/local.test.js b/server/services/videoGen/local.test.jsindex 501e86afe7..43a4715788 100644--- a/server/services/videoGen/local.test.js+++ b/server/services/videoGen/local.test.js@@ -1000,9 +1000,14 @@ describe('generateVideo — pre-output idle-stall deadline', () => {({ generateVideo } = await import('./local.js'));({ videoGenEvents } = await import('./events.js'));- // No output file was ever written (stalled before output), so even though- // the fs mock returns true, the failure path must not treat this as a- // watchdog success — that gate keys on completionWatchdogFired, not this.+ // A genuine pre-output stall wrote no real output — a 0-byte (or absent)+ // file. Keep existsSync true (the runtime venv check at build time needs+ // it) but report size 0 so isWatchdogSuccess correctly declines to treat+ // the kill as success; the failure path must report it as a stall.+ const { existsSync, statSync } = await import('fs');+ vi.mocked(existsSync).mockReturnValue(true);+ vi.mocked(statSync).mockReturnValue({ size: 0 });+const { spawnDetached } = await import('../../lib/detachedSpawn.js');const hang = makeHangingProc();vi.mocked(spawnDetached).mockImplementationOnce(async () => hang.proc);@@ -1040,6 +1045,54 @@ describe('generateVideo — pre-output idle-stall deadline', () => {expect(failed[1].error).toMatch(/VIDEOGEN_IDLE_STALL_MS/);});+ it('treats an idle-stall kill as SUCCESS when a real output file is on disk (runtime wrote its .mp4 but never printed a completion marker, then hung)', async () => {+ process.env.VIDEOGEN_IDLE_STALL_MS = '60000';+ vi.resetModules();+ ({ generateVideo } = await import('./local.js'));+ ({ videoGenEvents } = await import('./events.js'));++ // The output file exists + is non-empty — the render finished its real work+ // and wrote the video, but emitted no recognized completion marker, so the+ // completion watchdog never armed and the idle timer is what killed the+ // teardown hang. The finished output must be kept, not discarded.+ const { existsSync, statSync } = await import('fs');+ vi.mocked(existsSync).mockReturnValue(true);+ vi.mocked(statSync).mockReturnValue({ size: 1000 });++ const { spawnDetached } = await import('../../lib/detachedSpawn.js');+ const hang = makeHangingProc();+ vi.mocked(spawnDetached).mockImplementationOnce(async () => hang.proc);++ const events = [];+ const onCompleted = (e) => events.push(['completed', e]);+ const onFailed = (e) => events.push(['failed', e]);+ videoGenEvents.on('completed', onCompleted);+ videoGenEvents.on('failed', onFailed);++ generateVideo({+ jobId: 'idle-stall-output-intact',+ pythonPath: '/usr/bin/python3',+ modelId: 'ltx2_unified',+ prompt: 'wrote output but hung silently',+ width: 512, height: 512, numFrames: 25, fps: 24,+ mode: 'text',+ });+ await vi.advanceTimersByTimeAsync(0);++ // No completion marker ever printed; the render goes silent after writing.+ await vi.advanceTimersByTimeAsync(60001);+ expect(hang.proc.kill).toHaveBeenCalledWith('SIGKILL');+ hang.fireClose(null, 'SIGKILL');+ await vi.advanceTimersByTimeAsync(0);++ videoGenEvents.off('completed', onCompleted);+ videoGenEvents.off('failed', onFailed);++ const kinds = events.map(([k]) => k);+ expect(kinds).toContain('completed');+ expect(kinds).not.toContain('failed');+ });+it('does NOT fire the idle timer when the child exits cleanly (timer cleared on close)', async () => {process.env.VIDEOGEN_IDLE_STALL_MS = '60000';vi.resetModules();