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 cleanup errors and current render references

[._.]/ Adam Eivyfdec577031ab
diff --git a/client/src/components/musicVideo/stages/CleanupStage.jsx b/client/src/components/musicVideo/stages/CleanupStage.jsx
index 99a8dbf801..cbd50cf165 100644
--- a/client/src/components/musicVideo/stages/CleanupStage.jsx
+++ b/client/src/components/musicVideo/stages/CleanupStage.jsx
@@ -10,20 +10,28 @@ const bytes = files => files.reduce((sum, file) => sum + file.bytes, 0);
export default function CleanupStage({ board }) {
const { project } = board;
const [inventory, setInventory] = useState(null);
- const [error, setError] = useState(null);
+ const [loadError, setLoadError] = useState(null);
+ const [mutationError, setMutationError] = useState(null);
+ const error = mutationError || loadError;
const [busy, setBusy] = useState(false);
const generation = useRef(0);
+ const identityGeneration = useRef(0);
const cleaning = useRef(false);
const refresh = useRef(null);
refresh.current = () => {
const ticket = ++generation.current;
getMusicVideoRenderCleanup(project.id, { silent: true }).then(next => {
- if (ticket === generation.current) { setInventory(next); setError(null); }
- }).catch(err => { if (ticket === generation.current) setError(err.message); });
+ if (ticket === generation.current) { setInventory(next); setLoadError(null); }
+ }).catch(err => { if (ticket === generation.current) setLoadError(err.message); });
};
+ useEffect(() => {
+ identityGeneration.current += 1;
+ setMutationError(null);
+ return () => { identityGeneration.current += 1; };
+ }, [project.id]);
useEffect(() => {
setInventory(null);
- setError(null);
+ setLoadError(null);
refresh.current();
const onChange = event => { if (event.projectId === project.id) refresh.current(); };
const onConnect = () => refresh.current();
@@ -42,10 +50,12 @@ export default function CleanupStage({ board }) {
if (cleaning.current) return;
cleaning.current = true;
setBusy(true);
+ setMutationError(null);
+ const identity = identityGeneration.current;
const ticket = ++generation.current;
cleanupMusicVideoRenders(project.id, { unusedLooks }, { silent: true }).then(next => {
- if (ticket === generation.current) { setInventory(next); setError(null); }
- }).catch(err => { if (ticket === generation.current) setError(err.message); })
+ if (ticket === generation.current) { setInventory(next); setLoadError(null); }
+ }).catch(err => { if (identity === identityGeneration.current) setMutationError(err.message); })
.finally(() => { cleaning.current = false; setBusy(false); });
};
const finals = inventory?.finals || [];
diff --git a/client/src/components/musicVideo/stages/CleanupStage.test.jsx b/client/src/components/musicVideo/stages/CleanupStage.test.jsx
index 67c5a68e9f..d36046fa3e 100644
--- a/client/src/components/musicVideo/stages/CleanupStage.test.jsx
+++ b/client/src/components/musicVideo/stages/CleanupStage.test.jsx
@@ -1,5 +1,6 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
-import { fireEvent, render, screen, waitFor } from '@testing-library/react';
+import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';
+import socket from '../../../services/socket';
import CleanupStage from './CleanupStage.jsx';
import { cleanupMusicVideoRenders, getMusicVideoRenderCleanup } from '../../../services/apiMusicVideo.js';
@@ -37,6 +38,30 @@ describe('production cleanup', () => {
expect(screen.getByText('Superseded — safe to remove')).toBeInTheDocument();
});
+ it('keeps mutation failures visible when cleanup socket events refresh the inventory', async () => {
+ let rejectCleanup;
+ cleanupMusicVideoRenders.mockReturnValueOnce(new Promise((resolve, reject) => { rejectCleanup = reject; }));
+ render(<CleanupStage board={{ project: { id: 'example-project' } }} />);
+ fireEvent.click(await screen.findByRole('button', { name: 'Remove superseded renders' }));
+ const onCleanup = socket.on.mock.calls.find(([event]) => event === 'music-video:render-cleanup')[1];
+ await act(async () => { onCleanup({ projectId: 'example-project' }); });
+ await act(async () => { rejectCleanup(new Error('Segment removal failed')); });
+ expect(screen.getByRole('alert')).toHaveTextContent('Segment removal failed');
+ await act(async () => { onCleanup({ projectId: 'example-project' }); });
+ expect(screen.getByRole('alert')).toHaveTextContent('Segment removal failed');
+ });
+
+ it('drops a cleanup failure after switching to another project', async () => {
+ let rejectCleanup;
+ cleanupMusicVideoRenders.mockReturnValueOnce(new Promise((resolve, reject) => { rejectCleanup = reject; }));
+ const { rerender } = render(<CleanupStage board={{ project: { id: 'old-project' } }} />);
+ fireEvent.click(await screen.findByRole('button', { name: 'Remove superseded renders' }));
+ rerender(<CleanupStage board={{ project: { id: 'new-project' } }} />);
+ await screen.findByText('Superseded — safe to remove');
+ await act(async () => { rejectCleanup(new Error('Old project failure')); });
+ expect(screen.queryByRole('alert')).not.toBeInTheDocument();
+ });
+
it('drops a previous project inventory response after switching projects', async () => {
let resolveOld;
getMusicVideoRenderCleanup.mockReturnValueOnce(new Promise(resolve => { resolveOld = resolve; }));
diff --git a/server/services/musicVideo/render.js b/server/services/musicVideo/render.js
index 4aed50e903..eb4fbe54f5 100644
--- a/server/services/musicVideo/render.js
+++ b/server/services/musicVideo/render.js
@@ -1099,7 +1099,7 @@ async function renderFromShotSegments(projectId, project, handOff, options) {
});
await retireOldFinals(projectId, jobId);
// Older takes of each shot are dropped once the new cut is published.
- const pruned = await pruneSegments(plan, { startedAtMs }).catch(err => { console.warn(`⚠️ Music-video segment cleanup failed: ${err.message}`); return 0; });
+ const pruned = await pruneSegments(plan, { startedAtMs, current: true }).catch(err => { console.warn(`⚠️ Music-video segment cleanup failed: ${err.message}`); return 0; });
finish('complete');
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}` } });
diff --git a/server/services/musicVideo/renderCleanup.js b/server/services/musicVideo/renderCleanup.js
index fa8353df54..cf48837a48 100644
--- a/server/services/musicVideo/renderCleanup.js
+++ b/server/services/musicVideo/renderCleanup.js
@@ -36,7 +36,12 @@ async function finalInventory(projectId, history) {
const [{ listCollections }, timeline, director] = await Promise.all([
import('../mediaCollections.js'), import('../videoTimeline/local.js'), import('../creativeDirector/local.js'),
]);
- const owners = (await Promise.all([listProjects(), listCollections(), timeline.listProjects(), director.listProjects()])).flat();
+ // Completed run receipts describe history, rather than a live media dependency.
+ const projects = (await listProjects()).map(({ productionRuns, autonomousRun, ...record }) => ({
+ ...record, productionRuns: productionRuns?.filter(run => run.status !== 'completed'),
+ autonomousRun: autonomousRun?.status === 'completed' ? null : autonomousRun,
+ }));
+ const owners = [projects, ...(await Promise.all([listCollections(), timeline.listProjects(), director.listProjects()]))].flat();
const current = history.find(entry => entry.id === project.renderHistoryId);
const hasCurrent = current && await size(safeUnder(PATHS.videos, current.filename)) > 0;
const finals = [];
diff --git a/server/services/musicVideo/renderCleanup.test.js b/server/services/musicVideo/renderCleanup.test.js
index 2321c1fae8..36fe6333b7 100644
--- a/server/services/musicVideo/renderCleanup.test.js
+++ b/server/services/musicVideo/renderCleanup.test.js
@@ -50,6 +50,8 @@ describe('derived render retention', () => {
const ids = ['current', 'old', 'take', 'clone', 'collection', 'timeline', 'director', 'derived'];
await seed([...ids.map(id => entry(id)), entry('source', { modelId: 'video-model' }), entry('other', { musicVideoProjectId: 'another-project' }), entry('child', { sourceId: 'derived', musicVideoProjectId: null })]);
state.project.scenes = [{ takes: [{ assetId: 'take' }] }];
+ state.project.productionRuns = [{ status: 'completed', finalRender: { jobId: 'old' } }];
+ state.project.autonomousRun = { status: 'completed', output: { renderJobId: 'old', finalReviewedJobId: 'old' } };
state.others = [{ revision: { sourceRenderId: 'clone' } }];
state.collections = [{ items: [{ ref: 'collection' }] }];
state.timelines = [{ clips: [{ videoHistoryId: 'timeline' }] }];
diff --git a/server/services/musicVideo/shotSegments.js b/server/services/musicVideo/shotSegments.js
index decbb39801..e832801375 100644
--- a/server/services/musicVideo/shotSegments.js
+++ b/server/services/musicVideo/shotSegments.js
@@ -446,7 +446,14 @@ async function staleSegmentFiles(plan, { startedAtMs = Infinity, unusedLooks = f
return stale;
}
-export async function pruneSegments(plan, { reserved = false, ...options } = {}) {
+export async function pruneSegments(plan, { reserved = false, current = false, ...options } = {}) {
+ if (current) {
+ const { withProjectMediaMutation } = await import('./projects.js');
+ return withProjectMediaMutation(async () => {
+ const { plan: latest } = await planForLooks(plan.project.id);
+ return latest && !latest.error ? pruneSegments(latest, { reserved, ...options }) : 0;
+ });
+ }
const prune = async () => {
assertSegmentCleanupIdle(plan.project.id);
const stale = await staleSegmentFiles(plan, options);
diff --git a/server/services/musicVideo/shotSegments.test.js b/server/services/musicVideo/shotSegments.test.js
index 0a0d582691..e643cfb5e3 100644
--- a/server/services/musicVideo/shotSegments.test.js
+++ b/server/services/musicVideo/shotSegments.test.js
@@ -215,6 +215,23 @@ describe.skipIf(!hasFfmpeg)('shot segments', () => {
expect(existsSync(after.segments[2].path)).toBe(true);
}, 60000);
+ it('keeps an older cached take selected after a final render snapshot', async () => {
+ fixture.project = project({ id: 'mv-current-cache' });
+ const originalClips = fixture.clips;
+ try {
+ const original = await planShotSegments(fixture.project);
+ await renderMissingSegments(original, { concurrency: 2 });
+ fixture.clips = originalClips.map(clip => clip.sceneId === 'c' ? { ...clip, inSec: 0.1, outSec: 1.1 } : clip);
+ const rendered = await planShotSegments(fixture.project);
+ await renderMissingSegments(rendered, { concurrency: 2 });
+ // The director switches back to a previously cached take as finalization runs.
+ fixture.clips = originalClips;
+ await pruneSegments(rendered, { current: true });
+ expect(existsSync(original.segments[2].path)).toBe(true);
+ expect(existsSync(rendered.segments[2].path)).toBe(false);
+ } finally { fixture.clips = originalClips; }
+ });
+
it('retires only a successfully replaced shot while another edited shot still needs its replacement', async () => {
fixture.project = project({ id: 'mv-shot-replacement' });
const originalClips = fixture.clips;