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: preserve early video renderer diagnostics
[._.]/ Adam Eivy2512578f6c5d
diff --git a/server/services/videoGen/generateVideoHelpers.js b/server/services/videoGen/generateVideoHelpers.jsindex 493d17299b..5df5715d59 100644--- a/server/services/videoGen/generateVideoHelpers.js+++ b/server/services/videoGen/generateVideoHelpers.js@@ -713,16 +713,30 @@ export async function verifyPostCompletionOutputs({ outputPaths, completedOutput* attached is also valid: for a child that is being abandoned rather than* wired, it stays a harmless sink that keeps an 'error' from going unhandled.*/-export function bufferChildExit(proc) {+export function bufferChildExit(proc, { bufferOutput = false } = {}) {let buffered = null;+ const output = [];const onClose = (code, signal) => { buffered = buffered || { type: 'close', code, signal }; };const onError = (error) => { buffered = buffered || { type: 'error', error }; };+ const onStdout = (chunk) => output.push({ stream: 'stdout', chunk });+ const onStderr = (chunk) => output.push({ stream: 'stderr', chunk });+ onStdout.__earlyBuffer = true;+ onStderr.__earlyBuffer = true;proc.on('close', onClose);proc.on('error', onError);+ if (bufferOutput) {+ proc.stdout?.on('data', onStdout);+ proc.stderr?.on('data', onStderr);+ }return () => {proc.off?.('close', onClose);proc.off?.('error', onError);- return buffered;+ if (bufferOutput) {+ proc.stdout?.off?.('data', onStdout);+ proc.stderr?.off?.('data', onStderr);+ }+ if (!buffered && output.length === 0) return null;+ return output.length ? { ...(buffered || { type: 'output' }), output } : buffered;};}diff --git a/server/services/videoGen/generateVideoHelpers.test.js b/server/services/videoGen/generateVideoHelpers.test.jsindex c2e4b43e0c..c7cfcc2e54 100644--- a/server/services/videoGen/generateVideoHelpers.test.js+++ b/server/services/videoGen/generateVideoHelpers.test.js@@ -635,11 +635,23 @@ describe('bufferChildExit', () => {it('holds a close emitted before the real listeners were attached', () => {const proc = new EventEmitter();- const take = bufferChildExit(proc);+ const take = bufferChildExit(proc, { bufferOutput: true });proc.emit('close', 3, null);expect(take()).toEqual({ type: 'close', code: 3, signal: null });});+ it('retains output emitted before the real readers were attached', () => {+ const proc = new EventEmitter();+ proc.stdout = new EventEmitter();+ proc.stderr = new EventEmitter();+ const take = bufferChildExit(proc, { bufferOutput: true });+ proc.stderr.emit('data', Buffer.from('RuntimeError: shader compilation failed\\n'));+ proc.emit('close', 1, null);+ const early = take();+ expect(early).toMatchObject({ type: 'close', code: 1, signal: null });+ expect(early.output).toEqual([{ stream: 'stderr', chunk: expect.any(Buffer) }]);+ });+it('absorbs an error that would otherwise throw out of the emitter', () => {const proc = new EventEmitter();const take = bufferChildExit(proc);diff --git a/server/services/videoGen/local.test.js b/server/services/videoGen/local.test.jsindex 9078c0bc05..a3995b5aad 100644--- a/server/services/videoGen/local.test.js+++ b/server/services/videoGen/local.test.js@@ -5080,10 +5080,10 @@ describe('generateVideo — Gemma prompt-encode watchdog relaunch', () => {return {proc,// Full wiring — the stdout reader goes on with the real terminal handler,- // and only there. The pre-handoff exit buffer subscribes to 'close'/'error'- // alone, so this stays false across the handoff window even though the- // child's exit can no longer be lost.- isWired: () => typeof onData['stdout:data'] === 'function',+ // and only there. The pre-handoff buffer's output listeners are marked+ // separately, so this stays false across the handoff window even though+ // the child's output and exit can no longer be lost.+ isWired: () => typeof onData['stdout:data'] === 'function' && !onData['stdout:data'].__earlyBuffer,stderr: (text) => onData['stderr:data']?.(Buffer.from(`${text}\n`)),close: async (code, signal) => {proc.exitCode = code;diff --git a/server/services/videoGen/spawnWatch.js b/server/services/videoGen/spawnWatch.jsindex 92c0faa064..40dbb50e1e 100644--- a/server/services/videoGen/spawnWatch.js+++ b/server/services/videoGen/spawnWatch.js@@ -540,9 +540,10 @@ export async function spawnAndWatchVideo({: null);const replayEarlyExit = async () => {if (!earlyExit) return;+ for (const { stream, chunk } of earlyExit.output || []) proc[stream].emit('data', chunk);console.log(`⚠️ video render child exited before it was wired [${jobId.slice(0, 8)}]`);if (earlyExit.type === 'error') handleChildError(earlyExit.error);- else await handleChildClose(earlyExit.code, earlyExit.signal);+ else if (earlyExit.type === 'close') await handleChildClose(earlyExit.code, earlyExit.signal);};return replayEarlyExit;};@@ -630,7 +631,7 @@ export async function spawnAndWatchVideo({// Catch the replacement's terminal event in the same tick the spawn// resolved — the handoff below yields to the event loop, and a child that// dies in that window would otherwise emit into the void.- const takeRetryEarlyExit = bufferChildExit(retryProc);+ const takeRetryEarlyExit = bufferChildExit(retryProc, { bufferOutput: true });if (canceledDuringRelaunch(cancelEpochAtClose, retryProc)) return false;// Both awaits finish BEFORE the shared active process starts pointing at the// replacement, and the statements that follow them are synchronous.@@ -770,7 +771,7 @@ export async function spawnAndWatchVideo({// forever, still holding the accelerator claim, and a lost 'error' is worse// — an EventEmitter with no 'error' listener THROWS and takes the server// with it.- takeEarlyExit = bufferChildExit(firstProc);+ takeEarlyExit = bufferChildExit(firstProc, { bufferOutput: true });videoJobState.activeProcess = firstProc;await heavyClaim.handoffTo?.(firstProc.pid);} catch (err) {