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 won't verify lyric timings it guessed

Claude4973c2c0aa63
diff --git a/docs/features/music-video-autonomous.md b/docs/features/music-video-autonomous.md
index bb0a5aec83..cf4cb4dd59 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**, 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.
+**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_SETS_FAILED`), 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. It verifies only timings it can trust: when alignment failed or the recognizer heard less than half of the words, the timings are mostly guesses, so it leaves them provisional and parks the run with that reason. 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.
@@ -102,7 +102,7 @@ Choose **Who reviews each step → Orchestrator** in the start drawer to let a m
| Sound & look | start of **Mood board & style** | Approves, or sharpens the song style line, the visual style and the look prompt before the song and mood board are made from them |
| Song | end of **Analyze** | Aligns the vocal to the lyric sheet (and gives skipped lines evenly spaced word timings), then judges duration, sections and the share of lyric words the recognizer heard. A rejected local song is retaken; a Suno song is kept, since a retake spends credits |
| 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 |
+| 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) and logs a verdict with timecoded issues; nothing is re-rendered |
diff --git a/server/services/musicVideo/autonomousService.js b/server/services/musicVideo/autonomousService.js
index d0268963db..5a27cedcaf 100644
--- a/server/services/musicVideo/autonomousService.js
+++ b/server/services/musicVideo/autonomousService.js
@@ -321,26 +321,48 @@ async function orchestrateStyle(projectId, run) {
const cueText = (cue) => (typeof cue?.text === 'string' ? cue.text.trim() : '');
const validSpan = (start, end) => Number.isFinite(start) && Number.isFinite(end) && end > start;
const MIN_WORD_SEC = 0.05;
+// Below this share of recognizer-heard words the timings are mostly interpolated
+// (the aligner itself discards a line below the same share).
+const MIN_HEARD_WORD_SHARE = 0.5;
/**
* Give a lyric line with no usable word timings evenly spaced words inside its
- * own span, else the gap its neighbours leave — what a director does by hand
- * after alignment skips a line. Returns the repaired cues and the line count.
+ * own span, else a share of the gap its neighbours leave — what a director does
+ * by hand after alignment skips a line. Consecutive skipped lines split that gap
+ * by word count rather than each taking all of it. Returns the repaired cues
+ * and the line count.
*/
function repairLyricWordTimings(cues, durationSec) {
+ const wordsOf = cues.map((cue) => cueText(cue).split(/\s+/).filter(Boolean));
+ const usable = (cue) => Array.isArray(cue.words) && cue.words.length > 0 && cue.words.every((w) => validSpan(w.startSec, w.endSec))
+ && validSpan(cue.startSec, cue.endSec) && cue.words.every((w) => w.startSec >= cue.startSec && w.endSec <= cue.endSec);
+ const ownSpan = (cue) => validSpan(cue.startSec, cue.endSec) && cue.endSec <= durationSec;
+ const needs = cues.map((cue, i) => wordsOf[i].length > 0 && !usable(cue));
+ const spans = cues.map(() => null);
+ for (let i = 0; i < cues.length; i += 1) {
+ if (!needs[i]) continue;
+ if (ownSpan(cues[i])) { spans[i] = [cues[i].startSec, cues[i].endSec]; continue; }
+ let last = i;
+ while (last + 1 < cues.length && needs[last + 1] && !ownSpan(cues[last + 1])) last += 1;
+ const prevEnd = i > 0 && Number.isFinite(cues[i - 1].endSec) ? cues[i - 1].endSec : 0;
+ const nextStart = last < cues.length - 1 && Number.isFinite(cues[last + 1].startSec) ? cues[last + 1].startSec : durationSec;
+ const total = wordsOf.slice(i, last + 1).reduce((sum, words) => sum + words.length, 0);
+ let at = prevEnd;
+ for (let k = i; k <= last; k += 1) {
+ const end = k === last ? nextStart : at + ((nextStart - prevEnd) * wordsOf[k].length) / total;
+ spans[k] = [at, end];
+ at = end;
+ }
+ i = last;
+ }
let repaired = 0;
+ const round = (n) => Math.round(n * 1000) / 1000;
const out = cues.map((cue, i) => {
- const words = cueText(cue).split(/\s+/).filter(Boolean);
- if (!words.length) return cue;
- const usable = Array.isArray(cue.words) && cue.words.length > 0 && cue.words.every((w) => validSpan(w.startSec, w.endSec))
- && validSpan(cue.startSec, cue.endSec) && cue.words.every((w) => w.startSec >= cue.startSec && w.endSec <= cue.endSec);
- if (usable) return cue;
- const prevEnd = i > 0 && Number.isFinite(cues[i - 1].endSec) ? cues[i - 1].endSec : 0;
- const nextStart = i < cues.length - 1 && Number.isFinite(cues[i + 1].startSec) ? cues[i + 1].startSec : durationSec;
- const [start, end] = validSpan(cue.startSec, cue.endSec) && cue.endSec <= durationSec ? [cue.startSec, cue.endSec] : [prevEnd, nextStart];
+ if (!spans[i]) return cue;
+ const words = wordsOf[i];
+ const [start, end] = spans[i];
if (!validSpan(start, end) || (end - start) / words.length < MIN_WORD_SEC) return cue;
const step = (end - start) / words.length;
- const round = (n) => Math.round(n * 1000) / 1000;
repaired += 1;
return { ...cue, startSec: round(start), endSec: round(end),
words: words.map((w, k) => ({ w, startSec: round(start + k * step), endSec: round(k === words.length - 1 ? end : start + (k + 1) * step), conf: 'interpolated' })) };
@@ -350,8 +372,10 @@ function repairLyricWordTimings(cues, durationSec) {
/**
* 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.
+ * the timings the storyboard gate needs. Returns the alignment error, if any,
+ * and keeps it on the run (`output.alignmentError`) so the storyboard gate
+ * will not verify guessed timings; 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;
@@ -361,6 +385,9 @@ async function alignRunLyrics(projectId, run) {
const { cues, repaired } = repairLyricWordTimings(current.lyricCues || [], current.audioAnalysis?.durationSec);
return { project: repaired ? { ...current, lyricCues: cues } : current };
});
+ // Bound to the timings it left, so a later re-alignment by hand is judged on its own.
+ const basis = alignError ? productionAlignmentBasis(await getProject(projectId)) : null;
+ await patchRun(projectId, () => ({ output: { alignmentError: alignError ? { message: trimTo(alignError, 300), basis } : null } }));
return alignError;
}
@@ -415,10 +442,13 @@ async function orchestrateSong(projectId, run) {
/**
* 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.
+ * analysis; this records the check of it as the verification a director gives
+ * by listening — by the orchestrator, or by an autopilot the operator granted
+ * storyboard approval. It verifies only when every line has bounded word
+ * timings, alignment ran without error and the recognizer heard at least
+ * `MIN_HEARD_WORD_SHARE` of the words; otherwise the timings are mostly
+ * guesses, so it returns why and leaves them for a director. An instrumental
+ * is marked as one.
*/
async function settleLyricTiming(projectId, run) {
const orchestrated = isOrchestratedRun(run);
@@ -441,9 +471,15 @@ async function settleLyricTiming(projectId, run) {
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 ${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 record('revise', `${notes} Lines without timings need a director.`);
- return;
+ const failedAlignment = projectAutonomousRun(project)?.output?.alignmentError;
+ const alignmentError = failedAlignment?.basis === productionAlignmentBasis(project) ? failedAlignment.message : null;
+ const held = timed < cues.length ? 'Lines without timings need a director.'
+ : alignmentError ? `Lyric alignment failed (${alignmentError}), so these timings are guesses; a director needs to listen and verify them.`
+ : matched / words.length < MIN_HEARD_WORD_SHARE ? 'Too little of the vocal was heard to trust these timings; a director needs to listen and verify them.'
+ : null;
+ if (held) {
+ await record('revise', `${notes} ${held}`);
+ return `${notes} ${held}`;
}
const reviewer = orchestrated ? orchestratorIdentity(run) : { kind: 'autopilot', runId: run.id, authorizedBy: run.brief.autoApproveAuthorizedBy || null };
await deps.verifyAlignment(projectId, { basis: productionAlignmentBasis(project), notes, reviewer });
@@ -851,13 +887,16 @@ const STAGES = {
await prepareProductionReview(project.id);
project = await getProject(project.id);
}
+ let timingHeld = null;
if (isOrchestratedRun(run) || autoApproves(run, 'storyboard')) {
- await settleLyricTiming(project.id, run);
+ timingHeld = 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');
+ // Name why the timing was left unverified rather than only that it is provisional.
+ if (timingHeld && !productionReadiness(project).storyboard.approved) throw runError(409, 'MUSIC_VIDEO_APPROVAL_REQUIRED', trimTo(timingHeld, 500));
assertProductionApproval(project, 'storyboard');
// The authoring stage's pin, else the run's code-authoring pin taken as
// given (production checks it exactly), else the direction LLM.
diff --git a/server/services/musicVideo/autonomousService.test.js b/server/services/musicVideo/autonomousService.test.js
index f7c2de1e65..2479f6dd11 100644
--- a/server/services/musicVideo/autonomousService.test.js
+++ b/server/services/musicVideo/autonomousService.test.js
@@ -999,6 +999,25 @@ describe('autopilot clears the gates it was granted on its own', () => {
expect(doubles.verifyAlignment).not.toHaveBeenCalled();
expect(doubles.startProduction).not.toHaveBeenCalled();
});
+
+ it.each([
+ ['the aligner fails', async () => { throw new Error('aligner offline'); }, 'Lyric alignment failed (aligner offline)'],
+ ['the recognizer hears none of the words', async () => {}, 'Too little of the vocal was heard'],
+ ])('does not verify guessed timings when %s', async (_, align, reason) => {
+ doubles.alignLyrics = stub('align', align);
+ service.__setAutonomousDepsForTests(doubles);
+ analyzed({
+ lyricCues: [{ id: 'c1', text: 'rain on glass', startSec: null, endSec: null }, { id: 'c2', text: 'neon home', startSec: null, endSec: null }],
+ 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()).toMatchObject({ errorCode: 'MUSIC_VIDEO_APPROVAL_REQUIRED', error: expect.stringContaining(reason) });
+ // Skipped lines split the gap by word count instead of each taking the whole song.
+ expect(store.get('mv-auto').lyricCues.map((c) => [c.startSec, c.endSec])).toEqual([[0, 12], [12, 20]]);
+ expect(doubles.verifyAlignment).not.toHaveBeenCalled();
+ expect(doubles.startProduction).not.toHaveBeenCalled();
+ });
});
describe('orchestrated mode (brief.orchestrator)', () => {