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

Autopilot set to approve no longer parks on pilot, proof or a staled storyboard (#11135)

[._.]/24b646b5d3f4
diff --git a/server/services/musicVideo/autonomousService.js b/server/services/musicVideo/autonomousService.js
index 04dbdadeba..76200e4cfb 100644
--- a/server/services/musicVideo/autonomousService.js
+++ b/server/services/musicVideo/autonomousService.js
@@ -55,6 +55,8 @@ import { MUSIC_VIDEO_AUTOMATION_TOOL_IDS } from '../../lib/musicVideoAutomation.
* look, the song, the art direction, the lyric timing, the storyboard and the
* final video, and either approves each or revises it and judges again
* (bounded by `limits.maxReviewAttempts`, then the last version is accepted).
+ * It also repairs a failed production pilot and approves the passing pilot as
+ * the proof from that review's machine evidence (settleBlockedProduction).
* Every decision lands in `run.orchestration.reviews`. It is approval
* authority, so like `autoApprove` it is granted only to a signed-in session.
*/
@@ -69,7 +71,8 @@ import { getMusicVideoCharacterStyle } from '../../lib/musicVideoCharacterStyles
import { RENDER_TARGET } from '../../lib/renderTargets.js';
import { IMAGE_GEN_MODE } from '../../lib/generationModes.js';
import { assertFootageVideoModelsCapable, loadPoolEnv } from './productionPool.js';
-import { PRODUCTION_RESUMABLE_STATUSES, productionTargets } from './production.js';
+import { PRODUCTION_RESUMABLE_STATUSES, acceptProductionPilot, productionTargets } from './production.js';
+import { currentPilotPass, pilotInputBasis, pilotRepair } from './productionPilot.js';
import {
AUTONOMOUS_DEFAULT_LIMITS,
AUTONOMOUS_LIMIT_BOUNDS,
@@ -1147,7 +1150,7 @@ const STAGES = {
const medium = rendersFromCode(project, run) ? 'code' : autonomousMedium(run.brief.tools);
if (medium === 'code' && !['code', 'document'].includes(project.composition?.mode)) {
await deps.updateProject(project.id, { composition: { mode: 'document', authoringRenderer: 'three' } });
- }
+ } else if (medium !== 'code') await ensureFootageComposition(project.id);
await prepareProductionReview(project.id);
project = await getProject(project.id);
// The guide is generated in the background; the art gate is only meaningful once it exists.
@@ -1854,6 +1857,133 @@ async function raiseSizedLimit(projectId, runId, run, project, production) {
return resumed;
}
+// ---- a blocked production run, settled by the run itself --------------------------
+// A run set to approve does not stop production for the director: a staled art or
+// storyboard approval is reviewed and approved again (settleProductionStage), and
+// in an orchestrated run a failed pilot is repaired and generated again, up to
+// `limits.maxReviewAttempts` repairs per pilot, then its last take is accepted
+// with the open findings noted; a passing pilot is then approved as the proof
+// from the pilot review's own evidence. Anything else parks for the director.
+
+const CLIP_FIXES_MAX = 1000;
+const settlingProduction = new Set();
+
+/** A pilot whose review of its current inputs and media did not pass. */
+function failedPilot(project, production) {
+ for (const pilot of production.pilot?.scenes || []) {
+ if (currentPilotPass(project, pilot)) continue;
+ const review = (project.autoReviews || []).find((r) => r.id === pilot.reviewRunId);
+ const result = review?.attempts?.at(-1)?.review;
+ if (result && result.verdict !== 'pass' && !['running', 'stopped', 'limit-reached'].includes(review.status)
+ && pilot.inputBasis === pilotInputBasis(project, pilot.sceneId)) return { pilot, result };
+ }
+ return null;
+}
+
+/** The review's own words for what failed: its reason and blocking findings. */
+const pilotProblems = (result) => [...new Set([result.reason, ...(result.findings || [])
+ .filter((f) => f.severity === 'blocking').map((f) => f.note)].filter((t) => typeof t === 'string' && t.trim()).map((t) => t.trim()))];
+
+/**
+ * Repair a failed pilot as its review asks: the fix rides the shot's next
+ * prompt (a failed plate makes a new still too), which changes the pilot's
+ * inputs so production makes it again and reviews the new take. Once the
+ * pilot's repairs are spent, the last take is accepted with the findings noted.
+ */
+async function repairPilot(projectId, run, productionRunId, { pilot, result }) {
+ const project = await getProject(projectId);
+ const scene = (project.scenes || []).find((s) => s.sceneId === pilot.sceneId);
+ if (!scene) return false;
+ const repair = pilotRepair(result, scene, project);
+ const problems = pilotProblems(result).join(' ') || `The pilot review returned ${result.verdict}.`;
+ const spent = ((await latestRun(projectId))?.orchestration?.reviews || [])
+ .filter((r) => r.checkpoint === 'pilot' && r.sceneId === pilot.sceneId && r.verdict === 'revise').length;
+ if (spent < reviewLimit(run)) {
+ const at = new Date().toISOString();
+ const slot = repair.category === 'plate' ? 'stillFixes' : 'clipFixes';
+ await mutateProjectRecord(projectId, (current) => ({ project: { ...current, scenes: (current.scenes || []).map((s) => {
+ if (s.sceneId !== pilot.sceneId) return s;
+ // Earlier fixes stay in the prompt so a repair never undoes the last one; the newest win the length cap.
+ const text = [s[slot]?.text, problems].filter(Boolean).join(' ');
+ return { ...s, ...(slot === 'stillFixes' ? { referenceImageId: null } : {}), [slot]: { text: text.slice(-(slot === 'stillFixes' ? STILL_FIXES_MAX : CLIP_FIXES_MAX)), at } };
+ }) } }));
+ await recordReview(projectId, { checkpoint: 'pilot', sceneId: pilot.sceneId, verdict: 'revise',
+ notes: trimTo(`Pilot ${scene.label || pilot.sceneId}: ${repair.category} repair (${spent + 1} of ${reviewLimit(run)}), generated again with the fix. ${problems}`, 1500),
+ changes: [trimTo(`${pilot.sceneId}: ${problems}`, 300)] });
+ return true;
+ }
+ const note = trimTo(`Revision limit reached; accepted the last take with open findings: ${problems}`, 1000);
+ await mutateProjectRecord(projectId, (current) => acceptProductionPilot(current, productionRunId, pilot.sceneId, { by: 'orchestrator', note }));
+ await recordReview(projectId, { checkpoint: 'pilot', sceneId: pilot.sceneId, verdict: 'approve', notes: note });
+ return true;
+}
+
+/** Approve the rendered pilot as the proof, from the machine evidence of its passing (or accepted) review. */
+async function approvePilotProof(projectId, run, production) {
+ const project = await getProject(projectId);
+ const pilots = production.pilot?.scenes || [];
+ const readiness = productionReadiness(project);
+ const excerpt = (project.excerpts || []).find((e) => e.id === project.productionReview?.proof?.excerptId);
+ if (readiness.proof.approved || readiness.proof.problems.length || !excerpt?.filename
+ || !pilots.length || !pilots.every((pilot) => currentPilotPass(project, pilot))) return false;
+ const verdicts = pilots.map((pilot) => {
+ const result = (project.autoReviews || []).find((r) => r.id === pilot.reviewRunId)?.attempts?.at(-1)?.review || {};
+ const checks = Object.entries(result.checks || {}).map(([check, value]) => `${check} ${value}`);
+ return { pilot, result, checks, accepted: result.verdict !== 'pass' };
+ });
+ const audio = ['audioSync', 'lipSync'];
+ const visualReview = verdicts.map(({ pilot, result, checks, accepted }) => `Pilot ${pilot.sceneId} (${pilot.operation}): ${accepted ? 'accepted at the revision limit' : 'passed'}`
+ + `${checks.length ? `; checks ${checks.join(', ')}` : ''}${result.reason ? `. ${result.reason}` : ''}`).join(' ');
+ const audioReview = verdicts.map(({ pilot, result }) => `Pilot ${pilot.sceneId} audio: ${audio.map((check) => `${check} ${result.checks?.[check] || 'not checked'}`).join(', ')}`).join(' ');
+ const open = verdicts.filter((v) => v.accepted).map((v) => v.pilot.accepted?.note).filter(Boolean);
+ const limitations = trimTo(['Machine review of the rendered pilot by the run\'s orchestrator reviewer; no human playback.', ...open].join(' '), 4000);
+ await deps.approveProductionReview(projectId, { stage: 'proof', basis: readiness.basis.proof, approvedBy: 'orchestrator', reviewer: orchestratorIdentity(run),
+ proofReview: { method: 'machine', watchedWithAudio: false, excerptId: excerpt.id, filename: excerpt.filename,
+ machineEvidence: { visualReview: trimTo(`Rendered pilot review. ${visualReview}`, 8000), audioReview: trimTo(`Audio checks from the pilot review. ${audioReview}`, 8000), limitations } } });
+ await recordReview(projectId, { checkpoint: 'proof', verdict: 'approve', notes: trimTo(`Approved the rendered pilot from its review. ${limitations}`, 1500) });
+ return true;
+}
+
+/**
+ * Production stopped (`blocked`) on something a run set to approve can settle
+ * itself. Returns true when it settled it and production resumed; false parks
+ * the run for the director as before.
+ */
+async function settleBlockedProduction(projectId, run, productionRunId) {
+ if (settlingProduction.has(productionRunId)) return true;
+ settlingProduction.add(productionRunId);
+ try {
+ let project = await getProject(projectId);
+ const production = (project.productionRuns || []).find((r) => r.id === productionRunId);
+ if (!production) return false;
+ const orchestrated = isOrchestratedRun(run);
+ const readiness = productionReadiness(project);
+ let settled = false;
+ if (!readiness.storyboard.approved && (orchestrated || autoApproves(run, 'storyboard'))) {
+ project = await settleProductionStage(project, run, 'art');
+ project = await settleProductionStage(project, run, 'storyboard');
+ settled = productionReadiness(project).storyboard.approved;
+ } else if (readiness.storyboard.approved && orchestrated) {
+ const failed = failedPilot(project, production);
+ settled = failed ? await repairPilot(projectId, run, productionRunId, failed) : await approvePilotProof(projectId, run, production);
+ }
+ if (!settled || !await ownsProduction(projectId, productionRunId)) return false;
+ await deps.resumeProduction(projectId, productionRunId, { acceptBasis: true });
+ return true;
+ } catch (err) {
+ console.warn(`⚠️ Autonomous music video ${short(run.id)} could not settle blocked production: ${err.message}`);
+ return false;
+ } finally {
+ settlingProduction.delete(productionRunId);
+ }
+}
+
+/** The run still waits on this production run (a stop or cancel during a settle releases it). */
+async function ownsProduction(projectId, productionRunId) {
+ const latest = projectAutonomousRun(await getProject(projectId));
+ return latest?.status === 'running' && latest.processId === PROCESS_ID && latest.output?.productionRunId === productionRunId;
+}
+
/**
* A production run this autonomous run delegated to advanced. Mirrors its
* terminal state onto the run: completed → kick off the final render and
@@ -1882,6 +2012,8 @@ async function onProductionEvent({ projectId, runId, run: production }) {
if (run.status === 'running') await settleStills(projectId, run, runId);
} else if (production.status === 'limit-reached' && run.status === 'running' && await raiseSizedLimit(projectId, runId, run, project, production)) {
// The default generation limit grew to the planned shots and production goes on.
+ } else if (production.status === 'blocked' && run.status === 'running' && await settleBlockedProduction(projectId, run, runId)) {
+ // A run set to approve settled the stop itself and production goes on.
} else if (PRODUCTION_PARKED.has(production.status) && run.status === 'running') {
await park(projectId, 'needs-human', { error: reason || `Production is ${production.status}`, errorCode: 'PRODUCTION_PARKED' });
}
@@ -2012,9 +2144,24 @@ async function reconcileFinalRender(projectId, { restart = false } = {}) {
return startFinalRender(projectId, run);
}
+/**
+ * A footage project left in document mode with no document (projects created
+ * with a media mode used to default to it) cannot render; it is composed from its shots.
+ */
+async function ensureFootageComposition(projectId) {
+ const project = await getProject(projectId);
+ const composition = project?.composition;
+ if (composition?.mode !== 'document' || composition.document || composition.documentDraft
+ || normalizeMusicVideoProductionPolicy(project.productionPolicy).strategy === 'code-first') return;
+ // The manifest is replaced whole, so its cues, cutting and grade ride along.
+ await deps.updateProject(projectId, { composition: { ...composition, mode: 'composed' } });
+ console.log(`🎬 Autonomous music video set ${short(projectId)} to compose its footage (it had no composition document)`);
+}
+
/** Render the film (again) and wait for the render's own event. */
async function startFinalRender(projectId, run) {
if (!await settleOverlayText(projectId, run)) return;
+ if (!rendersFromCode(await getProject(projectId), run)) await ensureFootageComposition(projectId);
const render = await deps.renderVideo(projectId).catch((err) => ({ error: err }));
if (render.error) return failFinalRender(projectId, `The final render did not start: ${render.error.message}`, render.error.code || 'FINAL_RENDER_FAILED');
await patchRun(projectId, (r) => ({ output: { renderJobId: render.jobId || null }, ...stagePatch(r, 'produce', { status: 'running', error: null, step: RENDER_STEP }), error: null, errorCode: null }));
diff --git a/server/services/musicVideo/autonomousService.test.js b/server/services/musicVideo/autonomousService.test.js
index bfead2a1f5..9d835cd680 100644
--- a/server/services/musicVideo/autonomousService.test.js
+++ b/server/services/musicVideo/autonomousService.test.js
@@ -1,13 +1,13 @@
// Existing engine cases isolate the creative review boundary; explicit approval-flow
// cases below switch to the real model and verify pause/resume without providers.
-const creativeReview = vi.hoisted(() => ({ real: false }));
+const creativeReview = vi.hoisted(() => ({ real: false, readiness: {} }));
vi.mock('./productionReview.js', async (load) => {
const actual = await load();
return { ...actual,
assertProductionApproval: (...args) => creativeReview.real ? actual.assertProductionApproval(...args) : undefined,
productionReadiness: (...args) => creativeReview.real ? actual.productionReadiness(...args) : {
art: { approved: true }, storyboard: { approved: true }, proof: { approved: true }, basis: { proof: 'test-proof' }, readyForProduction: true,
- alignment: { status: 'verified' },
+ alignment: { status: 'verified' }, ...creativeReview.readiness,
},
};
});
@@ -67,6 +67,7 @@ const stub = (name, impl) => vi.fn(async (...args) => { calls.push(name); return
beforeEach(() => {
creativeReview.real = false;
+ creativeReview.readiness = {};
store.clear();
calls = [];
doubles = {
@@ -204,6 +205,20 @@ describe('startAutonomousVideo', () => {
}
});
+ // Uniquely catches a footage project left in document mode with no document failing its final render.
+ it('composes a footage project that has no composition document before its final render', async () => {
+ await service.startAutonomousVideo({ prompt: 'p' });
+ await vi.waitFor(() => expect(runOf()?.output.productionRunId).toBe('mvpr-1'));
+ Object.assign(store.get('mv-auto'), { composition: { mode: 'document', textCues: [{ id: 'cue' }] }, productionPolicy: { strategy: 'legacy' } });
+ doubles.renderVideo.mockImplementationOnce(async (id) => {
+ expect(store.get(id).composition).toEqual({ mode: 'composed', textCues: [{ id: 'cue' }] });
+ return { jobId: 'render-1' };
+ });
+ await service.__testing.onProductionEvent({ projectId: 'mv-auto', runId: 'mvpr-1', run: { status: 'completed' } });
+ expect(doubles.renderVideo).toHaveBeenCalledOnce();
+ expect(runOf().output).toMatchObject({ renderJobId: 'render-1' });
+ });
+
it('finishes — and starts the final render — when the delegated production run completes', async () => {
await service.startAutonomousVideo({ prompt: 'p' });
await vi.waitFor(() => expect(runOf()?.output.productionRunId).toBe('mvpr-1'));
@@ -1340,6 +1355,23 @@ describe('autopilot clears the gates it was granted on its own', () => {
expect(doubles.verifyAlignment).toHaveBeenCalledWith('mv-auto', expect.objectContaining({ notes: expect.stringContaining('source project') }));
});
+ // Uniquely catches a run granted the storyboard parking for the director when a prompt edit stales that approval mid-production.
+ it('approves a storyboard a prompt edit staled again and resumes production', async () => {
+ analyzed({ productionReview: { draft: { ...GUIDE, lyricsMode: 'instrumental', timingNotes: 'Synthetic instrumental master checked.', storyboard: [shot] } } });
+ await service.startAutonomousVideo({ prompt: 'p', tools: ['image:local'], ...GRANT[0] }, GRANT[1]);
+ await vi.waitFor(() => expect(doubles.startProduction).toHaveBeenCalledOnce());
+ const project = store.get('mv-auto');
+ project.scenes[0].prompt = 'the dancer turns toward the light';
+ project.productionRuns = [{ id: 'mvpr-1', status: 'blocked', createdAt: new Date().toISOString() }];
+ expect(actual.productionReadiness(project).storyboard.approved).toBe(false);
+ doubles.approveProductionReview.mockClear();
+ await service.__testing.onProductionEvent({ projectId: 'mv-auto', runId: 'mvpr-1', run: { status: 'blocked', stopReason: 'Production review needs human approval' } });
+ expect(doubles.approveProductionReview).toHaveBeenCalledWith('mv-auto', expect.objectContaining({ stage: 'storyboard', approvedBy: 'autopilot' }));
+ expect(actual.productionReadiness(store.get('mv-auto')).storyboard.approved).toBe(true);
+ expect(doubles.resumeProduction).toHaveBeenCalledWith('mv-auto', 'mvpr-1', { acceptBasis: true });
+ expect(runOf().status).toBe('running');
+ });
+
it('marks an instrumental song as one instead of asking for lyrics', async () => {
analyzed({ productionReview: { draft: { ...GUIDE, lyricsMode: 'vocal', storyboard: [shot] } } });
await service.startAutonomousVideo({ prompt: 'p', tools: ['image:local'], instrumental: true, ...GRANT[0] }, GRANT[1]);
@@ -1513,6 +1545,67 @@ describe('orchestrated mode (brief.orchestrator)', () => {
expect(runOf()).toMatchObject({ status: 'needs-human', errorCode: 'PRODUCTION_PARKED' });
});
+ describe('a production run blocked on its pilot', () => {
+ let pilotInputBasis;
+ let pilotDependencies;
+ beforeEach(async () => {
+ ({ pilotInputBasis, pilotDependencies } = await import('./productionPilot.js'));
+ doubles.approveProductionReview = stub('approve', async () => {});
+ service.__setAutonomousDepsForTests(doubles);
+ });
+ const pilotFixture = async (limits) => {
+ await service.startAutonomousVideo({ prompt: 'p', tools: ['image:local', 'video:local'], orchestrator: ORCHESTRATOR, ...(limits ? { limits } : {}) }, { autoApproveAuthorized: true });
+ await vi.waitFor(() => expect(doubles.startProduction).toHaveBeenCalledOnce());
+ store.get('mv-auto').scenes = [{ sceneId: 'mvs-a', label: 'Skate park', startSec: 0, endSec: 4, prompt: 'a skater carves the bowl', referenceImageId: 'a1.png', videoHistoryId: 'clip-1', takes: [] }];
+ store.get('mv-auto').productionRuns = [{ id: 'mvpr-1', status: 'blocked', createdAt: new Date().toISOString(), pilot: { scenes: [] } }];
+ };
+ // A pilot review of the scene as it stands now, with the given verdict.
+ const reviewPilot = (id, result) => {
+ const project = store.get('mv-auto');
+ project.autoReviews = [...(project.autoReviews || []), { id, status: result.verdict === 'pass' ? 'passed' : 'needs-human',
+ attempts: [{ n: 1, excerptId: 'test-proof', review: { checks: {}, findings: [], ...result, dependencies: pilotDependencies(project, 'mvs-a') } }] }];
+ project.productionRuns[0].pilot = { scenes: [{ sceneId: 'mvs-a', operation: 'cutaway', reviewRunId: id, inputBasis: pilotInputBasis(project, 'mvs-a') }] };
+ };
+ const blocked = () => service.__testing.onProductionEvent({ projectId: 'mv-auto', runId: 'mvpr-1', run: { status: 'blocked', stopReason: 'Pilot mvs-a: revise.' } });
+
+ // Uniquely catches a failed pilot parking an orchestrated run, or a repair the next take never sees.
+ it('repairs a failed pilot within the review limit, then accepts its last take with the findings noted', async () => {
+ await pilotFixture({ maxReviewAttempts: 1 });
+ reviewPilot('rev-1', { verdict: 'revise', reason: 'The skater floats above the ramp.', checks: { motion: 'fail' },
+ findings: [{ severity: 'blocking', note: 'Wheels never touch the coping.' }] });
+ await blocked();
+ expect(store.get('mv-auto').scenes[0]).toMatchObject({ videoHistoryId: 'clip-1',
+ clipFixes: { text: 'The skater floats above the ramp. Wheels never touch the coping.' } });
+ expect(reviews()).toContain('pilot:revise');
+ expect(doubles.resumeProduction).toHaveBeenLastCalledWith('mv-auto', 'mvpr-1', { acceptBasis: true });
+ expect(runOf().status).toBe('running');
+
+ // Production made the shot again from the fix, and that take failed too: the repair is spent.
+ store.get('mv-auto').scenes[0].videoHistoryId = 'clip-2';
+ reviewPilot('rev-2', { verdict: 'revise', reason: 'The landing is still soft.' });
+ doubles.resumeProduction.mockClear();
+ await blocked();
+ expect(store.get('mv-auto').productionRuns[0].pilot.scenes[0].accepted).toMatchObject({ reviewRunId: 'rev-2', by: 'orchestrator',
+ note: expect.stringContaining('The landing is still soft.') });
+ expect(reviews().filter((r) => r.startsWith('pilot'))).toEqual(['pilot:revise', 'pilot:approve']);
+ expect(doubles.resumeProduction).toHaveBeenCalledWith('mv-auto', 'mvpr-1', { acceptBasis: true });
+ expect(runOf().status).toBe('running');
+ });
+
+ // Uniquely catches an orchestrated run parking on the proof gate after its pilot passed.
+ it('approves the passing pilot as the proof from its machine review', async () => {
+ await pilotFixture();
+ reviewPilot('rev-1', { verdict: 'pass', reason: 'The carve lands on the downbeat.', checks: { motion: 'pass', audioSync: 'pass' } });
+ creativeReview.readiness = { proof: { approved: false, problems: [] } };
+ await blocked();
+ expect(doubles.approveProductionReview).toHaveBeenCalledWith('mv-auto', expect.objectContaining({ stage: 'proof', basis: 'test-proof', approvedBy: 'orchestrator',
+ proofReview: expect.objectContaining({ method: 'machine', watchedWithAudio: false, excerptId: 'test-proof', filename: 'test-proof.mp4',
+ machineEvidence: expect.objectContaining({ audioReview: expect.stringContaining('audioSync pass') }) }) }));
+ expect(reviews()).toContain('proof:approve');
+ expect(doubles.resumeProduction).toHaveBeenCalledWith('mv-auto', 'mvpr-1', { acceptBasis: true });
+ });
+ });
+
// Uniquely catches an unviewable still being recorded as an approved review while the run still waits for the director.
it('does not record approval for stills the reviewer could not see', async () => {
await service.startAutonomousVideo({ prompt: 'p', tools: ['image:local'], orchestrator: ORCHESTRATOR }, { autoApproveAuthorized: true });
diff --git a/server/services/musicVideo/excerptRender.js b/server/services/musicVideo/excerptRender.js
index ddf1218fc3..72e9c5e6f6 100644
--- a/server/services/musicVideo/excerptRender.js
+++ b/server/services/musicVideo/excerptRender.js
@@ -276,7 +276,7 @@ export async function startExcerptRender(projectId, { startSec, endSec, aspect =
status: 422, code: 'EXCERPT_ASPECT_UNSUPPORTED',
});
}
- const { ffmpeg, audioPath, composed, clips, audioDurationSec, soundBed } = await planMusicVideoRender(project);
+ const { ffmpeg, audioPath, composed, clips, audioDurationSec, soundBed } = await planMusicVideoRender(project, { draft: true });
await ensureDir(PATHS.videos);
await ensureDir(PATHS.videoThumbnails);
diff --git a/server/services/musicVideo/production.js b/server/services/musicVideo/production.js
index 78240810e1..e98b84b625 100644
--- a/server/services/musicVideo/production.js
+++ b/server/services/musicVideo/production.js
@@ -49,7 +49,7 @@ import { projectAutoReviews } from './autoReview.js';
import { projectRevisions } from './revision.js';
import { castAndSetsSettled } from './castAndSets.js';
import { assertProductionApproval } from './productionReview.js';
-import { currentPilotPass, pilotClass, pilotInputBasis, pilotRepair, selectProductionPilots } from './productionPilot.js';
+import { currentPilotPass, pilotClass, pilotInputBasis, pilotRepair, selectProductionPilots, stalePilotSlot } from './productionPilot.js';
const PRODUCTION_LIMIT_BOUNDS = Object.freeze({
maxGenerations: Object.freeze({ min: 1, max: 500 }),
@@ -486,6 +486,8 @@ function nextOpenGeneration(project, run, jobs, { pendingPilots, targets }) {
* `author-document` / `revise-document` — author the approved document or
* just the failed song sections, without changing its assets;
* `render-document` — encode the chosen document after continuous review;
+ * `refresh-pilot` — a pilot's inputs changed after its review: clear the
+ * reviewed take so the pilot is generated again from them;
* `review` — every scene holds its media: hand the continuous excerpt
* `[startSec, endSec)` to an auto-review run;
* `wait` — work in flight (generation jobs, or the review run);
@@ -519,6 +521,8 @@ export function nextProductionStep(project, run, { jobs = [], processId = null }
const pendingPilots = pilots.filter((pilot) => !currentPilotPass(project, pilot));
const blocking = blockingPilotReview(project, run, pendingPilots);
if (blocking) return blocking;
+ const stale = pendingPilots.find((pilot) => stalePilotSlot(project, pilot));
+ if (stale) return { type: 'refresh-pilot', sceneId: stale.sceneId };
if (run.authoring && targets.frame.some((scene) => scene.shotMode === 'performance')) {
const gate = castAndSetsGate(project, run);
if (gate) return { type: 'halt', status: 'blocked', reason: 'This selected performance shot needs the reviewed Cast & Sets references. Build and approve that check-in, then resume; production will not start an unbudgeted image batch.' };
@@ -758,6 +762,28 @@ export const attachProductionReview = (project, runId, reviewRunId, now = new Da
export const planProductionPilots = (project, runId, now = new Date().toISOString()) =>
mutateRun(project, runId, () => ({ pilot: { scenes: selectProductionPilots(project) } }), now);
+/** Clear a stale pilot take (see stalePilotSlot); the take stays in the scene's history. */
+export function refreshProductionPilot(project, runId, sceneId, now = new Date().toISOString()) {
+ const run = findProductionRun(project, runId);
+ const pilot = run.pilot?.scenes?.find((p) => p.sceneId === sceneId);
+ const slot = pilot && stalePilotSlot(project, pilot);
+ if (!slot) return { project, run };
+ return mutateRun({ ...project, scenes: project.scenes.map((scene) => (scene.sceneId === sceneId ? { ...scene, [slot]: null } : scene)) },
+ runId, () => ({}), now);
+}
+
+/**
+ * The run's orchestrator accepts a pilot's last reviewed take once its repairs
+ * are spent. Bound to that review, so new media or inputs need a new review.
+ */
+export const acceptProductionPilot = (project, runId, sceneId, { by, note }, now = new Date().toISOString()) =>
+ mutateRun(project, runId, (run) => {
+ const pilot = run.pilot?.scenes?.find((p) => p.sceneId === sceneId);
+ if (!pilot?.reviewRunId) throw productionError(409, 'PRODUCTION_PILOT_REQUIRED', 'This pilot has no review to accept');
+ return { pilot: { ...run.pilot, scenes: run.pilot.scenes.map((p) => (p.sceneId === sceneId
+ ? { ...p, accepted: { reviewRunId: p.reviewRunId, by, note: note || null, at: now } } : p)) } };
+ }, now);
+
export const attachProductionPilotReview = (project, runId, sceneId, reviewRunId, now = new Date().toISOString()) =>
mutateRun(project, runId, (run) => ({ pilot: { ...run.pilot, scenes: run.pilot.scenes.map((pilot) =>
pilot.sceneId === sceneId ? { ...pilot, reviewRunId, inputBasis: pilotInputBasis(project, sceneId) } : pilot) } }), now);
diff --git a/server/services/musicVideo/productionDispatch.js b/server/services/musicVideo/productionDispatch.js
index 21e8a71a6b..75a812f4a0 100644
--- a/server/services/musicVideo/productionDispatch.js
+++ b/server/services/musicVideo/productionDispatch.js
@@ -113,7 +113,10 @@ async function dispatchClip({ project, scene, route, tag }) {
const spanSec = typeof scene.startSec === 'number' && typeof scene.endSec === 'number' && scene.endSec > scene.startSec
? scene.endSec - scene.startSec : null;
const isGrok = route.mode === 'grok';
- const prompt = [base, isGrok ? approximateMotionCues(project.phrases, scene.startSec, scene.endSec) : ''].filter(Boolean).join('. ');
+ // The autonomous run's pilot repair names what the last clip got wrong (autonomousService.js).
+ const fixes = typeof scene.clipFixes?.text === 'string' ? scene.clipFixes.text : '';
+ const prompt = [base, isGrok ? approximateMotionCues(project.phrases, scene.startSec, scene.endSec) : '',
+ fixes ? `Fix these problems from the previous take while preserving the shot intent: ${fixes}` : ''].filter(Boolean).join('. ');
const byBackend = {
// A supplied-audio route animates the frame from its shot's own song window.
local: route.audio === 'supplied' ? { modelId: route.model, mode: 'a2v', _suppliedAudio: true } : { modelId: route.model, disableAudio: true },
diff --git a/server/services/musicVideo/productionPilot.js b/server/services/musicVideo/productionPilot.js
index c7bb08ef81..507353a067 100644
--- a/server/services/musicVideo/productionPilot.js
+++ b/server/services/musicVideo/productionPilot.js
@@ -50,12 +50,34 @@ export const pilotInputBasis = (project, sceneId) => {
style: project.visualSpec, references: project.styleReferences });
};
+/**
+ * A pilot passes on its current review of its current inputs and media: a pass
+ * verdict, or a take the run's orchestrator accepted on that same review once
+ * its repairs were spent (`pilot.accepted`).
+ */
export function currentPilotPass(project, pilot) {
const review = project.autoReviews?.find((r) => r.id === pilot.reviewRunId);
const result = review?.attempts?.at(-1)?.review;
- return review?.status === 'passed' && result?.verdict === 'pass'
- && pilot.inputBasis === pilotInputBasis(project, pilot.sceneId)
- && !musicVideoDependencyChanges(project, result.dependencies).length;
+ if (!result || pilot.inputBasis !== pilotInputBasis(project, pilot.sceneId)
+ || musicVideoDependencyChanges(project, result.dependencies).length) return false;
+ return (review.status === 'passed' && result.verdict === 'pass') || (!!pilot.accepted && pilot.accepted.reviewRunId === pilot.reviewRunId);
+}
+
+/**
+ * The media slot a pilot must make again: its inputs changed after its review
+ * (a prompt edit, a repair) while the reviewed take is still the selected one.
+ * Reviewing that take again would judge what the old inputs made. Null when
+ * nothing is stale.
+ */
+export function stalePilotSlot(project, pilot) {
+ const result = project.autoReviews?.find((r) => r.id === pilot.reviewRunId)?.attempts?.at(-1)?.review;
+ if (!result || pilot.inputBasis === pilotInputBasis(project, pilot.sceneId)) return null;
+ const scene = project.scenes?.find((s) => s.sceneId === pilot.sceneId);
+ if (!scene) return null;
+ const [slot, role] = pilotClass(scene, project) === 'still' ? ['referenceImageId', 'plate'] : ['videoHistoryId', 'clip'];
+ const reviewed = result.dependencies?.references?.find((ref) => ref.sceneId === scene.sceneId && ref.role === role);
+ if (!scene[slot] || !reviewed) return null;
+ return musicVideoDependencyChanges(project, { ...result.dependencies, references: [reviewed] }).length ? null : slot;
}
/** Prefer an edit/reuse before charging for replacement media. No identical retries. */
diff --git a/server/services/musicVideo/productionService.js b/server/services/musicVideo/productionService.js
index 0865284ef3..935de0dff4 100644
--- a/server/services/musicVideo/productionService.js
+++ b/server/services/musicVideo/productionService.js
@@ -41,6 +41,7 @@ import {
attachProductionReview,
attachProductionPilotReview,
planProductionPilots,
+ refreshProductionPilot,
reserveProductionReview,
quoteProductionSpend,
attachProductionDocument,
@@ -456,6 +457,11 @@ async function takeSteps(projectId, runId) {
await mutateProjectRecord(projectId, (current) => planProductionPilots(current, runId));
continue;
}
+ if (step.type === 'refresh-pilot') {
+ await mutateProjectRecord(projectId, (current) => refreshProductionPilot(current, runId, step.sceneId));
+ console.log(`🔁 Music Video production ${short(runId)} makes pilot ${step.sceneId} again from its changed inputs`);
+ continue;
+ }
if (step.type === 'halt') {
const out = await halt(projectId, runId, { status: step.status, reason: step.reason });
diff --git a/server/services/musicVideo/productionService.test.js b/server/services/musicVideo/productionService.test.js
index 2244a36077..1e5232cfa9 100644
--- a/server/services/musicVideo/productionService.test.js
+++ b/server/services/musicVideo/productionService.test.js
@@ -1279,6 +1279,28 @@ describe('budgeted production pilots (#9351)', () => {
.toMatchObject({ category, expectedGenerationSpendUsd: 0 });
});
+ // Uniquely catches a pilot re-reviewing the take its old prompt made, or staying halted on that review.
+ it('makes the pilot again when its prompt changes after a failed review', async () => {
+ board(); pendingPilot(); await reachPilot();
+ verdict({ verdict: 'revise', checks: { motion: 'fail' }, reason: 'Synthetic failed evidence' }); await settle();
+ expect(theRun().status).toBe('blocked');
+ store.get('mv-example').scenes[0].prompt = 'lights sweep left';
+ await service.resumeProduction('mv-example', theRun().id, { acceptBasis: true }); await settle();
+ expect(dispatch.mock.calls[2][0]).toMatchObject({ stepKind: 'clip', scene: expect.objectContaining({ sceneId: 'shot-0', prompt: 'lights sweep left' }) });
+ expect(startAutoReview).toHaveBeenCalledTimes(1);
+ });
+
+ // Uniquely catches an orchestrator-accepted pilot still holding the bulk wave, or an acceptance surviving new media.
+ it('lets an accepted pilot release the bulk wave while its reviewed take stays selected', async () => {
+ const { acceptProductionPilot } = await import('./production.js');
+ board(); pendingPilot(); await reachPilot();
+ verdict({ verdict: 'revise', checks: { motion: 'fail' }, reason: 'Synthetic failed evidence' }); await settle();
+ store.set('mv-example', acceptProductionPilot(current(), theRun().id, 'shot-0', { by: 'orchestrator', note: 'Accepted at the limit' }).project);
+ await service.resumeProduction('mv-example', theRun().id); await settle();
+ expect(dispatch.mock.calls.map(([a]) => a.scene.sceneId)).toEqual(expect.arrayContaining(['shot-1', 'shot-2', 'shot-3']));
+ expect((await service.getProduction('mv-example', theRun().id)).run.pilot.scenes[0].status).toBe('accepted');
+ });
+
it('never treats missing provenance as an accepted pilot', async () => {
board(); pendingPilot(); await reachPilot();
verdict({ verdict: 'pass' }, null); await settle();
diff --git a/server/services/musicVideo/projectsLogic.js b/server/services/musicVideo/projectsLogic.js
index a67fbd68b5..df22c107ff 100644
--- a/server/services/musicVideo/projectsLogic.js
+++ b/server/services/musicVideo/projectsLogic.js
@@ -100,6 +100,7 @@ function normalizeVisualSpec(patch, base = null) {
/** Build a fresh project record from validated create input. */
export function buildProjectRecord(input, { id, now }) {
+ const productionPolicy = normalizeMusicVideoProductionPolicy(input.productionPolicy || (input.mediaMode ? { strategy: 'code-first', maxGeneratedVideoPercent: input.mediaMode === 'code-images-video' ? 100 : 0 } : null));
const {
name, mode = 'director', trackId = null,
uploadedAudioFilename = null, concept = null,
@@ -160,7 +161,9 @@ export function buildProjectRecord(input, { id, now }) {
pacing: input.pacing ?? null,
// #8984 — composition manifest (null = plain concatenation render).
// The document pointer is set only by the import routes, never on create.
- composition: input.composition || input.mediaMode ? withStoredCompositionDocument(normalizeComposition(input.composition || { mode: 'document' }), null) : null,
+ // A code-first project authors a document; a footage project composes its shots.
+ composition: input.composition || input.mediaMode ? withStoredCompositionDocument(normalizeComposition(input.composition
+ || { mode: productionPolicy.strategy === 'code-first' ? 'document' : 'composed' }), null) : null,
// #8988 — optional sound-design bed mixed under the song.
soundBed: input.soundBed ? normalizeSoundBed(input.soundBed) : null,
// The finishing film look every preview, render and baked still is viewed through; null = none.
@@ -171,7 +174,7 @@ export function buildProjectRecord(input, { id, now }) {
// proof checklist); null until the director starts one. See treatment.js.
treatment: null,
mediaMode: musicVideoMediaMode(input),
- productionPolicy: normalizeMusicVideoProductionPolicy(input.productionPolicy || (input.mediaMode ? { strategy: 'code-first', maxGeneratedVideoPercent: input.mediaMode === 'code-images-video' ? 100 : 0 } : null)),
+ productionPolicy,
scenes: [],
renderHistoryId: null,
renderError: null,
diff --git a/server/services/musicVideo/projectsLogic.test.js b/server/services/musicVideo/projectsLogic.test.js
index 1a0a4915eb..ab416c50aa 100644
--- a/server/services/musicVideo/projectsLogic.test.js
+++ b/server/services/musicVideo/projectsLogic.test.js
@@ -19,6 +19,14 @@ import {
const baseProject = () => buildProjectRecord({ name: 'Test MV' }, { id: 'mv-1', now: '2026-01-01T00:00:00.000Z' });
describe('buildProjectRecord', () => {
+ // Uniquely catches a footage project created in document mode with no document, which no render can use.
+ it('composes a footage project and leaves a code-first one to its document', () => {
+ const footage = buildProjectRecord({ name: 'A', mediaMode: 'code-images-video', productionPolicy: { strategy: 'legacy' } }, { id: 'mv-f', now: 'n' });
+ expect(footage.composition).toMatchObject({ mode: 'composed' });
+ expect(footage.composition.document ?? null).toBeNull();
+ expect(buildProjectRecord({ name: 'B', mediaMode: 'code-images-video' }, { id: 'mv-c', now: 'n' }).composition).toMatchObject({ mode: 'document' });
+ });
+
it('builds a draft director project with sensible defaults', () => {
const p = buildProjectRecord({ name: 'Neon Nights', trackId: 'track-9' }, { id: 'mv-x', now: '2026-01-01T00:00:00.000Z' });
expect(p).toMatchObject({
diff --git a/server/services/musicVideo/render.js b/server/services/musicVideo/render.js
index 9d3e025d17..a7cd39e768 100644
--- a/server/services/musicVideo/render.js
+++ b/server/services/musicVideo/render.js
@@ -209,11 +209,13 @@ const authoredSpan = (scene) => (sceneHasAuthoredSpan(scene) ? round3(scene.endS
// in scene order. Neither needs footage: a still needs its selected reference
// frame (404 MISSING_STILLS when it is gone), and both need an authored span
// (422 UNTIMED_SECTIONS), since there is no clip to take a length from.
-export async function resolveSceneClips(project, { layered = false } = {}) {
+export async function resolveSceneClips(project, { layered = false, stillForMissingClip = false } = {}) {
+ // A draft shows a footage shot that has no clip yet as its still (layered renders only).
+ const standIn = (s) => stillForMissingClip && layered && !s.videoHistoryId && s.referenceImageId && sceneVisualLayer(s, { layered }) === 'footage';
const scenes = (Array.isArray(project.scenes) ? project.scenes : [])
.slice()
.sort((a, b) => (a.order ?? 0) - (b.order ?? 0))
- .filter((s) => s && (s.videoHistoryId || sceneVisualLayer(s, { layered }) !== 'footage'));
+ .filter((s) => s && (s.videoHistoryId || sceneVisualLayer(s, { layered }) !== 'footage' || standIn(s)));
if (scenes.length === 0) {
throw new ServerError('No scene videos to render — generate at least one scene clip first', {
status: 400, code: 'NO_SCENE_CLIPS',
@@ -226,7 +228,7 @@ export async function resolveSceneClips(project, { layered = false } = {}) {
const untimed = [];
const clips = [];
for (const scene of scenes) {
- const layer = sceneVisualLayer(scene, { layered });
+ const layer = standIn(scene) ? 'still' : sceneVisualLayer(scene, { layered });
if (layer !== 'footage') {
const spanSec = authoredSpan(scene);
if (spanSec == null) { untimed.push(scene.sceneId); continue; }
@@ -603,7 +605,7 @@ export function assertCurrentClipDependencies(project) {
{ status: 422, code: 'STALE_CLIP_DEPENDENCIES', context: { sceneIds: stale.map((scene) => scene.sceneId) } });
}
-export async function planMusicVideoRender(project) {
+export async function planMusicVideoRender(project, { draft = false } = {}) {
assertMusicVideoMediaSelections(project);
assertCurrentClipDependencies(project);
const ffmpeg = await findFfmpeg();
@@ -616,7 +618,7 @@ export async function planMusicVideoRender(project) {
// #8985: a composed render cuts still and card sections into the same
// timebase as the footage; plain concat renders footage only, as before.
const composed = project.composition?.mode === 'composed';
- const rawClips = await resolveSceneClips(project, { layered: composed });
+ const rawClips = await resolveSceneClips(project, { layered: composed, stillForMissingClip: draft });
const audioDurationSec = await probeVideoDuration(audioPath).catch(() => null);
const beats = project.audioAnalysis?.beats;
const snapped = beatSnapClips(rawClips, beats, { scenes: project.scenes });
diff --git a/server/services/musicVideo/render.test.js b/server/services/musicVideo/render.test.js
index d858b0e579..67ff907b57 100644
--- a/server/services/musicVideo/render.test.js
+++ b/server/services/musicVideo/render.test.js
@@ -317,6 +317,19 @@ describe('resolveSceneClips', () => {
expect(clips).toEqual([expect.objectContaining({ sceneId: 's1', layer: 'card', cardText: '', cardColor: '#000000', duration: 3 })]);
});
+ // Uniquely catches a draft dropping a footage shot that has a still but no clip yet, or a final render padding with stills.
+ it('shows a clipless footage shot as its still in a layered draft only', async () => {
+ loadHistory.mockResolvedValue([{ id: 'h1', filename: 'a.mp4', width: 768, height: 512, fps: 24, numFrames: 48 }]);
+ const project = { scenes: [
+ { sceneId: 's1', order: 0, videoHistoryId: 'h1', startSec: 0, endSec: 2 },
+ { sceneId: 's2', order: 1, videoHistoryId: null, referenceImageId: 'still.png', startSec: 2, endSec: 5 },
+ ] };
+ const draft = await resolveSceneClips(project, { layered: true, stillForMissingClip: true });
+ expect(draft.map((c) => [c.sceneId, c.layer || 'footage'])).toEqual([['s1', 'footage'], ['s2', 'still']]);
+ expect(draft[1]).toMatchObject({ duration: 3, imagePath: expect.stringContaining('still.png') });
+ expect((await resolveSceneClips(project, { layered: true })).map((c) => c.sceneId)).toEqual(['s1']);
+ });
+
it('throws NO_SCENE_CLIPS when no scene has a clip', async () => {
loadHistory.mockResolvedValue([]);
await expect(resolveSceneClips({ scenes: [{ sceneId: 's1', order: 0, videoHistoryId: null }] }))