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: music video autopilot waits for Cast & Sets before the art gate instead of parking with an empty guide (#10431)

[._.]/ Adam Eivy27219cb5f153
diff --git a/server/services/musicVideo/autonomousService.js b/server/services/musicVideo/autonomousService.js
index aaeea4398b..b34ed1a82d 100644
--- a/server/services/musicVideo/autonomousService.js
+++ b/server/services/musicVideo/autonomousService.js
@@ -1,6 +1,7 @@
import { musicVideoMediaMode, musicVideoAllowsMedia } from '../../lib/musicVideoMediaPolicy.js';
import { prepareProductionReview } from './productionReviewService.js';
import { assertProductionApproval, productionAlignmentBasis, productionReadiness, productionReviewBasis } from './productionReview.js';
+import { CAST_SETS_WORKING } from './castAndSets.js';
/**
* Fully-autonomous Music Video — the run orchestrator.
@@ -110,6 +111,13 @@ const defaults = {
renderVideo: async (...args) => (await import('./render.js')).renderMusicVideo(...args),
activeRenderJobId: async (projectId) => (await import('./render.js')).getActiveRenderJobId(projectId),
cancelRender: async (jobId) => (await import('./render.js')).cancelRender(jobId),
+ // An interrupted (previous process) Cast & Sets stage re-pins to this one; true when it did.
+ resumeInterruptedCastAndSets: async (project) => {
+ const { presentProjectCastAndSets, resumeCastAndSets } = await import('./castAndSetsService.js');
+ if (!presentProjectCastAndSets(project).castAndSets?.interrupted) return false;
+ await resumeCastAndSets(project.id);
+ return true;
+ },
// The review persistence path; session authority was checked on start/resume.
approveProductionReview: async (...args) => (await import('./productionReviewService.js')).approveProductionReview(...args),
// Orchestrated mode: the reviewer call, and the edits a reviewer makes by hand.
@@ -181,6 +189,7 @@ const stagePatch = (run, stage, patch) => ({ stages: { [stage]: { ...run.stages[
// ---- production review auto-approval (brief.autoApprove) --------------------------
const RENDER_STEP = 'rendering';
+const CAST_STEP = 'cast-and-sets';
const autoApproves = (run, stage) => normalizeAutoApprove(run.brief.autoApprove).includes(stage);
/**
@@ -810,6 +819,15 @@ const STAGES = {
}
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.
+ const castStage = project.castAndSets;
+ if (castStage?.status === 'failed') {
+ throw runError(500, 'CAST_SETS_FAILED', `Cast & Sets failed: ${castStage.stopReason || castStage.error || 'unknown error'}`);
+ }
+ if (CAST_SETS_WORKING.includes(castStage?.status) && productionReadiness(project).art.problems.length) {
+ await deps.resumeInterruptedCastAndSets(project);
+ return { output: {}, wait: true, step: CAST_STEP };
+ }
const artWasApproved = productionReadiness(project).art.approved;
project = await settleProductionStage(project, run, 'art');
if (!artWasApproved && productionReadiness(project).art.approved) {
@@ -905,9 +923,15 @@ async function advance(projectId) {
}
if (result.wait) {
await patchRun(projectId, (r) => ({ output: result.output, ...stagePatch(r, stage, { status: 'running', step: result.step || null }) }));
- console.log(`🎬 Autonomous music video ${short(run.id)} handed ${stage} to ${result.step === RENDER_STEP ? 'the final render' : 'production'}`);
+ console.log(`🎬 Autonomous music video ${short(run.id)} handed ${stage} to ${result.step === RENDER_STEP ? 'the final render' : result.step === CAST_STEP ? 'Cast & Sets' : 'production'}`);
// The render may have settled before its job id was stored on the run.
if (result.step === RENDER_STEP) await reconcileFinalRender(projectId);
+ // Cast & Sets may likewise have settled while the wait was being stored.
+ // It runs once this loop releases the project, so the re-entry it triggers is not dropped as "already running".
+ else if (result.step === CAST_STEP) {
+ settlement.promise.then(() => reconcileCastAndSets(projectId))
+ .catch((err) => console.error(`❌ Autonomous music video could not settle on Cast & Sets: ${err.message}`));
+ }
return;
}
const next = nextAutonomousStage(stage);
@@ -1156,6 +1180,33 @@ async function onProductionEvent({ projectId, runId, run: production }) {
}
}
+// ---- Cast & Sets completion ------------------------------------------------------
+
+/**
+ * Settle a run waiting on Cast & Sets from the project's own record: still
+ * working → keep waiting; failed → park failed with its error; otherwise
+ * (review/approved/skipped) re-enter `produce`, which now has a guide to review.
+ */
+async function reconcileCastAndSets(projectId) {
+ const project = await getProject(projectId).catch(() => null);
+ const run = projectAutonomousRun(project);
+ if (!run || run.stage !== 'produce' || run.status !== 'running' || run.processId !== PROCESS_ID || run.stages.produce?.step !== CAST_STEP) return;
+ const stage = project.castAndSets;
+ if (CAST_SETS_WORKING.includes(stage?.status)) return;
+ if (stage?.status === 'failed') {
+ const error = trimTo(`Cast & Sets failed: ${stage.stopReason || stage.error || 'unknown error'}`, 500);
+ await patchRun(projectId, (r) => stagePatch(r, 'produce', { status: 'failed', error, step: null }));
+ await park(projectId, 'failed', { error, errorCode: 'CAST_SETS_FAILED' });
+ return;
+ }
+ advanceInBackground(projectId);
+}
+
+musicVideoEvents.on('cast-and-sets', ({ projectId }) => {
+ if (!projectId) return;
+ reconcileCastAndSets(projectId).catch((err) => console.error(`❌ Autonomous music video could not settle on Cast & Sets: ${err.message}`));
+});
+
// ---- final render completion -----------------------------------------------------
/** Park the run as failed on its final render, with the stage marked failed so Retry re-renders only. */
diff --git a/server/services/musicVideo/autonomousService.test.js b/server/services/musicVideo/autonomousService.test.js
index 9317791c6c..c43e5b023f 100644
--- a/server/services/musicVideo/autonomousService.test.js
+++ b/server/services/musicVideo/autonomousService.test.js
@@ -100,6 +100,7 @@ beforeEach(() => {
// The render job stays live until a test settles it with a `render` event.
activeRenderJobId: vi.fn(async () => 'render-1'),
cancelRender: vi.fn(async () => true),
+ resumeInterruptedCastAndSets: vi.fn(async () => false),
};
service.__setAutonomousDepsForTests(doubles);
});
@@ -875,6 +876,55 @@ describe('auto-approve the rest (brief.autoApprove)', () => {
expect(approvals().proof).toBeUndefined();
expect(actual.productionReadiness(store.get('mv-auto')).readyForProduction).toBe(true);
});
+
+ describe('waiting for Cast & Sets before the art gate (#10431)', () => {
+ const setCast = (castAndSets) => { store.get('mv-auto').castAndSets = castAndSets; };
+ const settleCast = (patch) => {
+ Object.assign(store.get('mv-auto').castAndSets, patch);
+ musicVideoEvents.emit('cast-and-sets', { projectId: 'mv-auto', stage: store.get('mv-auto').castAndSets });
+ };
+ const startWithCastDirecting = async (autoApprove) => {
+ reviewFixture();
+ // The guide is not there yet: no artifact on the draft, Cast & Sets still directing.
+ const analyze = doubles.analyzeSong.getMockImplementation();
+ doubles.analyzeSong.mockImplementation(async (...args) => {
+ await analyze(...args);
+ store.get('mv-auto').productionReview.draft.guideArtifactId = null;
+ setCast({ status: 'directing', processId: 'cast-proc', revision: 1, images: {}, plan: {} });
+ });
+ await service.startAutonomousVideo({ prompt: 'p', tools: ['image:local'], ...(autoApprove ? { autoApprove } : {}) }, { autoApproveAuthorized: true });
+ await vi.waitFor(() => expect(runOf()?.stages.produce.step).toBe('cast-and-sets'));
+ };
+
+ it('does not park while Cast & Sets is directing, then auto-approves art once it settles', async () => {
+ await startWithCastDirecting(['art', 'storyboard']);
+ expect(runOf()).toMatchObject({ status: 'running', stage: 'produce' });
+ expect(doubles.approveProductionReview).not.toHaveBeenCalled();
+
+ // The guide lands: direction + sheet, stage in review.
+ store.get('mv-auto').productionReview.draft.guideArtifactId = 'guide';
+ settleCast({ status: 'review', direction: { cast: 'x' }, artifactId: 'guide' });
+ await vi.waitFor(() => expect(doubles.startProduction).toHaveBeenCalledOnce());
+ expect(doubles.approveProductionReview.mock.calls.map(([, input]) => input.stage)).toEqual(['art', 'storyboard']);
+ });
+
+ it('without an art grant parks for a human only after the guide exists', async () => {
+ await startWithCastDirecting();
+ expect(runOf().status).toBe('running');
+ store.get('mv-auto').productionReview.draft.guideArtifactId = 'guide';
+ settleCast({ status: 'review', direction: { cast: 'x' }, artifactId: 'guide' });
+ await settled('needs-human');
+ expect(runOf()).toMatchObject({ errorCode: 'MUSIC_VIDEO_APPROVAL_REQUIRED' });
+ expect(doubles.approveProductionReview).not.toHaveBeenCalled();
+ });
+
+ it('parks failed with the Cast & Sets error when it fails', async () => {
+ await startWithCastDirecting(['art']);
+ settleCast({ status: 'failed', stopReason: 'The character image failed twice' });
+ await settled('failed');
+ expect(runOf()).toMatchObject({ errorCode: 'CAST_SETS_FAILED', error: expect.stringContaining('The character image failed twice') });
+ });
+ });
});
describe('orchestrated mode (brief.orchestrator)', () => {