Skip to content

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

fix([issue-724]): treat watchdog SIGKILL after completion as success, not failure

[._.]/ Adam Eivyc350dfb97bcc
diff --git a/server/services/videoGen/local.js b/server/services/videoGen/local.js
index 66656174d4..8613f03f5d 100644
--- a/server/services/videoGen/local.js
+++ b/server/services/videoGen/local.js
@@ -770,6 +770,11 @@ export async function generateVideo({ pythonPath, prompt, negativePrompt = '', m
// 'error') so the timer can't outlive this child or fire against a recycled
// PID. Armed at most once per child (re-seeing the marker is a no-op).
let completionWatchdog = null;
+ // Set when the watchdog itself fires the SIGKILL. The 'close' handler reads
+ // it so it can treat that kill as success (the render already wrote its file —
+ // we only killed a post-completion teardown hang) rather than reporting the
+ // generic "killed, likely OOM" failure.
+ let completionWatchdogFired = false;
const clearCompletionWatchdog = () => {
if (completionWatchdog) {
clearTimeout(completionWatchdog);
@@ -785,6 +790,7 @@ export async function generateVideo({ pythonPath, prompt, negativePrompt = '', m
completionWatchdog = null;
if (activeProcess !== proc || proc.exitCode !== null || proc.signalCode !== null) return;
console.log(`⚠️ video child reported completion but never exited — SIGKILL [${jobId.slice(0, 8)}]`);
+ completionWatchdogFired = true;
proc.kill('SIGKILL');
} catch (err) {
console.error(`❌ completion watchdog failed [${jobId.slice(0, 8)}]: ${err.message}`);
@@ -972,7 +978,15 @@ export async function generateVideo({ pythonPath, prompt, negativePrompt = '', m
await unlink(audioFilePath).catch(() => {});
}
- if (code !== 0) {
+ // 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 = completionWatchdogFired && signal === 'SIGKILL'
+ && existsSync(outputPath) && statSync(outputPath).size > 0;
+
+ if (code !== 0 && !watchdogSuccess) {
job.status = 'error';
let reason;
if (missingPyModule) {
@@ -997,6 +1011,9 @@ export async function generateVideo({ pythonPath, prompt, negativePrompt = '', m
broadcastSse(job, { type: 'error', error: `Generation failed: ${reason}` });
videoGenEvents.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)}]`);
+ }
job.status = 'complete';
await optimizeForStreaming(outputPath);
const thumbnail = await generateThumbnail(outputPath, jobId);
diff --git a/server/services/videoGen/local.test.js b/server/services/videoGen/local.test.js
index 12f69e8748..f8bdf2980c 100644
--- a/server/services/videoGen/local.test.js
+++ b/server/services/videoGen/local.test.js
@@ -553,6 +553,93 @@ describe('generateVideo — panel-side completion watchdog', () => {
expect(hang.proc.kill).toHaveBeenCalledWith('SIGKILL');
});
+ it('reports completed (not failed) when the watchdog SIGKILL fires after a real render finished', async () => {
+ process.env.VIDEOGEN_COMPLETION_WATCHDOG_MS = '40000';
+ vi.resetModules();
+ ({ generateVideo } = await import('./local.js'));
+ ({ videoGenEvents } = await import('./events.js'));
+
+ // The output file exists + is non-empty (fs mock already returns true/size 1000),
+ // so the watchdog-killed render must be treated as a success.
+ const { existsSync, statSync } = await import('fs');
+ vi.mocked(existsSync).mockReturnValue(true);
+ vi.mocked(statSync).mockReturnValue({ size: 1000 });
+
+ const { spawn } = await import('child_process');
+ const hang = makeHangingProc();
+ vi.mocked(spawn).mockImplementationOnce(() => 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: 'watchdog-success-recover',
+ pythonPath: '/usr/bin/python3',
+ modelId: 'ltx2_unified',
+ prompt: 'render then teardown-hang',
+ width: 512, height: 512, numFrames: 25, fps: 24,
+ mode: 'text',
+ });
+ await vi.advanceTimersByTimeAsync(0);
+
+ // Render emits its result JSON, then hangs in teardown.
+ hang.emitStdout('{"video_path": "/data/videos/out.mp4"}\n');
+ // Watchdog fires the SIGKILL past the grace window.
+ await vi.advanceTimersByTimeAsync(40001);
+ expect(hang.proc.kill).toHaveBeenCalledWith('SIGKILL');
+ // The OS delivers the kill → 'close' fires with signal 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('still reports failed when a SIGKILL arrives without a completion marker (real OOM kill)', async () => {
+ process.env.VIDEOGEN_COMPLETION_WATCHDOG_MS = '40000';
+ vi.resetModules();
+ ({ generateVideo } = await import('./local.js'));
+ ({ videoGenEvents } = await import('./events.js'));
+
+ const { spawn } = await import('child_process');
+ const hang = makeHangingProc();
+ vi.mocked(spawn).mockImplementationOnce(() => 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: 'watchdog-oom-kill',
+ pythonPath: '/usr/bin/python3',
+ modelId: 'ltx2_unified',
+ prompt: 'oom before completion',
+ width: 512, height: 512, numFrames: 25, fps: 24,
+ mode: 'text',
+ });
+ await vi.advanceTimersByTimeAsync(0);
+
+ // No completion marker ever seen — the kernel OOM-kills the child mid-render.
+ 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('failed');
+ expect(kinds).not.toContain('completed');
+ });
+
it('does NOT SIGKILL when the child exits cleanly after completion (timer is cleared on close)', async () => {
process.env.VIDEOGEN_COMPLETION_WATCHDOG_MS = '40000';
vi.resetModules();