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 gets past the art and storyboard gates on its own

Claudeed6a3c0696c3
diff --git a/docs/features/music-video-autonomous.md b/docs/features/music-video-autonomous.md
index a89b27a348..bb0a5aec83 100644
--- a/docs/features/music-video-autonomous.md
+++ b/docs/features/music-video-autonomous.md
@@ -86,7 +86,7 @@ The review panel shows the selected visual guide and its version, the saved stor
A proof approval is bound to its exact excerpt ID and filename; `energyComparison` and `timecodedNotes` are optional notes. Human playback uses `watchedWithAudio: true`. An authenticated agent can submit `method: 'machine'`, `watchedWithAudio: false`, and `machineEvidence` containing substantive `visualReview`, `audioReview`, and `limitations`, alongside the same excerpt ID and filename. The observations must come from actual motion and audio review against the saved plan; technical validation, isolated still frames or a completed render do not establish choreography quality. If the available tools cannot assess motion and audio, leave approval pending. The UI distinguishes machine review from playback. Persisted automatic waivers no longer count as approved proof; valid art and playback decisions remain valid.
-**Automatic planning approvals.** An authenticated start or `POST /api/music-video/:id/autonomous/resume` can grant `autoApprove: ['art', 'storyboard']` (any subset). The run records `brief.autoApprove`, `brief.autoApproveAuthorizedAt`, and `brief.autoApproveAuthorizedBy`; automatic decisions also record the run ID. A resume list replaces the grant; explicit `[]` revokes it and also requires authentication. Omitting the list preserves the existing policy. In **Produce**, automatic planning approval requires a clean readiness report; provisional timings or other open problems still park the run. Proof is never auto-approved; a legacy brief listing `proof` is ignored for it, since the final render no longer waits on a proof. Start drawer and run panel expose the planning choices without a password field, and the run panel shows existing grants so they can be revoked.
+**Automatic planning approvals.** An authenticated start or `POST /api/music-video/:id/autonomous/resume` can grant `autoApprove: ['art', 'storyboard']` (any subset). The run records `brief.autoApprove`, `brief.autoApproveAuthorizedAt`, and `brief.autoApproveAuthorizedBy`; automatic decisions also record the run ID. A resume list replaces the grant; explicit `[]` revokes it and also requires authentication. Omitting the list preserves the existing policy. In **Produce**, the run first waits for Cast & Sets to draft the art guide (`stages.produce.step: 'cast-and-sets'`; its settle event carries the run on, and a failed Cast & Sets fails the run with `CAST_AND_SETS_FAILED` so Retry starts it again), so the art gate is never judged empty. A `storyboard` grant also makes the run do the lyric-timing chores a director would: after analysis it aligns the vocal to the lyric sheet and times lines alignment skipped, then before the storyboard gate it verifies the timing (reviewer `{ kind: 'autopilot', runId }`), marks an instrumental song as one, and anchors each shot to the lyric lines it overlaps. Automatic planning approval still requires a clean readiness report; a line it cannot time, or any other open problem, still parks the run. Proof is never auto-approved; a legacy brief listing `proof` is ignored for it, since the final render no longer waits on a proof. Start drawer and run panel expose the planning choices without a password field, and the run panel shows existing grants so they can be revoked.
External draft preparation uses the existing authenticated session without password re-entry; agents may prepare drafts. PortOS never submits a final post: review and publish on the destination platform, then record the resulting link. Existing projects and assets remain intact, but an older project's final render now requires the same production review.
diff --git a/server/services/musicVideo/autonomousService.js b/server/services/musicVideo/autonomousService.js
index b34ed1a82d..d0268963db 100644
--- a/server/services/musicVideo/autonomousService.js
+++ b/server/services/musicVideo/autonomousService.js
@@ -348,6 +348,22 @@ function repairLyricWordTimings(cues, durationSec) {
return { cues: out, repaired };
}
+/**
+ * Align the vocal to the lyric sheet and time the lines alignment skipped —
+ * the timings the storyboard gate needs. Returns the alignment error, if any;
+ * the repair still runs so a failed alignment leaves what it can.
+ */
+async function alignRunLyrics(projectId, run) {
+ if (run.brief.instrumental || !(await getProject(projectId))?.lyricCues?.some((c) => cueText(c))) return null;
+ let alignError = null;
+ await deps.alignLyrics(projectId).catch((err) => { alignError = err.message; });
+ await mutateProjectRecord(projectId, (current) => {
+ const { cues, repaired } = repairLyricWordTimings(current.lyricCues || [], current.audioAnalysis?.durationSec);
+ return { project: repaired ? { ...current, lyricCues: cues } : current };
+ });
+ return alignError;
+}
+
/** The song as measurements: analysis plus how much of the written lyric the recognizer heard. */
function songFacts(project, run, alignError) {
const analysis = project.audioAnalysis || {};
@@ -377,14 +393,7 @@ function songFacts(project, run, alignError) {
* credits the operator did not approve, so that song is kept and the reason logged.
*/
async function orchestrateSong(projectId, run) {
- let alignError = null;
- if (!run.brief.instrumental && (await getProject(projectId))?.lyricCues?.some((c) => cueText(c))) {
- await deps.alignLyrics(projectId).catch((err) => { alignError = err.message; });
- await mutateProjectRecord(projectId, (current) => {
- const { cues, repaired } = repairLyricWordTimings(current.lyricCues || [], current.audioAnalysis?.durationSec);
- return { project: repaired ? { ...current, lyricCues: cues } : current };
- });
- }
+ const alignError = await alignRunLyrics(projectId, run);
const { buildSongReviewPrompt } = await reviewModule();
const project = await getProject(projectId);
const facts = songFacts(project, run, alignError);
@@ -405,12 +414,16 @@ async function orchestrateSong(projectId, run) {
}
/**
- * Verify the lyric timing for the storyboard gate. Alignment already ran at the
- * song checkpoint; this records the orchestrator's check of it (every line has
- * bounded word timings) as the verification a director gives by listening.
- * An instrumental is marked as one. Problems it cannot fix stay for readiness to name.
+ * Verify the lyric timing for the storyboard gate. Alignment already ran after
+ * analysis; this records the check of it (every line has bounded word timings)
+ * as the verification a director gives by listening — by the orchestrator, or
+ * by an autopilot the operator granted storyboard approval. An instrumental is
+ * marked as one. Problems it cannot fix stay for readiness to name.
*/
-async function orchestrateAlignment(projectId, run) {
+async function settleLyricTiming(projectId, run) {
+ const orchestrated = isOrchestratedRun(run);
+ const record = (verdict, notes) => (orchestrated
+ ? recordReview(projectId, { checkpoint: 'alignment', verdict, score: null, notes, route: null, visual: false }) : null);
const project = await getProject(projectId);
const draft = project.productionReview?.draft;
if (!draft || draft.storyboardSource === 'document') return;
@@ -421,19 +434,20 @@ async function orchestrateAlignment(projectId, run) {
if (!run.brief.instrumental) return;
await mutateProjectRecord(projectId, (current) => ({ project: { ...current, productionReview: { ...current.productionReview,
draft: { ...current.productionReview.draft, lyricsMode: 'instrumental', timingNotes: 'Instrumental song: no lyric timing to verify.' } } } }));
- await recordReview(projectId, { checkpoint: 'alignment', verdict: 'approve', score: null, notes: 'Instrumental song: no lyric timing to verify.', route: null, visual: false });
+ await record('approve', 'Instrumental song: no lyric timing to verify.');
return;
}
const words = cues.flatMap((c) => c.words || []);
const timed = cues.filter((c) => c.words?.length && validSpan(c.startSec, c.endSec)).length;
const matched = words.filter((w) => w.conf === 'matched').length;
- const notes = `Checked by the orchestrator: ${timed} of ${cues.length} lines carry word timings; ${matched} of ${words.length} words were heard by the recognizer, the rest interpolated.`;
+ const notes = `Checked by the ${orchestrated ? 'orchestrator' : 'autopilot'}: ${timed} of ${cues.length} lines carry word timings; ${matched} of ${words.length} words were heard by the recognizer, the rest interpolated.`;
if (timed < cues.length) {
- await recordReview(projectId, { checkpoint: 'alignment', verdict: 'revise', score: null, notes: `${notes} Lines without timings need a director.`, route: null, visual: false });
+ await record('revise', `${notes} Lines without timings need a director.`);
return;
}
- await deps.verifyAlignment(projectId, { basis: productionAlignmentBasis(project), notes, reviewer: orchestratorIdentity(run) });
- await recordReview(projectId, { checkpoint: 'alignment', verdict: 'approve', score: null, notes, route: null, visual: false });
+ const reviewer = orchestrated ? orchestratorIdentity(run) : { kind: 'autopilot', runId: run.id, authorizedBy: run.brief.autoApproveAuthorizedBy || null };
+ await deps.verifyAlignment(projectId, { basis: productionAlignmentBasis(project), notes, reviewer });
+ await record('approve', notes);
}
/** Anchor every storyboard shot to the lyric lines it overlaps (the "Review lyric anchors" chore). */
@@ -797,6 +811,8 @@ const STAGES = {
async analyze({ project, run }) {
await deps.analyzeSong(project.id);
+ // A storyboard grant needs the lyric timings production verifies, so the autopilot aligns too.
+ if (!isOrchestratedRun(run) && autoApproves(run, 'storyboard')) await alignRunLyrics(project.id, run);
if (isOrchestratedRun(run) && (await orchestrateSong(project.id, run)).retake) {
// A local fallback stays local: the retake must not send the run back to Suno.
const reset = Object.fromEntries(SONG_OUTPUT_KEYS.filter((key) => key !== 'songSource' && key !== 'songFallbackReason').map((key) => [key, null]));
@@ -835,8 +851,10 @@ const STAGES = {
await prepareProductionReview(project.id);
project = await getProject(project.id);
}
- if (isOrchestratedRun(run)) {
- await orchestrateAlignment(project.id, run);
+ if (isOrchestratedRun(run) || autoApproves(run, 'storyboard')) {
+ await settleLyricTiming(project.id, run);
+ // The orchestrator anchors inside its storyboard review; the autopilot does it here.
+ if (!isOrchestratedRun(run)) await anchorStoryboardLyrics(project.id);
project = await getProject(project.id);
}
project = await settleProductionStage(project, run, 'storyboard');
diff --git a/server/services/musicVideo/autonomousService.test.js b/server/services/musicVideo/autonomousService.test.js
index c43e5b023f..9fa76034b0 100644
--- a/server/services/musicVideo/autonomousService.test.js
+++ b/server/services/musicVideo/autonomousService.test.js
@@ -24,7 +24,7 @@ vi.mock('./productionReviewService.js', () => ({
* checkpoints, failure parking and retry, and the hand-off to production.
*/
-import { describe, it, expect, vi, beforeEach } from 'vitest';
+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
const store = new Map();
let writeTail = Promise.resolve();
@@ -927,6 +927,129 @@ describe('auto-approve the rest (brief.autoApprove)', () => {
});
});
+describe('autopilot clears the gates it was granted on its own', () => {
+ let actual;
+ let prepare;
+ beforeEach(async () => {
+ creativeReview.real = true;
+ actual = await vi.importActual('./productionReview.js');
+ ({ prepareProductionReview: prepare } = await import('./productionReviewService.js'));
+ doubles.approveProductionReview = stub('approve', async (id, input) => {
+ store.set(id, clone(actual.approveProductionStage(clone(store.get(id)), input)));
+ });
+ doubles.verifyAlignment = stub('verify', async (id, { basis, notes, reviewer }) => {
+ const project = store.get(id);
+ project.productionReview = { ...project.productionReview, alignmentBasis: basis, alignmentReview: { basis, reviewer },
+ draft: { ...project.productionReview.draft, timingStatus: 'verified', timingNotes: notes } };
+ });
+ doubles.alignLyrics = stub('align', async () => {});
+ doubles.castAndSetsStage = vi.fn(async (id) => ({ ...store.get(id).castAndSets, interrupted: false }));
+ doubles.resumeCastAndSets = stub('resume-cast', async () => {});
+ service.__setAutonomousDepsForTests(doubles);
+ });
+ afterEach(() => { prepare.mockReset(); prepare.mockImplementation(async () => {}); });
+
+ const GUIDE = { cast: 'Paper dancer', environments: 'Theatre', visualLanguage: 'Ink silhouettes', motionLanguage: 'Slow orbit', guideArtifactId: 'guide' };
+ const shot = { sceneId: 'shot', lyricCueIds: [], action: 'Dancer unfolds', staging: 'Wide theatre', camera: 'Orbit', transition: 'Fade' };
+ const analyzed = (extra) => doubles.analyzeSong.mockImplementation(async () => {
+ Object.assign(store.get('mv-auto'), {
+ audioAnalysis: { durationSec: 20, sections: [{ id: 'chorus', label: 'Chorus', startSec: 0, endSec: 20 }] },
+ scenes: [{ sceneId: 'shot', startSec: 0, endSec: 20, label: 'Chorus' }],
+ devArtifacts: [{ id: 'guide', version: 1, file: 'guide.html', mimeType: 'text/html' }],
+ ...extra,
+ });
+ });
+ const GRANT = [{ autoApprove: ['art', 'storyboard'] }, { autoApproveAuthorized: true }];
+
+ it('aligns, times and verifies the lyrics of a vocal song, then approves the storyboard', async () => {
+ analyzed({
+ lyricCues: [
+ { id: 'c1', text: 'rain on glass', startSec: 1, endSec: 4, words: [
+ { w: 'rain', startSec: 1, endSec: 2, conf: 'matched' }, { w: 'on', startSec: 2, endSec: 3, conf: 'matched' }, { w: 'glass', startSec: 3, endSec: 4, conf: 'matched' }] },
+ { id: 'c2', text: 'neon home', startSec: null, endSec: null },
+ ],
+ productionReview: { draft: { ...GUIDE, lyricsMode: 'vocal', timingStatus: 'provisional', timingNotes: '', 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');
+ expect(doubles.alignLyrics).toHaveBeenCalledWith('mv-auto');
+ expect(project.lyricCues[1]).toMatchObject({ startSec: 4, endSec: 20, words: [{ w: 'neon', conf: 'interpolated' }, { w: 'home' }] });
+ expect(project.productionReview.alignmentReview.reviewer).toMatchObject({ kind: 'autopilot', runId: runOf().id });
+ expect(project.productionReview.draft.storyboard[0].lyricCueIds).toEqual(['c1', 'c2']);
+ expect(project.productionReview.approvals).toMatchObject({ art: { approvedBy: 'autopilot' }, storyboard: { approvedBy: 'autopilot' } });
+ });
+
+ 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]);
+ await vi.waitFor(() => expect(doubles.startProduction).toHaveBeenCalledOnce());
+ expect(store.get('mv-auto').productionReview.draft.lyricsMode).toBe('instrumental');
+ expect(doubles.alignLyrics).not.toHaveBeenCalled();
+ });
+
+ it('still parks for a human on a lyric line it cannot time', async () => {
+ analyzed({
+ audioAnalysis: { durationSec: 20 },
+ lyricCues: [{ id: 'c1', text: 'rain on glass', startSec: null, endSec: null }, { id: 'c2', text: 'neon home', startSec: 0, endSec: 20,
+ words: [{ w: 'neon', startSec: 0, endSec: 10, conf: 'matched' }, { w: 'home', startSec: 10, endSec: 20, conf: 'matched' }] }],
+ productionReview: { draft: { ...GUIDE, lyricsMode: 'vocal', timingStatus: 'provisional', storyboard: [shot] } },
+ });
+ await service.startAutonomousVideo({ prompt: 'p', tools: ['image:local'], ...GRANT[0] }, GRANT[1]);
+ await settled('needs-human');
+ expect(runOf().errorCode).toBe('MUSIC_VIDEO_APPROVAL_REQUIRED');
+ expect(doubles.verifyAlignment).not.toHaveBeenCalled();
+ expect(doubles.startProduction).not.toHaveBeenCalled();
+ });
+
+ // Cast & Sets drafts the guide after produce starts; its settle event carries the run on.
+ const castRunning = () => {
+ analyzed({ productionReview: { draft: { lyricsMode: 'instrumental', timingNotes: 'Instrumental.', storyboard: [shot] } } });
+ prepare.mockImplementation(async (id) => {
+ const project = store.get(id);
+ if (!project.castAndSets) project.castAndSets = { status: 'directing' };
+ if (project.castAndSets.status === 'approved') project.productionReview.draft = { ...project.productionReview.draft, ...GUIDE };
+ });
+ };
+ const settleCast = async (status, extra = {}) => {
+ store.get('mv-auto').castAndSets = { status, ...extra };
+ musicVideoEvents.emit('cast-and-sets', { projectId: 'mv-auto', stage: { status, interrupted: false } });
+ await service.__testing.settleBackground();
+ };
+
+ it('waits for Cast & Sets instead of parking at an empty art gate, then approves art and continues', async () => {
+ castRunning();
+ await service.startAutonomousVideo({ prompt: 'p', tools: ['image:local'], ...GRANT[0] }, GRANT[1]);
+ await vi.waitFor(() => expect(runOf().stages.produce).toMatchObject({ status: 'running', step: 'cast-and-sets' }));
+ await service.__testing.settleBackground();
+ expect(runOf().status).toBe('running');
+ expect(doubles.approveProductionReview).not.toHaveBeenCalled();
+
+ await settleCast('approved');
+ await vi.waitFor(() => expect(doubles.startProduction).toHaveBeenCalledOnce());
+ expect(store.get('mv-auto').productionReview.approvals.art).toMatchObject({ approvedBy: 'autopilot' });
+ });
+
+ it('without an art grant parks for a human only once the guide exists, and a failed Cast & Sets fails the run', async () => {
+ castRunning();
+ await service.startAutonomousVideo({ prompt: 'p', tools: ['image:local'] });
+ await vi.waitFor(() => expect(runOf().stages.produce.step).toBe('cast-and-sets'));
+ await service.__testing.settleBackground();
+ await settleCast('approved');
+ await settled('needs-human');
+ expect(store.get('mv-auto').productionReview.draft.guideArtifactId).toBe('guide');
+
+ store.get('mv-auto').castAndSets = null;
+ store.get('mv-auto').productionReview.draft = { lyricsMode: 'instrumental', storyboard: [shot] };
+ await service.resumeAutonomousVideo('mv-auto');
+ await vi.waitFor(() => expect(runOf().stages.produce.step).toBe('cast-and-sets'));
+ await service.__testing.settleBackground();
+ await settleCast('failed', { stopReason: 'The image backend is offline' });
+ await settled('failed');
+ expect(runOf()).toMatchObject({ status: 'failed', errorCode: 'CAST_AND_SETS_FAILED', error: expect.stringContaining('image backend is offline') });
+ });
+});
+
describe('orchestrated mode (brief.orchestrator)', () => {
const ORCHESTRATOR = { providerId: 'orch', model: 'judge', effort: 'high' };
let answers;