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

Let autopilot take mid-run direction, keep approvals across a composition migration, and fit the full-film review range (#11189)

[._.]/32a203f9507b
diff --git a/server/lib/musicVideoValidation.js b/server/lib/musicVideoValidation.js
index 24539db856..ce017df506 100644
--- a/server/lib/musicVideoValidation.js
+++ b/server/lib/musicVideoValidation.js
@@ -1062,6 +1062,9 @@ export const musicVideoAutonomousStartSchema = z.object({
// Resume a parked/failed run, or approve the checkpoint it is waiting on.
export const musicVideoAutonomousResumeSchema = z.object({
+ // Change course mid-run: the brief's prompt and guidance, which production plans shots from.
+ prompt: z.string().trim().min(1).max(AUTONOMOUS_PROMPT_MAX).optional(),
+ guidance: z.string().max(4000).optional(),
// Replace the stage output the director edited at a checkpoint.
lyrics: z.string().max(20000).optional(),
style: z.string().max(AUTONOMOUS_PROMPT_MAX).optional(),
diff --git a/server/services/musicVideo/autonomousService.js b/server/services/musicVideo/autonomousService.js
index da329e7379..af914d3a48 100644
--- a/server/services/musicVideo/autonomousService.js
+++ b/server/services/musicVideo/autonomousService.js
@@ -1,6 +1,6 @@
import { musicVideoMediaMode, musicVideoAllowsMedia } from '../../lib/musicVideoMediaPolicy.js';
import { prepareProductionReview } from './productionReviewService.js';
-import { ALIGNMENT_UNVERIFIED_PROBLEM, assertProductionApproval, productionAlignmentBasis, productionReadiness, productionReviewBasis } from './productionReview.js';
+import { ALIGNMENT_UNVERIFIED_PROBLEM, assertProductionApproval, carryProductionApprovals, productionAlignmentBasis, productionReadiness, productionReviewBasis } from './productionReview.js';
import { CAST_SETS_WORKING } from './castAndSets.js';
import { applyTreatmentPatch, applyTreatmentToProject } from './treatment.js';
import { codeFirstProductionAssets, normalizeMusicVideoProductionPolicy } from '../../lib/musicVideoMediumPlan.js';
@@ -699,6 +699,9 @@ async function orchestrateProductionStage(project, run, stage) {
}
}
+/** The brief's prompt and guidance as production's planning directive. */
+const briefDirective = (brief) => trimTo([brief.prompt, brief.guidance].filter(Boolean).join('\n\n'), 4000);
+
/** The run renders its film from code alone rather than through production. */
const rendersFromCode = (project, run) => musicVideoMediaMode(project) === 'code-only' || autonomousMedium(run.brief.tools) === 'code';
@@ -1210,7 +1213,7 @@ const STAGES = {
}
const pool = briefProductionPool(run.brief, project);
const started = await deps.startProduction(project.id, {
- directive: trimTo([run.brief.prompt, run.brief.guidance].filter(Boolean).join('\n\n'), 4000),
+ directive: briefDirective(run.brief),
pool,
...(stopsBeforeClips(project, run, pool) ? { stopBefore: 'clips' } : {}),
limits: { ...run.brief.limits, ...(run.brief.budgetUsd != null ? { spendCapUsd: run.brief.budgetUsd } : {}) },
@@ -1634,6 +1637,9 @@ export async function resumeAutonomousVideo(projectId, edits = {}, { autoApprove
const retake = edits.retakeSong === true;
if (retake && run.brief.songFrom) throw runError(409, 'SONG_REUSED', 'This run reuses an existing song, so it has no song to retake');
if (retake) assertAtSongCheckpoint(run);
+ // A changed prompt or guidance reaches production's shot planner on this resume.
+ const directionPatch = Object.fromEntries(['prompt', 'guidance'].filter((key) => typeof edits[key] === 'string' && edits[key] !== (run.brief[key] ?? '')).map((key) => [key, edits[key]]));
+ const directionChanged = Object.keys(directionPatch).length > 0;
const modelsChanged = toolsPatch !== null || (modelsPatch !== null && JSON.stringify(modelsPatch) !== JSON.stringify(run.brief.models || {}));
// Approving the stills goes on to the clips, including in any new production run.
const stillsApproved = run.status === 'awaiting-approval' && run.awaiting === 'stills';
@@ -1659,8 +1665,9 @@ export async function resumeAutonomousVideo(projectId, edits = {}, { autoApprove
const stage = retake ? 'song' : r.stage;
return {
status: 'running', awaiting: null, error: null, errorCode: null, processId: PROCESS_ID,
- ...(edits.suno || edits.localMusic !== undefined || grant || modelsPatch || toolsPatch || limitsPatch || stillsApproved ? { brief: {
+ ...(edits.suno || edits.localMusic !== undefined || grant || modelsPatch || toolsPatch || limitsPatch || stillsApproved || directionChanged ? { brief: {
...r.brief,
+ ...directionPatch,
...(toolsPatch ? { tools: toolsPatch } : {}),
...(stillsApproved ? { stopBeforeVideo: false } : {}),
...(modelsPatch ? { models: modelsPatch } : {}),
@@ -1724,7 +1731,7 @@ export async function resumeAutonomousVideo(projectId, edits = {}, { autoApprove
return { project: presentProjectAutonomousRun(latest), run: presentAutonomousRun(projectAutonomousRun(latest)) };
}
if (resume.kind === 'production') {
- return resumeDelegatedProduction(projectId, out.run, { swapModels: modelsChanged, limits: edits.limits, stillsApproved });
+ return resumeDelegatedProduction(projectId, out.run, { swapModels: modelsChanged, limits: edits.limits, stillsApproved, directionChanged });
}
advanceInBackground(projectId);
return { project: out.project, run: presentAutonomousRun(out.run) };
@@ -1756,7 +1763,7 @@ const PRODUCTION_LIVE = new Set(['running', 'limit-reached', 'blocked', 'needs-r
* when that run is already complete. No production run left to follow — or a model
* swap on one that cannot resume — starts a new one from the brief by re-entering `produce`.
*/
-async function resumeDelegatedProduction(projectId, run, { swapModels = false, limits, stillsApproved = false } = {}) {
+async function resumeDelegatedProduction(projectId, run, { swapModels = false, limits, stillsApproved = false, directionChanged = false } = {}) {
const project = await getProject(projectId);
const runs = Array.isArray(project.productionRuns) ? project.productionRuns : [];
const current = runs.find((r) => r.id === run.output.productionRunId) || null;
@@ -1790,6 +1797,7 @@ async function resumeDelegatedProduction(projectId, run, { swapModels = false, l
acceptBasis: true,
...(productionLimits ? { limits: productionLimits } : {}),
...(swapModels ? { pool: briefProductionPool(run.brief, project) } : {}),
+ ...(directionChanged ? { directive: briefDirective(run.brief) } : {}),
})
.then(() => null, (err) => err);
if (failure) {
@@ -2166,6 +2174,8 @@ async function ensureFootageComposition(projectId) {
|| normalizeMusicVideoProductionPolicy(project.productionPolicy).strategy === 'code-first') return false;
// The manifest is replaced whole, so its cues, cutting and grade ride along.
await deps.updateProject(projectId, { composition: { ...composition, mode: 'composed' } });
+ // No one reviewed this switch, so the approvals it would stale carry over.
+ await mutateProjectRecord(projectId, (current) => ({ project: carryProductionApprovals(project, current, 'Composed the footage of a project with no composition document') }));
console.log(`🎬 Autonomous music video set ${short(projectId)} to compose its footage (it had no composition document)`);
return true;
}
diff --git a/server/services/musicVideo/autonomousService.test.js b/server/services/musicVideo/autonomousService.test.js
index bbfdc73243..9d0721fc58 100644
--- a/server/services/musicVideo/autonomousService.test.js
+++ b/server/services/musicVideo/autonomousService.test.js
@@ -377,6 +377,16 @@ describe('startAutonomousVideo', () => {
expect(runOf()).toMatchObject({ status: 'completed', output: expect.objectContaining({ productionDone: true, renderJobId: 'production-render' }) });
});
+ // Uniquely catches a mid-run course change never reaching production's shot planner.
+ it('carries a changed prompt and guidance to the parked production run on resume', async () => {
+ await delegated();
+ store.get('mv-auto').productionRuns[0].status = 'limit-reached';
+ await service.__testing.onProductionEvent({ projectId: 'mv-auto', runId: 'mvpr-1', run: { status: 'limit-reached', stopReason: 'generation limit' } });
+ await service.resumeAutonomousVideo('mv-auto', { prompt: 'p', guidance: 'Natural chestnut shag, no pencil.' });
+ expect(runOf().brief).toMatchObject({ prompt: 'p', guidance: 'Natural chestnut shag, no pencil.' });
+ expect(doubles.resumeProduction).toHaveBeenCalledWith('mv-auto', 'mvpr-1', { acceptBasis: true, directive: 'p\n\nNatural chestnut shag, no pencil.' });
+ });
+
it('resumes a parked run with raised limits, and a model swap continues that run with the new pool', async () => {
await delegated();
store.get('mv-auto').productionRuns[0].status = 'limit-reached';
diff --git a/server/services/musicVideo/excerptRender.js b/server/services/musicVideo/excerptRender.js
index 25a2805578..f6d414ca65 100644
--- a/server/services/musicVideo/excerptRender.js
+++ b/server/services/musicVideo/excerptRender.js
@@ -285,7 +285,8 @@ export async function startExcerptRender(projectId, { startSec, endSec, aspect =
// dims/fps/sections/cues in ABSOLUTE song time — the coordinate space
// `startSec`/`endSec` and `excerptBoundaryTimes` are given in.
const probe = buildMusicVideoFfmpegArgs(clips, audioPath, join(PATHS.videos, 'probe.mp4'), { audioDurationSec, frameGrid: composed });
- if (!(startSec >= 0) || !(endSec > startSec) || endSec > probe.totalDuration + (pilotSceneId ? 1 / probe.fps : 1e-6)) {
+ // A range ending on the song's analysed length may overrun the frame-rounded render by under a frame.
+ if (!excerptRangeFits(startSec, endSec, probe.totalDuration, probe.fps)) {
throw new ServerError(
`The excerpt range must fall within the project's ${probe.totalDuration.toFixed(2)}s render`,
{ status: 422, code: 'INVALID_EXCERPT_RANGE', context: { totalDuration: probe.totalDuration } },
diff --git a/server/services/musicVideo/excerptRender.test.js b/server/services/musicVideo/excerptRender.test.js
index 17d813b72b..1dce858097 100644
--- a/server/services/musicVideo/excerptRender.test.js
+++ b/server/services/musicVideo/excerptRender.test.js
@@ -181,3 +181,15 @@ describe('excerpt typography parity (#10703)', () => {
expect(encodeFileContactSheetAtTimes).toHaveBeenCalledWith(expect.any(String), expect.any(String), [0], { width: 64, height: 64, fps: 24 });
});
});
+
+describe('excerpt range', () => {
+ // Uniquely catches a full-film review (ending on the analysed song length) refused by the frame-rounded render.
+ it('accepts an end under one frame past the render and refuses one beyond it', async () => {
+ prime('excerpt-range');
+ const { excerptId } = await startExcerptRender('excerpt-range', { startSec: 0, endSec: 4.014 });
+ expect(excerpt('excerpt-range', excerptId)).toMatchObject({ status: 'rendering', endSec: 4 });
+ lastProc().emit('close', 1, null);
+ await vi.waitFor(() => expect(excerpt('excerpt-range', excerptId).status).toBe('error'));
+ await expect(startExcerptRender('excerpt-range', { startSec: 0, endSec: 4.1 })).rejects.toMatchObject({ code: 'INVALID_EXCERPT_RANGE' });
+ });
+});
diff --git a/server/services/musicVideo/planner.js b/server/services/musicVideo/planner.js
index ddf9cb9976..88094f5209 100644
--- a/server/services/musicVideo/planner.js
+++ b/server/services/musicVideo/planner.js
@@ -383,7 +383,12 @@ export async function planProject(id, { seedPrompts = true, providerId, model, e
let llmRoute = null;
let proposedCameras = new Map();
if (seedPrompts) {
- const guidance = [project.automation?.guidance?.trim(), directive?.trim()].filter(Boolean).join('\n');
+ // The run's brief comes first; the project's live guidance is edited later
+ // and wins where they disagree (a director's mid-run course change).
+ const live = project.automation?.guidance?.trim();
+ const guidance = directive?.trim()
+ ? [`Run brief:\n${directive.trim()}`, live && `Current project guidance (takes precedence over the brief):\n${live}`].filter(Boolean).join('\n\n')
+ : live;
const planning = directive?.trim() ? { ...project, automation: { ...project.automation, guidance } } : project;
const { seeded, reason, route } = await tryProposeScenePrompts(planning, shots, { providerId, model, effort });
llmRoute = route || null;
diff --git a/server/services/musicVideo/production.js b/server/services/musicVideo/production.js
index 6db8d0fd84..fa46b8591b 100644
--- a/server/services/musicVideo/production.js
+++ b/server/services/musicVideo/production.js
@@ -847,7 +847,7 @@ export function stopProductionOnProject(project, runId, now = new Date().toISOSt
* budget. A run halted on a changed creative setup continues only when the
* director accepts the new basis (`acceptBasis`), which re-snapshots it.
*/
-export function resumeProductionOnProject(project, runId, { limits, acceptBasis = false, processId, pool = null, pricing = {}, stopBefore } = {}, now = new Date().toISOString()) {
+export function resumeProductionOnProject(project, runId, { limits, acceptBasis = false, processId, pool = null, pricing = {}, stopBefore, directive } = {}, now = new Date().toISOString()) {
return mutateRun(project, runId, (run) => {
if (!RESUMABLE.has(run.status)) throw productionError(409, 'PRODUCTION_CLOSED', `This production run is ${run.status} — start a new run instead`);
if (normalizeMusicVideoProductionPolicy(project?.productionPolicy).strategy === 'code-first' && !run.authoring) throw productionError(409, 'PRODUCTION_AUTHORING_REQUIRED', 'Cancel this legacy run and start a code-first run with an authoring model');
@@ -878,6 +878,8 @@ export function resumeProductionOnProject(project, runId, { limits, acceptBasis
processId,
resumedAt: now,
retryAcknowledged: run.steps.filter((step) => step.status === 'failed').map((step) => step.key),
+ // The director changed course: later shot planning follows the new direction.
+ ...(typeof directive === 'string' ? { directive: trimTo(directive, PRODUCTION_DIRECTIVE_MAX) } : {}),
stopBefore: nextStop,
// A stills-only run makes no clip, so it drops any pending clip pilot.
...(nextStop ? { pilot: null } : !run.pilot && !run.reviewRunId ? { pilot: { scenes: null } } : {}),
diff --git a/server/services/musicVideo/productionReview.js b/server/services/musicVideo/productionReview.js
index a366013fe4..fdc800ff37 100644
--- a/server/services/musicVideo/productionReview.js
+++ b/server/services/musicVideo/productionReview.js
@@ -477,6 +477,26 @@ export function approveProductionStage(project, { stage, basis, proofReview, app
approvals: { ...project.productionReview?.approvals, [stage]: decision } } };
}
+/**
+ * Re-bind the stages that were approved before a machine-only change (a legacy
+ * footage project switched to compose its shots) onto the changed project, so
+ * a change no one reviewed does not stale an approval no one revoked. A stage
+ * that was not approved stays as it was.
+ */
+export function carryProductionApprovals(before, after, reason) {
+ const was = productionReadiness(before);
+ const basis = productionReviewBasis(after);
+ const inputs = productionApprovalInputs(after);
+ const proofExcerpt = after.excerpts?.find(e => e.id === after.productionReview?.proof?.excerptId);
+ const approvals = { ...after.productionReview?.approvals };
+ for (const stage of ['art', 'storyboard', 'proof']) {
+ if (!was[stage]?.approved || !approvals[stage]) continue;
+ const next = stage === 'proof' ? hash({ basis: basis.proof, excerptId: proofExcerpt?.id, filename: proofExcerpt?.filename }) : basis[stage];
+ approvals[stage] = { ...approvals[stage], basis: next, inputs: inputs[stage], carriedOver: { reason, at: new Date().toISOString() } };
+ }
+ return { ...after, productionReview: { ...after.productionReview, approvals } };
+}
+
/** Comments retain the exact reviewed draft, even after a replacement import. */
export function recordProductionFeedback(project, input) {
const review = project.productionReview || {};
diff --git a/server/services/musicVideo/productionReview.storyboard.test.js b/server/services/musicVideo/productionReview.storyboard.test.js
index 0ae2167d24..f70bcb129c 100644
--- a/server/services/musicVideo/productionReview.storyboard.test.js
+++ b/server/services/musicVideo/productionReview.storyboard.test.js
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest';
-import { productionReadiness, productionAlignmentBasis, approveProductionStage } from './productionReview.js';
+import { productionReadiness, productionAlignmentBasis, approveProductionStage, carryProductionApprovals } from './productionReview.js';
const WORD_PROBLEM = /bounded, positive-duration word timings/;
const SHOT_PROBLEM = /^Complete timing, action, staging, camera and transition/;
@@ -64,6 +64,15 @@ describe('approving a Board storyboard of derived shots', () => {
const approved = approveProductionStage(art, { stage: 'storyboard', basis: before.basis.storyboard });
expect(approved.productionReview.draft.storyboard).toEqual(before.storyboard.shots);
expect(productionReadiness(approved).storyboard.approved).toBe(true);
+
+ // Uniquely catches a machine-only composition migration staling art and storyboard approvals.
+ const composed = { ...approved, composition: { mode: 'composed' } };
+ expect(productionReadiness(composed).storyboard.approved).toBe(false);
+ const carried = carryProductionApprovals(approved, composed, 'compose footage');
+ expect(productionReadiness(carried)).toMatchObject({ art: { approved: true }, storyboard: { approved: true } });
+ expect(carried.productionReview.approvals.storyboard.carriedOver).toMatchObject({ reason: 'compose footage' });
+ // A later creative change still stales it.
+ expect(productionReadiness({ ...carried, concept: 'A new concept' }).storyboard.approved).toBe(false);
});
});
diff --git a/server/services/musicVideo/productionService.js b/server/services/musicVideo/productionService.js
index 935de0dff4..db9edd73ca 100644
--- a/server/services/musicVideo/productionService.js
+++ b/server/services/musicVideo/productionService.js
@@ -682,7 +682,7 @@ export async function startProduction(projectId, { directive, pool: requested, l
* continue. A replacement pool is validated exactly like Start's.
* Returns `{ project, run }`.
*/
-export async function resumeProduction(projectId, runId, { limits, acceptBasis = false, pool: requested, stopBefore } = {}) {
+export async function resumeProduction(projectId, runId, { limits, acceptBasis = false, pool: requested, stopBefore, directive } = {}) {
const before = await requireProject(projectId);
const prior = findProductionRun(before, runId);
const priorReviewId = prior.reviewRunId;
@@ -691,7 +691,7 @@ export async function resumeProduction(projectId, runId, { limits, acceptBasis =
const jobs = await liveJobs();
await mutateProjectRecord(projectId, (current) => reconcileProductionSteps(current, runId, jobs));
const out = await mutateProjectRecord(projectId, (current) => resumeProductionOnProject(current, runId, {
- limits, acceptBasis, processId: PROCESS_ID, stopBefore, ...(pool ? { pool, pricing: poolPricing(pool, current) } : {}),
+ limits, acceptBasis, processId: PROCESS_ID, stopBefore, directive, ...(pool ? { pool, pricing: poolPricing(pool, current) } : {}),
}));
if (pool) console.log(`🎬 Music Video production ${short(runId)} resumed with a replaced pool: ${pool.length} allowed route(s)`);
if (priorReviewId && !out.run.reviewRunId) {