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(video): log reactor cleanup rm failures instead of swallowing them (#7799)
[._.]/ Adam Eivy9c24eb1195f6
diff --git a/server/services/videoGen/reactor.js b/server/services/videoGen/reactor.jsindex e74298d2af..1bdb57d697 100644--- a/server/services/videoGen/reactor.js+++ b/server/services/videoGen/reactor.js@@ -306,7 +306,10 @@ async function runReactorVideo(job, jobId, {throw new Error(`Reactor streamed ${result.frames ?? Math.round(result.seconds * 24)} frames but every sampled frame was blank`);}} finally {- await Promise.all(samples.map((name) => rm(join(PATHS.videoThumbnails, name), { force: true }).catch(() => {})));+ await Promise.all(samples.map((name) => {+ const p = join(PATHS.videoThumbnails, name);+ return rm(p, { force: true }).catch((err) => { console.log(`⚠️ Reactor cleanup: could not remove sample frame ${p} (${err.code})`); });+ }));}if (entry.aborted) return finalizeCanceled(job, jobId);// Durable publication owns the output from this point until it settles.@@ -324,9 +327,9 @@ async function runReactorVideo(job, jobId, {: '';finalizeJobFailure(job, jobId, null, entry.aborted ? 'Canceled' : `Reactor video generation failed: ${err?.message || 'unknown error'}${continuationHint}`, { force: true });} finally {- await rm(`${outputPath}.capture`, { recursive: true, force: true }).catch(() => {});- if (frame.fittedPath) await rm(frame.fittedPath, { force: true }).catch(() => {});- if (entry.aborted) await rm(outputPath, { force: true }).catch(() => {});+ await rm(`${outputPath}.capture`, { recursive: true, force: true }).catch((err) => { console.log(`⚠️ Reactor cleanup: could not remove capture dir ${outputPath}.capture (${err.code})`); });+ if (frame.fittedPath) await rm(frame.fittedPath, { force: true }).catch((err) => { console.log(`⚠️ Reactor cleanup: could not remove fitted frame ${frame.fittedPath} (${err.code})`); });+ if (entry.aborted) await rm(outputPath, { force: true }).catch((err) => { console.log(`⚠️ Reactor cleanup: could not remove aborted output ${outputPath} (${err.code})`); });activeRequests.delete(jobId);activeJobs.delete(jobId);}diff --git a/server/services/videoGen/reactor.test.js b/server/services/videoGen/reactor.test.jsindex 9329c1e534..8a82702b0c 100644--- a/server/services/videoGen/reactor.test.js+++ b/server/services/videoGen/reactor.test.js@@ -5,7 +5,7 @@ import { join } from 'path';import { tmpdir } from 'os';const root = join(tmpdir(), `reactor-test-${process.pid}`);-const mocks = vi.hoisted(() => ({ spawn: vi.fn(), finalize: vi.fn(), settings: vi.fn(), samples: vi.fn(), runtime: vi.fn(), optimize: vi.fn(), thumbnail: vi.fn(), history: vi.fn() }));+const mocks = vi.hoisted(() => ({ spawn: vi.fn(), finalize: vi.fn(), settings: vi.fn(), samples: vi.fn(), runtime: vi.fn(), optimize: vi.fn(), thumbnail: vi.fn(), history: vi.fn(), rm: vi.fn() }));vi.mock('../../lib/childProcess.js', async (importOriginal) => ({ ...await importOriginal(), spawn: mocks.spawn }));vi.mock('./reactorRuntime.js', () => ({ ensureReactorRuntime: mocks.runtime }));vi.mock('../../lib/ffmpeg.js', () => ({ extractEvaluationFrames: mocks.samples, optimizeForStreaming: mocks.optimize, generateThumbnail: mocks.thumbnail }));@@ -21,6 +21,12 @@ vi.mock('../../lib/fileUtils.js', async () => {const actual = await vi.importActual('../../lib/fileUtils.js');return { ...actual, PATHS: { ...actual.PATHS, videos: join(root, 'videos'), videoThumbnails: root, data: root }, ensureDir: (dir) => mkdir(dir, { recursive: true }) };});+// fs/promises: real by default; mocks.rm allows a test to intercept rm without+// affecting mkdir/writeFile/stat/readFile which are used directly in tests.+vi.mock('fs/promises', async (importOriginal) => {+ const actual = await importOriginal();+ return { ...actual, rm: (...args) => mocks.rm(...args) };+});const reactor = await import('./reactor.js');const { videoGenEvents } = await import('./events.js');const settings = { videoGen: { reactor: { apiKey: 'example-key' } } };@@ -28,6 +34,9 @@ let child;let input;beforeEach(async () => {vi.clearAllMocks();+ // Default rm to the real implementation so existing tests use real FS operations.+ const { rm: realRm } = await vi.importActual('fs/promises');+ mocks.rm.mockImplementation(realRm);await mkdir(root, { recursive: true });await writeFile(join(root, 'python'), 'placeholder');vi.stubEnv('REACTOR_PYTHON_PATH', join(root, 'python'));@@ -360,4 +369,39 @@ describe('Reactor SDK adapter', () => {expect(mocks.finalize).not.toHaveBeenCalled();});+ // Acceptance criteria for #7799: a cleanup rm that rejects must be logged with+ // the path and error code; the job's success verdict must be unchanged.+ it('logs a cleanup rm failure and still finalizes the job successfully', async () => {+ const sourceImagePath = join(root, 'portrait.png');+ const sharp = (await import('sharp')).default;+ await sharp({ create: { width: 900, height: 1600, channels: 3, background: '#204080' } }).png().toFile(sourceImagePath);+ const { rm: realRm } = await vi.importActual('fs/promises');+ const eperm = Object.assign(new Error('EPERM: operation not permitted'), { code: 'EPERM' });+ // Intercept only the fitted-frame removal; let all other rm calls through.+ mocks.rm.mockImplementation(async (path, opts) => {+ if (typeof path === 'string' && path.endsWith('.start.png')) throw eperm;+ return realRm(path, opts);+ });+ const logged = [];+ const spy = vi.spyOn(console, 'log').mockImplementation((...args) => { logged.push(args.join(' ')); });+ const completed = vi.fn();+ const failed = vi.fn();+ videoGenEvents.on('completed', completed);+ videoGenEvents.on('failed', failed);+ const job = await started({ sourceImagePath });+ await writeFile(input.outputPath, 'example-video');+ child.stdout.emit('data', Buffer.from('{\"type\":\"complete\",\"clipId\":\"clip-example\",\"seconds\":6}\n'));+ child.emit('close', 0);+ // Job must finalize (success verdict unchanged even though cleanup rm failed).+ await vi.waitFor(() => expect(mocks.finalize).toHaveBeenCalledWith(+ expect.objectContaining({ jobId: job.jobId }),+ ));+ expect(failed).not.toHaveBeenCalled();+ // Cleanup failure must have been logged with the path and error code.+ const warning = logged.find((l) => l.includes('⚠️') && l.includes('EPERM'));+ expect(warning, 'expected a ⚠️ log naming EPERM for the failed rm').toBeTruthy();+ expect(warning).toContain('.start.png');+ spy.mockRestore();+ });+});