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 shot files rendered during a final render from being pruned (#11776)
[._.]/ Adam Eivy57074bda0860
diff --git a/server/services/musicVideo/render.js b/server/services/musicVideo/render.jsindex 97476ee4db..33e3f46fc7 100644--- a/server/services/musicVideo/render.js+++ b/server/services/musicVideo/render.js@@ -1035,6 +1035,7 @@ async function renderSeekedMode(projectId, project, handOff, renderer, options =// missing, then join by stream copy with the song laid under them once.async function renderFromShotSegments(projectId, project, handOff, options) {const { planShotSegments, renderMissingSegments, stitchSegments, pruneSegments } = await import('./shotSegments.js');+ const startedAtMs = Date.now();const plan = await planShotSegments(project);await ensureDir(PATHS.videos);await ensureDir(PATHS.videoThumbnails);@@ -1095,7 +1096,7 @@ async function renderFromShotSegments(projectId, project, handOff, options) {});finish('complete');// Older takes of each shot are dropped once the new cut is published.- const pruned = await pruneSegments(plan).catch(() => 0);+ const pruned = await pruneSegments(plan, { startedAtMs }).catch(() => 0);console.log(`✅ Music video rendered [${jobId.slice(0, 8)}]: ${filename} (${all.length - cached} of ${all.length} segments rendered${pruned ? `, ${pruned} old dropped` : ''})`);broadcastSse(job, { type: 'complete', result: { id: jobId, filename, thumbnail: thumb, path: `/data/videos/${filename}` } });}).catch(async (err) => {diff --git a/server/services/musicVideo/shotSegments.js b/server/services/musicVideo/shotSegments.jsindex e63159ca0a..5902df955e 100644--- a/server/services/musicVideo/shotSegments.js+++ b/server/services/musicVideo/shotSegments.js@@ -412,9 +412,11 @@ export async function stitchSegments(plan, outputPath, { signal, segments = [...* current take stays, so a look can be restored without rendering* (deleteFilmLook drops one); a look that isn't listed could never be found* again, so its files go. The rendered-so-far previews are replaced by their- * own builder.+ * own builder. A file written at or after `startedAtMs` (a shot rendered while+ * the final render ran) was made after this plan was cut, so the plan cannot+ * tell whether it is current and it stays.*/-export async function pruneSegments(plan) {+export async function pruneSegments(plan, { startedAtMs = Infinity } = {}) {const keep = new Set([...plan.segments, ...(plan.outro ? [plan.outro] : [])].flatMap((s) => [s.path, s.basePath]));// Only takes that play the video's look keep its other looks; a shot's own// look keeps just its current file, as before.@@ -429,6 +431,8 @@ export async function pruneSegments(plan) {const path = join(plan.dir, name);if (keep.has(path) || [...inFlight.keys()].some((p) => path.startsWith(p))) continue;if (name.endsWith('.partial.mp4') || name.startsWith(LOOKS_FILE) || name.startsWith('preview-')) continue;+ const info = await stat(path).catch(() => null);+ if (!info || info.mtimeMs >= startedAtMs) continue;await rm(path, { force: true }).then(() => { removed += 1; }, () => {});}return removed;diff --git a/server/services/musicVideo/shotSegments.test.js b/server/services/musicVideo/shotSegments.test.jsindex 6cbbd1ef4a..6488be0ade 100644--- a/server/services/musicVideo/shotSegments.test.js+++ b/server/services/musicVideo/shotSegments.test.js@@ -6,7 +6,7 @@*/import { describe, it, expect, vi, afterAll, afterEach, beforeAll } from 'vitest';import { execFileSync } from 'child_process';-import { existsSync, mkdirSync, rmSync, writeFileSync } from 'fs';+import { existsSync, mkdirSync, rmSync, utimesSync, writeFileSync } from 'fs';import { join } from 'path';import { cleanupTempDataRoots, lazyTempDataRoot, makePathsProxy } from '../../lib/mockPathsDataRoot.js';@@ -255,6 +255,24 @@ describe.skipIf(!hasFfmpeg)('shot segments', () => {}, 60000);});+describe('pruneSegments time floor', () => {+ it('keeps a file written after the render started and still removes older unplanned ones', async () => {+ fixture.project = project({ id: 'mv-segments-floor-test' });+ const plan = await planShotSegments(fixture.project);+ mkdirSync(plan.dir, { recursive: true });+ const older = join(plan.dir, 'older-take.mp4');+ const newer = join(plan.dir, 'newer-look.mp4');+ writeFileSync(older, 'x');+ writeFileSync(newer, 'x');+ const startedAtMs = Date.now();+ utimesSync(older, (startedAtMs - 5000) / 1000, (startedAtMs - 5000) / 1000);+ utimesSync(newer, (startedAtMs + 5000) / 1000, (startedAtMs + 5000) / 1000);+ await pruneSegments(plan, { startedAtMs });+ expect(existsSync(older)).toBe(false);+ expect(existsSync(newer)).toBe(true);+ });+});+describe('renderSegment after a cancel', () => {const deferred = () => { let release; const promise = new Promise((r) => { release = r; }); return { promise, release }; };