Skip to content

Show it a video you love. Get a new video in the same style. An AI crew (Claude Code or Codex) plans, builds and reviews it with you.

fix: surface a failed lyric alignment instead of dropping the result

unpack.wasm897221f1b03c
diff --git a/app/server/inputs.ts b/app/server/inputs.ts
index 8364ba3..9b2ef29 100644
--- a/app/server/inputs.ts
+++ b/app/server/inputs.ts
@@ -4,7 +4,7 @@
import { existsSync, mkdirSync, writeFileSync, readdirSync } from 'node:fs';
import { join } from 'node:path';
import { spawnTool } from './runner.ts';
-import { L, PY, ROOT, SCRIPTS, dirOf, load, log, noPython, readJSON, readText, update } from './store.ts';
+import { L, PY, ROOT, SCRIPTS, chat, dirOf, load, log, noPython, readJSON, readText, update } from './store.ts';
import type { Job, Plan, RequiredInput } from '../shared/types.ts';
export function requiredInputs(id: string, plan: Plan | null, job: Job): RequiredInput[] {
@@ -31,10 +31,28 @@ export function provideInput(id: string, inputId: string, saved: string[]) { /
if (!r || !saved.length) return false;
update(id, (j) => { j.provided = { ...(j.provided || {}), [inputId]: saved }; j.waived = (j.waived || []).filter((x) => x !== inputId); });
const txt = r.kind === 'lyrics' && saved.find((f) => /\.txt$/i.test(f)), text = txt && !/(^|\/)lyrics\.txt$/i.test(txt) ? readText(join(d, txt)) : null;
- (text?.trim() ? saveLyrics(id, text) : alignIfReady(id)).catch((e) => console.error(e));
+ void withAlignNotice(id, text?.trim() ? saveLyrics(id, text) : alignIfReady(id));
return true;
}
// Lyrics pasted before the music arrived are only text: time them as soon as there is audio (and again before production).
+// A failed timing used to be invisible to the person who can act on it: `saveLyrics` resolves an
+// `{ ok: false }` result and an `alignIfReady` rejection carries only a message, so both call
+// sites dropped the outcome. Every alignment attempt now ends in a chat line when it fails - the
+// job log keeps the detail, the chat says that it happened and what to do next.
+export function withAlignNotice(id: string, p: Promise<LyricsResult | null>): Promise<LyricsResult | null> {
+ return p
+ .then((r) => {
+ if (r && !r.ok) chat(id, 'system', L(id, '無法為歌詞對時;流程會繼續,之後重新貼上歌詞即可再試一次',
+ 'Lyrics could not be timed; the run continues, and pasting them again later will retry the alignment'));
+ return r;
+ })
+ .catch((e: Error) => {
+ chat(id, 'system', L(id, '無法為歌詞對時;流程會繼續,之後重新貼上歌詞即可再試一次',
+ `Lyrics could not be timed (${e.message}); the run continues`));
+ return null;
+ });
+}
+export const alignIfReadyWithNotice = (id: string) => withAlignNotice(id, alignIfReady(id));
export async function alignIfReady(id: string): Promise<LyricsResult | null> {
const d = dirOf(id);
if (!existsSync(join(d, 'inputs', 'lyrics.txt')) || existsSync(join(d, 'analysis', 'lyrics', 'subs.lrc')) || !musicFile(id)) return null;
diff --git a/app/server/jobs.test.ts b/app/server/jobs.test.ts
index 5aff009..c3e098b 100644
--- a/app/server/jobs.test.ts
+++ b/app/server/jobs.test.ts
@@ -2,12 +2,14 @@
// Runs against a throwaway projects folder (REELMIMIC_PROJECTS), never the real one. No agent is started.
import { after, before, describe, test } from 'node:test';
import assert from 'node:assert/strict';
-import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
+import { existsSync, mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
const TMP = mkdtempSync(join(tmpdir(), 'reelmimic-test-'));
process.env.REELMIMIC_PROJECTS = TMP;
+// Make every python spawn fail in this file's process: the alignment test needs the failure path.
+process.env.PYTHON = 'rr-no-such-python';
const J = await import('./jobs.ts');
after(() => rmSync(TMP, { recursive: true, force: true }));
@@ -146,6 +148,7 @@ describe('project list', () => {
});
const S = await import('./store.ts');
+const I = await import('./inputs.ts');
describe('event log', () => {
test('an event goes to events.jsonl and the snapshot, without rewriting job.json', () => {
const { id } = newJob();
@@ -176,3 +179,19 @@ describe('event log', () => {
assert.equal((J.snapshot(id).job.log[0] as { text?: string }).text, 'old');
});
});
+
+describe('lyric alignment notices', () => {
+ test('a failed alignment is surfaced in the chat instead of vanishing', async () => {
+ const { id } = newJob();
+ mkdirSync(join(J.dirOf(id), 'inputs'), { recursive: true });
+ writeFileSync(join(J.dirOf(id), 'inputs', 'lyrics.txt'), 'la la la\n');
+ writeFileSync(join(J.dirOf(id), 'inputs', 'song.mp3'), '');
+ writePlan(id, { music: { file: 'inputs/song.mp3' } });
+ const r = await I.alignIfReadyWithNotice(id);
+ assert.ok(r === null || r.ok === false, 'alignment must not report success without python');
+ const last = J.load(id).chat.at(-1);
+ assert.equal(last?.role, 'system');
+ assert.match(last?.text || '', /could not be timed|無法為歌詞對時/);
+ assert.ok(!existsSync(join(J.dirOf(id), 'analysis', 'lyrics', 'subs.lrc')), 'no subs.lrc without a run');
+ });
+});
diff --git a/app/server/jobs.ts b/app/server/jobs.ts
index e6810b8..a0ba9c0 100644
--- a/app/server/jobs.ts
+++ b/app/server/jobs.ts
@@ -13,7 +13,7 @@
import { appendFileSync, existsSync, mkdirSync, writeFileSync, readdirSync, cpSync } from 'node:fs';
import { extname, join, relative } from 'node:path';
import { finalPanel } from './final.ts';
-import { openInputs, alignIfReady, requiredInputs } from './inputs.ts';
+import { openInputs, alignIfReadyWithNotice, requiredInputs } from './inputs.ts';
import { flushNotes, fromAnalysis, fromStyle, preProduction } from './preprod.ts';
import { production } from './production.ts';
import { stopPrerenders } from './prerender.ts';
@@ -175,7 +175,7 @@ export async function approve(id: string) {
return run(id, () => approveFlow(id));
}
async function approveFlow(id: string) {
- await alignIfReady(id).catch(() => null); // lyrics pasted before the music arrived: time them now, before anything is built
+ await alignIfReadyWithNotice(id); // lyrics pasted before the music arrived: time them now, before anything is built
update(id, (j) => { j.approvedAt = now(); j.approvedPlanVersion = readJSON<Plan>(join(dirOf(id), 'plan.json'))?.version; j.engineSnapshot = snapshotEngine(id); j.pipeline = {}; j.sessions = j.approvedAtPrev ? {} : Object.fromEntries(Object.entries(j.sessions || {}).filter(([k]) => k.startsWith('cast-'))); j.approvedAtPrev = true; j.needs = []; j.userNote = null; j.critiqueRounds = 0; });
diskWarning(id);
chat(id, 'system', L(id, `企劃已核准,開始生產:角色關 → 分段製作(每段做完立刻審)→ 組裝 → 最後評審`, 'Plan approved. Production: characters → parts built and reviewed as they finish → assembly → final review'));