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: preserve finals referenced by canonical video URLs

[._.]/ Adam Eivyecac237d7f3f
diff --git a/server/services/musicVideo/renderCleanup.js b/server/services/musicVideo/renderCleanup.js
index 24bad0739e..15b9d964b0 100644
--- a/server/services/musicVideo/renderCleanup.js
+++ b/server/services/musicVideo/renderCleanup.js
@@ -31,8 +31,14 @@ export function assertRenderCleanupIdle(projectId) {
}
// Include legacy and nested references (takes, proof, kits, clone provenance).
-const references = (value, ids) => typeof value === 'string' ? ids.has(value)
- : value && typeof value === 'object' && Object.values(value).some(child => references(child, ids));
+const references = (value, ids) => {
+ if (typeof value === 'string') {
+ if (ids.has(value)) return true;
+ const path = /^https?:\/\//.test(value) && URL.canParse(value) ? new URL(value).pathname : value.split(/[?#]/, 1)[0];
+ return ids.has(path);
+ }
+ return value && typeof value === 'object' && Object.values(value).some(child => references(child, ids));
+};
const size = async path => path ? stat(path).then(info => info.size, error => {
if (error.code === 'ENOENT') return 0;
throw error;
@@ -66,7 +72,8 @@ async function finalInventory(projectId, history, pending = []) {
for (const entry of retirementEntries(history, pending)) {
// Only the full-render pipeline owns this tag. Source clips use musicVideo.projectId.
if (entry.musicVideoProjectId !== projectId || !['music-video', 'music-video-code', 'music-video-document', 'music-video-eidoverse'].includes(entry.modelId) || entry.id === project.renderHistoryId) continue;
- const ids = new Set([entry.id, entry.filename]);
+ const ids = new Set([entry.id, entry.filename, safeUnder(PATHS.videos, entry.filename),
+ `/data/videos/${entry.filename}`, `/data/videos/${encodeURIComponent(entry.filename)}`]);
const referenced = owners.some(owner => references(owner, ids))
|| history.some(other => other.id !== entry.id && references(other, ids));
const reason = !hasCurrent ? 'No completed replacement' : referenced ? 'Referenced by saved media or production records' : null;
diff --git a/server/services/musicVideo/renderCleanup.test.js b/server/services/musicVideo/renderCleanup.test.js
index 0d08cde0c8..c621ebe7a2 100644
--- a/server/services/musicVideo/renderCleanup.test.js
+++ b/server/services/musicVideo/renderCleanup.test.js
@@ -74,6 +74,17 @@ describe('derived render retention', () => {
for (const id of [...ids.filter(id => id !== 'old'), 'source', 'other']) expect(existsSync(join(PATHS.videos, `${id}.mp4`))).toBe(true);
});
+ it('preserves canonical render URLs during automatic and explicit cleanup', async () => {
+ await seed([entry('current'), entry('path'), entry('url'), entry('unused')]);
+ state.others = [{ composition: { media: '/data/videos/path.mp4' } }];
+ state.collections = [{ items: [{ url: 'https://example.test/data/videos/url.mp4?download=1' }] }];
+ expect(await cleanupSupersededFinals('example-project', { replacementId: 'current' })).toBe(1);
+ const result = await cleanupRenders('example-project');
+ expect(result.finals.map(item => [item.id, !!item.reason])).toEqual([['path', true], ['url', true]]);
+ for (const id of ['current', 'path', 'url']) expect(existsSync(join(PATHS.videos, `${id}.mp4`))).toBe(true);
+ expect(existsSync(join(PATHS.videos, 'unused.mp4'))).toBe(false);
+ });
+
it('keeps history and bytes retryable when index removal fails, then settles them on retry', async () => {
await seed([entry('current'), entry('old')]);
unindexVideo.mockRejectedValueOnce(new Error('Index temporarily unavailable'));