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
Resume re-renders a final revision that already ended; a hand-off parks the run
Claude321574755cf0
diff --git a/docs/features/music-video-autonomous.md b/docs/features/music-video-autonomous.mdindex 07c4acea35..ed8f5a68fb 100644--- a/docs/features/music-video-autonomous.md+++ b/docs/features/music-video-autonomous.md@@ -104,7 +104,7 @@ Choose **Who reviews each step → Orchestrator** in the start drawer to let a m| Art direction | **Produce** | Reads the cast, environments, visual and motion guides (and the guide sheet when it is an image and the model can see), approves or rewrites fields || Lyric timing | **Produce** | Verifies the aligned timings when every line carries bounded word timings, alignment ran without error and the recognizer heard at least half of the words; otherwise leaves them for a director || Storyboard | **Produce** | Anchors shots to the lyric lines they overlap, fills blank fields, approves or files change requests that re-plan the named shots, then resolves them |-| Final video | after the final render | Looks at 24 frames sampled across the film (when the model can see). A `revise` with timecoded issues sends those sections back while revisions remain: a code or document film is re-authored with the issues as change requests on the film; footage gets an auto-review over the scenes the issues fall in, judged by the orchestrator and limited to the generations production left (not run when a dollar budget is set, which only production can enforce). The film is rendered again and reviewed again (`stages.produce.step: 'final-revision'`, `output.finalAutoReviewId`). Stop, Cancel and Resume carry through to that auto-review |+| Final video | after the final render | Looks at 24 frames sampled across the film (when the model can see). A `revise` with timecoded issues sends those sections back while revisions remain: a code or document film is re-authored with the issues as change requests on the film; footage gets an auto-review over the scenes the issues fall in, judged by the orchestrator and limited to the generations production left (not run when a dollar budget is set, which only production can enforce). The film is rendered again and reviewed again (`stages.produce.step: 'final-revision'`, `output.finalAutoReviewId`). Stop, Cancel and Resume carry through to that auto-review; one that hands off to a director (or fails) parks the run with its reason (`FINAL_REVISION_NEEDS_HUMAN`), and Resume, once it is finished, renders and reviews the film again |Production's plate and draft reviews use the orchestrator too. Each decision lands in `run.orchestration.reviews` (`checkpoint`, `verdict` of `approve`/`revise`/`retake`/`noted`, `score`, `notes`, `changes`, `issues`, `route`), which the run panel shows as a decision log. When the revision limit is reached the latest version is accepted and the note says so. Each revision is stored with its log entry (`output.lyricsForReview`, `output.styleDraft`), so a Retry after a failed review judges the latest revision rather than the first draft. A storyboard re-plan that fails fails the stage (`ORCHESTRATOR_REVISION_FAILED`) instead of approving the unchanged shot; Retry asks the orchestrator again. A readiness problem the orchestrator cannot fix still parks the run for a human, with the problem named. The orchestrator never publishes.diff --git a/server/services/musicVideo/autonomousService.js b/server/services/musicVideo/autonomousService.jsindex 016b89ea40..12c6dff5ca 100644--- a/server/services/musicVideo/autonomousService.js+++ b/server/services/musicVideo/autonomousService.js@@ -1245,14 +1245,22 @@ export async function resumeAutonomousVideo(projectId, edits = {}, { autoApprove});if (retakenTrackId) await unlinkRunTrack(projectId, out.run.id, retakenTrackId);if (out.run.stage === 'produce' && out.run.output.finalAutoReviewId) {- // The orchestrator's footage revision picks up where it stopped; one that- // already ended gives way to the re-render below.- const resumed = await deps.resumeAutoReview(projectId, out.run.output.finalAutoReviewId).then(() => true, () => false);- if (resumed) {+ // The orchestrator's footage revision picks up where it stopped. One that+ // already ended (or a director finished) leaves a revised film to render+ // and review again; any other failure is the director's to see.+ const failure = await deps.resumeAutoReview(projectId, out.run.output.finalAutoReviewId).then(() => null, (err) => err);+ if (!failure) {const { project: next, run } = await patchRun(projectId, (r) => stagePatch(r, 'produce', { status: 'running', step: FINAL_REVISION_STEP }));return { project: presentProjectAutonomousRun(next), run: presentAutonomousRun(run) };}- await patchRun(projectId, () => ({ output: { finalAutoReviewId: null } }));+ if (!['AUTO_REVIEW_CLOSED', 'NOT_FOUND'].includes(failure.code)) {+ const parked = await park(projectId, 'needs-human', { error: trimTo(`The final revision could not resume: ${failure.message}`, 500), errorCode: failure.code || null });+ return { project: parked.project, run: presentAutonomousRun(parked.run) };+ }+ const { run } = await patchRun(projectId, () => ({ output: { finalAutoReviewId: null } }));+ await startFinalRender(projectId, run);+ const latest = await getProject(projectId);+ return { project: presentProjectAutonomousRun(latest), run: presentAutonomousRun(projectAutonomousRun(latest)) };}if (out.run.stage === 'produce' && (out.run.output.renderJobId || out.run.output.productionDone)) {// Production (or the code render) already finished; only the final render is left.@@ -1444,15 +1452,23 @@ async function startFinalRender(projectId, run) {}/**- * The orchestrator's footage revision ended. Whatever it decided, the film is- * rendered again for the next final review; a run it left resumable (stopped- * or limit-reached) is closed first so it does not hold the revision slot.+ * The orchestrator's footage revision ended. One that handed off to a human+ * (`needs-human`) or failed leaves its revision open, so the run parks with the+ * reason and keeps the revision's id: Resume, once the director has finished+ * it, renders and reviews the film again. Otherwise the film is rendered again+ * for the next final review; a run it left resumable (stopped or+ * limit-reached) is closed first so it does not hold the revision slot.*/async function onAutoReviewEvent({ projectId, runId, run: review }) {if (!projectId || !runId || !review || review.status === 'running') return;const project = await getProject(projectId).catch(() => null);const run = runAwaitingRender(project);if (!run || run.output.finalAutoReviewId !== runId || run.stages.produce?.step !== FINAL_REVISION_STEP) return;+ if (['needs-human', 'failed'].includes(review.status)) {+ const reason = [review.stopReason, review.error].find((v) => typeof v === 'string' && v.trim()) || `the revision ${review.status === 'failed' ? 'failed' : 'needs a director'}`;+ await park(projectId, 'needs-human', { error: trimTo(`The revision of the final video was left for a director: ${reason}`, 500), errorCode: 'FINAL_REVISION_NEEDS_HUMAN' });+ return;+ }await patchRun(projectId, () => ({ output: { finalAutoReviewId: null } }));if (['stopped', 'limit-reached'].includes(review.status)) {await deps.cancelAutoReview(projectId, runId).catch((err) => console.warn(`⚠️ Autonomous music video ${short(run.id)} could not close its revision: ${trimTo(err.message, 200)}`));diff --git a/server/services/musicVideo/autonomousService.test.js b/server/services/musicVideo/autonomousService.test.jsindex 59ed3c1d36..11abc30bce 100644--- a/server/services/musicVideo/autonomousService.test.js+++ b/server/services/musicVideo/autonomousService.test.js@@ -1202,34 +1202,105 @@ describe('orchestrated mode (brief.orchestrator)', () => {expect(doubles.finalReviewFrames.mock.calls.map(([jobId]) => jobId)).toEqual(['render-1', 'render-2']);});- it('sends flagged footage back through an auto-review it judges, within the generations production left, then stops at the limit', async () => {- doubles.startAutoReview = stub('auto-review', async () => ({ run: { id: 'mvar-fix' } }));- service.__setAutonomousDepsForTests(doubles);- doubles.analyzeSong.mockImplementation(async () => {- Object.assign(store.get('mv-auto'), { scenes: [{ sceneId: 'a', startSec: 0, endSec: 10 }, { sceneId: 'b', startSec: 10, endSec: 20 }] });+ describe('final-video revision of footage', () => {+ const PRODUCTION = { id: 'mvpr-1', limits: { maxGenerations: 40, spendCapUsd: null }, usage: { generations: 10 } };+ // Runs a footage film to its first final review, which flags 0:04 (and later 0:12).+ const reachFinalReview = async (production = PRODUCTION) => {+ doubles.startAutoReview = stub('auto-review', async () => ({ run: { id: 'mvar-fix' } }));+ for (const name of ['stopAutoReview', 'cancelAutoReview', 'resumeAutoReview']) doubles[name] = stub(name, async () => ({}));+ service.__setAutonomousDepsForTests(doubles);+ doubles.analyzeSong.mockImplementation(async () => {+ Object.assign(store.get('mv-auto'), { scenes: [{ sceneId: 'a', startSec: 0, endSec: 10 }, { sceneId: 'b', startSec: 10, endSec: 20 }] });+ });+ answers.final = [+ { verdict: 'revise', notes: 'The opening stutters.', issues: [{ atSec: 4, text: 'Frozen frame' }] },+ { verdict: 'revise', notes: 'Still soft.', issues: [{ atSec: 12, text: 'Blurry' }] },+ ];+ await service.startAutonomousVideo({ prompt: 'p', tools: ['image:local'], limits: { maxReviewAttempts: 1 }, orchestrator: ORCHESTRATOR }, { autoApproveAuthorized: true });+ await vi.waitFor(() => expect(runOf()?.output.productionRunId).toBe('mvpr-1'));+ store.get('mv-auto').productionRuns = [production];+ await service.__testing.onProductionEvent({ projectId: 'mv-auto', runId: 'mvpr-1', run: { status: 'completed' } });+ // A finished render is the project's latest, as the render service records it.+ store.get('mv-auto').renderHistoryId = 'render-1';+ await service.__testing.onRenderEvent({ projectId: 'mv-auto', jobId: 'render-1', status: 'completed' });+ };+ const rendersAgain = async () => {+ doubles.renderVideo.mockResolvedValueOnce({ jobId: 'render-2' });+ doubles.activeRenderJobId.mockResolvedValue('render-2');+ };++ it('sends flagged footage back through an auto-review it judges, within the generations production left, then stops at the limit', async () => {+ await reachFinalReview();+ await vi.waitFor(() => expect(runOf().output.finalAutoReviewId).toBe('mvar-fix'));+ expect(doubles.startAutoReview).toHaveBeenCalledWith('mv-auto', { startSec: 0, endSec: 10, limits: { maxAttempts: 2, maxGenerations: 30 },+ reviewer: { providerId: 'orch', model: 'judge' } });+ expect(runOf()).toMatchObject({ status: 'running', stages: { produce: { step: 'final-revision' } } });++ await rendersAgain();+ musicVideoEvents.emit('auto-review', { projectId: 'mv-auto', runId: 'mvar-fix', run: { id: 'mvar-fix', status: 'passed' } });+ await vi.waitFor(() => expect(runOf().output.renderJobId).toBe('render-2'));+ await service.__testing.onRenderEvent({ projectId: 'mv-auto', jobId: 'render-2', status: 'completed' });+ await settled('completed');+ expect(doubles.startAutoReview).toHaveBeenCalledOnce();+ expect(reviews().slice(-2)).toEqual(['final:revise', 'final:noted']);+ expect(runOf().orchestration.reviews.at(-1).notes).toMatch(/Revision limit reached/);});- answers.final = [- { verdict: 'revise', notes: 'The opening stutters.', issues: [{ atSec: 4, text: 'Frozen frame' }] },- { verdict: 'revise', notes: 'Still soft.', issues: [{ atSec: 12, text: 'Blurry' }] },- ];- await service.startAutonomousVideo({ prompt: 'p', tools: ['image:local'], limits: { maxReviewAttempts: 1 }, orchestrator: ORCHESTRATOR }, { autoApproveAuthorized: true });- await vi.waitFor(() => expect(runOf()?.output.productionRunId).toBe('mvpr-1'));- store.get('mv-auto').productionRuns = [{ id: 'mvpr-1', limits: { maxGenerations: 40, spendCapUsd: null }, usage: { generations: 10 } }];- await service.__testing.onProductionEvent({ projectId: 'mv-auto', runId: 'mvpr-1', run: { status: 'completed' } });- await service.__testing.onRenderEvent({ projectId: 'mv-auto', jobId: 'render-1', status: 'completed' });- await vi.waitFor(() => expect(runOf().output.finalAutoReviewId).toBe('mvar-fix'));- expect(doubles.startAutoReview).toHaveBeenCalledWith('mv-auto', { startSec: 0, endSec: 10, limits: { maxAttempts: 2, maxGenerations: 30 },- reviewer: { providerId: 'orch', model: 'judge' } });- expect(runOf()).toMatchObject({ status: 'running', stages: { produce: { step: 'final-revision' } } });- doubles.renderVideo.mockResolvedValueOnce({ jobId: 'render-2' });- doubles.activeRenderJobId.mockResolvedValue('render-2');- musicVideoEvents.emit('auto-review', { projectId: 'mv-auto', runId: 'mvar-fix', run: { id: 'mvar-fix', status: 'passed' } });- await vi.waitFor(() => expect(runOf().output.renderJobId).toBe('render-2'));- await service.__testing.onRenderEvent({ projectId: 'mv-auto', jobId: 'render-2', status: 'completed' });- await settled('completed');- expect(doubles.startAutoReview).toHaveBeenCalledOnce();- expect(reviews().slice(-2)).toEqual(['final:revise', 'final:noted']);- expect(runOf().orchestration.reviews.at(-1).notes).toMatch(/Revision limit reached/);+ it.each([+ ['a dollar budget is set', { ...PRODUCTION, limits: { maxGenerations: 40, spendCapUsd: 5 } }, /dollar budget/],+ ['production spent its generations', { ...PRODUCTION, usage: { generations: 40 } }, /spent its generations/],+ ])('keeps the film without a revision when %s', async (_, production, why) => {+ await reachFinalReview(production);+ await settled('completed');+ expect(doubles.startAutoReview).not.toHaveBeenCalled();+ expect(runOf().orchestration.reviews.at(-1)).toMatchObject({ checkpoint: 'final', verdict: 'noted', notes: expect.stringMatching(why) });+ });++ it('carries Stop, Resume and Cancel through to the revision, and re-renders when Resume finds it already ended', async () => {+ await reachFinalReview();+ await vi.waitFor(() => expect(runOf().output.finalAutoReviewId).toBe('mvar-fix'));+ await service.stopAutonomousVideo('mv-auto');+ expect(doubles.stopAutoReview).toHaveBeenCalledWith('mv-auto', 'mvar-fix');+ await service.resumeAutonomousVideo('mv-auto');+ expect(doubles.resumeAutoReview).toHaveBeenCalledWith('mv-auto', 'mvar-fix');+ expect(runOf()).toMatchObject({ status: 'running', stages: { produce: { step: 'final-revision' } } });++ // The revision ends while the run is stopped (its event is ignored); Resume renders the revised film.+ await service.stopAutonomousVideo('mv-auto');+ doubles.resumeAutoReview.mockRejectedValueOnce(Object.assign(new Error('This run is already canceled'), { code: 'AUTO_REVIEW_CLOSED' }));+ await rendersAgain();+ await service.resumeAutonomousVideo('mv-auto');+ expect(runOf()).toMatchObject({ status: 'running', output: { renderJobId: 'render-2', finalAutoReviewId: null } });++ await service.cancelAutonomousVideo('mv-auto');+ expect(doubles.cancelAutoReview).not.toHaveBeenCalled();+ });++ it('parks for a director when Resume cannot reach the revision for another reason', async () => {+ await reachFinalReview();+ await vi.waitFor(() => expect(runOf().output.finalAutoReviewId).toBe('mvar-fix'));+ await service.stopAutonomousVideo('mv-auto');+ doubles.resumeAutoReview.mockRejectedValueOnce(Object.assign(new Error('database unavailable'), { code: 'DB_DOWN' }));+ await service.resumeAutonomousVideo('mv-auto');+ expect(runOf()).toMatchObject({ status: 'needs-human', errorCode: 'DB_DOWN', error: expect.stringContaining('database unavailable'), output: { finalAutoReviewId: 'mvar-fix' } });+ expect(doubles.renderVideo).toHaveBeenCalledOnce();++ await service.cancelAutonomousVideo('mv-auto');+ expect(doubles.cancelAutoReview).toHaveBeenCalledWith('mv-auto', 'mvar-fix');+ });++ it('parks with the reason when the revision hands off to a human, and renders again once the director resumes', async () => {+ await reachFinalReview();+ await vi.waitFor(() => expect(runOf().output.finalAutoReviewId).toBe('mvar-fix'));+ await service.__testing.onAutoReviewEvent({ projectId: 'mv-auto', runId: 'mvar-fix',+ run: { id: 'mvar-fix', status: 'needs-human', stopReason: 'The clip for scene a cannot be generated automatically' } });+ expect(runOf()).toMatchObject({ status: 'needs-human', errorCode: 'FINAL_REVISION_NEEDS_HUMAN',+ error: expect.stringContaining('cannot be generated automatically'), output: { finalAutoReviewId: 'mvar-fix', renderJobId: 'render-1' } });++ doubles.resumeAutoReview.mockRejectedValueOnce(Object.assign(new Error('This run is needs-human'), { code: 'AUTO_REVIEW_CLOSED' }));+ await rendersAgain();+ await service.resumeAutonomousVideo('mv-auto');+ expect(runOf()).toMatchObject({ status: 'running', output: { renderJobId: 'render-2', finalAutoReviewId: null } });+ });});});