commit 17f2a9c64e6c924bd5343ca6bf1ec1995150003f
parent 85f77f737a2c31487c7dc23912a9f74d72787f02
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Tue, 17 Nov 2026 17:01:29 -0500
a card's Pick keeps its review verdict as `narration --pick` does; the queue's marker rule is the route's (review 1)
SHOULD 9: keepCardVerdict (cardNarrationCli.mjs) is the one block `narration --pick` and `reads pick`
run: a verdict given on the card as it played, on the same words, moves to the reading picked.
Nit: a bench read's marker holds an item's queue step by the post-narration route's rule -- while
its job has not ended (the editor asked), or for two minutes when it names no job -- never 45 minutes
for a press that failed (45 minutes only when the editor cannot be asked).
Also: `queue --retry` on a step that cannot be retried is a QueueError (its --json error shape);
enqueueRereads and pickReads take dryRun (what would be queued or picked); a read the model marks
not queueable is skipped with its reason.
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
3 files changed, 109 insertions(+), 16 deletions(-)
diff --git a/umtool/lib/report/cardNarrationCli.mjs b/umtool/lib/report/cardNarrationCli.mjs
@@ -78,6 +78,19 @@ export function nextCardReading(readings, text) {
/** A reading as a line: its key, words, reading, tuning, length -- and whether the card plays it. */
const readingLine = (r, current) => ` ${r.key === current ? "▶" : " "} ${r.key.slice(0, 12)} ${Number(r.seconds).toFixed(2)} s reading ${readingOfRecord(r)}${r.askedTuning ? ` ${Object.entries(r.askedTuning).map(([k, v]) => `${k} ${v}`).join(", ")}` : ""} "${spacing(r.text).slice(0, 70)}"`;
+/**
+ * A VERDICT ON THESE WORDS IS KEPT (lane line-rerun ruling; `narration --pick` and `reads pick`, one rule): the review
+ * keys a verdict by the narration's key, which a reading moves -- a verdict given on the card as it played (`nowKey`,
+ * its key before the pick), on the same words, moves to the reading picked (`rec`). Returns `{ kept, row }`.
+ */
+export async function keepCardVerdict(projectDir, cardId, { nowKey, rec }) {
+ const { readNarrationReview, setNarrationReview } = await import("umtool-report-to-video/narration-review");
+ const row = (await readNarrationReview(projectDir)).rows?.[cardId];
+ const kept = !!row?.verdict && row.key === nowKey && spacing(row.text) === spacing(rec.text);
+ if (kept) await setNarrationReview(projectDir, cardId, { verdict: row.verdict, key: rec.key, text: rec.text });
+ return { kept, row };
+}
+
/** `umtool narration <project> …` */
export async function cardNarrationCommand(args, { root = REPORTS_ROOT, out = (s) => console.log(s), err = (s) => console.error(s), narrate = null } = {}) {
const flags = new Map();
@@ -146,12 +159,7 @@ export async function cardNarrationCommand(args, { root = REPORTS_ROOT, out = (s
const want = resolveNarration({ ...e, narration: { ...e.narration, text: patch.text, reading: patch.reading ?? undefined, tuning: patch.tuning ?? undefined } }, manifest.render);
if (narrationKey(want) !== rec.key) throw new NarrateError(`${cardId}: reading ${rec.key.slice(0, 12)} was made with another voice or speed than the card's now -- read it again (--read)`);
const { result } = await write(patch);
- // A VERDICT ON THESE WORDS IS KEPT (lane line-rerun ruling): the review keys a verdict by the narration's key,
- // which a reading moves -- a verdict given on the card as it played, on the same words, moves with the pick.
- const { readNarrationReview, setNarrationReview } = await import("umtool-report-to-video/narration-review");
- const row = (await readNarrationReview(project.dir)).rows?.[cardId];
- const kept = !!row?.verdict && row.key === now.key && spacing(row.text) === spacing(rec.text);
- if (kept) await setNarrationReview(project.dir, cardId, { verdict: row.verdict, key: rec.key, text: rec.text });
+ const { kept, row } = await keepCardVerdict(project.dir, cardId, { nowKey: now.key, rec });
if (json) out(JSON.stringify({ ok: true, id: cardId, key: rec.key, narration: result.entry.narration, verdictKept: kept, token: result.token ?? null }, null, 2));
else out(`${cardId}: plays reading ${readingOfRecord(rec)} (${rec.key.slice(0, 12)})${kept ? ` -- still ${row.verdict} (the same words)` : ""}`);
return 0;
diff --git a/umtool/lib/report/readsQueue.mjs b/umtool/lib/report/readsQueue.mjs
@@ -97,6 +97,7 @@ export async function enqueueRereads(project, o = {}) {
for (const r of want) {
if (r.state === "recorded") skipped.push({ id: r.id, why: "a recorded read is yours: record it again" });
else if (r.state === "fresh") skipped.push({ id: r.id, why: "fresh: nothing to re-read" });
+ else if (r.queueable === false) skipped.push({ id: r.id, why: r.why ?? "not re-read here" });
else pick.push(r);
}
const qdir = queueDirFor(o);
@@ -113,6 +114,10 @@ export async function enqueueRereads(project, o = {}) {
}
const made = [];
const rowsOut = [];
+ if (o.dryRun) {
+ const plan = [...byItem].sort((a, b) => a[1][0].n - b[1][0].n).map(([item, rs]) => ({ qid: null, item, reads: rs.map((r) => r.id) }));
+ return { batches, result: { batch: null, steps: plan, skipped, dryRun: true } };
+ }
for (const [item, rs] of [...byItem].sort((a, b) => a[1][0].n - b[1][0].n)) {
const ids = rs.map((r) => r.id);
const step = await addStep(qdir, {
@@ -134,17 +139,46 @@ export async function enqueueRereads(project, o = {}) {
});
}
-/** Whether a bench read of post item `e` is in flight (the take op's marker, young and naming a job not yet kept). */
-export async function benchReadInFlight(dir, e, { now = Date.now() } = {}) {
+/** A bench read's marker with no job yet counts as in flight this long (the post-narration route's own rule). */
+export const BENCH_STARTING_MS = 2 * 60 * 1000;
+
+/**
+ * Whether an editor job has ENDED (done, failed, cancelled): the editor asked (`GET /api/ops/job/<id>`); null when it
+ * cannot be asked (no editor, no token, no answer) -- the caller then falls back on the marker's age.
+ */
+export async function editorJobEnded(jobId, { env = process.env } = {}) {
+ try {
+ const { editorConfig } = await import("./fetchWindows.mjs");
+ const cfg = editorConfig(env);
+ if (!cfg.token) return null;
+ const r = await fetch(`${cfg.url}/api/ops/job/${encodeURIComponent(jobId)}`, { headers: { authorization: `Bearer ${cfg.token}` }, signal: AbortSignal.timeout(5000) });
+ const j = await r.json().catch(() => null);
+ if (!r.ok || !j?.job) return null;
+ return !["queued", "running"].includes(String(j.job.status));
+ } catch {
+ return null;
+ }
+}
+
+/**
+ * Whether a bench read of post item `e` is in flight -- the take op's marker, by the route's rule: a marker naming a
+ * job is in flight while that job has not ended; one with no job yet, for its first two minutes. A marker whose take
+ * is already kept, or whose job the editor says ended, holds nothing. `jobEnded(jobId)` is editorJobEnded (a test's
+ * stub); when the editor cannot say, the marker counts for BENCH_MARKER_MS.
+ */
+export async function benchReadInFlight(dir, e, { now = Date.now(), jobEnded = editorJobEnded } = {}) {
if (e?.type !== "post") return null;
const file = path.join(dir, ...takesDirOf(postIdOf(e)).split("/"), ".reading.json");
const st = await stat(file).catch(() => null);
if (!st) return null;
const marker = await readFile(file, "utf8").then(JSON.parse, () => null);
const at = Date.parse(String(marker?.at ?? "")) || st.mtimeMs;
- if (now - at > BENCH_MARKER_MS) return null;
if (marker?.file && (e.narration?.takes ?? []).some((t) => t?.file === marker.file)) return null;
- return { at: new Date(at).toISOString(), jobId: marker?.jobId ?? null };
+ if (!marker?.jobId) return now - at < BENCH_STARTING_MS ? { at: new Date(at).toISOString(), jobId: null } : null;
+ const ended = await jobEnded(String(marker.jobId));
+ if (ended === true) return null;
+ if (ended === null && now - at > BENCH_MARKER_MS) return null;
+ return { at: new Date(at).toISOString(), jobId: marker.jobId };
}
/**
@@ -153,7 +187,7 @@ export async function benchReadInFlight(dir, e, { now = Date.now() } = {}) {
* `run(argv)` runs a umtool argv (default: the CLI's own dispatch); `tts` / `narrate` the editor's ops as a test hands
* them (postsCommand's `tts`, cardNarrationCommand's `narrate`).
*/
-export async function runOneItem(project, item, ids, { reportsRoot = REPORTS_ROOT, run = null, log = (s) => console.log(s), tts = null, narrate = null } = {}) {
+export async function runOneItem(project, item, ids, { reportsRoot = REPORTS_ROOT, run = null, log = (s) => console.log(s), tts = null, narrate = null, jobEnded = undefined } = {}) {
const { rows, ctx } = await projectReads(project, { reportsRoot });
const e = ctx.manifest.timeline.find((x) => x?.id === item);
if (!e) throw new QueueError(`${item} is not in the cut any more`);
@@ -163,7 +197,7 @@ export async function runOneItem(project, item, ids, { reportsRoot = REPORTS_ROO
log(`${item}: nothing to re-read now (its reads are fresh, or re-read and waiting for a pick)`);
return { code: 0, argv: null, reads: [] };
}
- const inFlight = await benchReadInFlight(project.dir, e);
+ const inFlight = await benchReadInFlight(project.dir, e, jobEnded ? { jobEnded } : {});
if (inFlight) throw new QueueError(`${item}: a read of this post is being made on its bench (since ${inFlight.at}) -- retry when it lands`);
const argv = itemRereadArgv(project.id, e, reads);
log(`${item}: re-reading ${reads.map((r) => r.id).join(", ")} -- umtool ${argv.join(" ")}`);
@@ -244,7 +278,11 @@ export async function retryRead(project, readId, o = {}) {
const qdir = queueDirFor(o);
const row = (await readBatches(project.dir)).flatMap((b) => b.rows).reverse().find((r) => r.read === readId);
if (!row) throw new QueueError(`${readId} was never queued (umtool reads ${project.id} reread --only ${readId})`);
- return retryStep(qdir, row.qid);
+ try {
+ return await retryStep(qdir, row.qid);
+ } catch (err) {
+ throw new QueueError(`${readId}: ${err instanceof Error ? err.message : String(err)}`);
+ }
}
/**
@@ -253,7 +291,7 @@ export async function retryRead(project, readId, o = {}) {
* before (a card: its reading before, words and all). `only`: those read ids. ONE structural write, its own undo point.
* Returns `{ picked: [{ item, take?, key? }], result }`.
*/
-export async function pickReads(project, { which = "new", only = null, token = null, reportsRoot = REPORTS_ROOT } = {}) {
+export async function pickReads(project, { which = "new", only = null, token = null, reportsRoot = REPORTS_ROOT, dryRun = false } = {}) {
if (which !== "new" && which !== "old") throw new QueueError("pick takes --new or --old");
const keep = only?.length ? new Set(only) : null;
const picks = new Map();
@@ -272,21 +310,28 @@ export async function pickReads(project, { which = "new", only = null, token = n
}
}
if (!picks.size) throw new QueueError(which === "new" ? "no read waits for a pick (no unpicked re-read)" : "no re-read to go back from (the newest batch has none)");
+ if (dryRun) return { picked: [...picks.values()], result: null, dryRun: true };
const { cardReadings, readingOfRecord } = await import("./cardNarrationCli.mjs");
const cards = new Map();
for (const x of picks.values()) {
if (!x.key) continue;
const rec = (await cardReadings(project.dir, x.item)).find((r) => r.key === x.key);
if (!rec) throw new QueueError(`${x.item}: its reading ${x.key.slice(0, 12)} is not kept any more`);
- cards.set(x.item, { text: rec.text, reading: readingOfRecord(rec) > 0 ? readingOfRecord(rec) : null, tuning: rec.askedTuning ?? null });
+ cards.set(x.item, { text: rec.text, reading: readingOfRecord(rec) > 0 ? readingOfRecord(rec) : null, tuning: rec.askedTuning ?? null, rec });
}
+ // Each card's key as it plays now: a verdict given on it moves with a pick of the same words (keepCardVerdict).
+ const { narrationsOf } = await import("umtool-report-to-video/narration");
+ const { readManifest } = await import("../projects/report.mjs");
+ const keysNow = new Map(narrationsOf((await readManifest(project.dir)) ?? {}).map((n) => [n.id, n.key]));
const { cardNarrationIn, manifestToken, postNarrationIn, structuralEdit } = await import("./manifest.mjs");
const { withEditNotes } = await import("./edit-guard.mjs");
const tok = token ?? (await manifestToken(project.dir));
const { result } = await withEditNotes(project, async () => structuralEdit(project.dir, "reads-pick", tok, (m) => {
for (const x of picks.values()) {
if (x.key) {
- cardNarrationIn(m, x.item, cards.get(x.item));
+ const { rec: _r, ...patch } = cards.get(x.item);
+ void _r;
+ cardNarrationIn(m, x.item, patch);
continue;
}
const e = m.timeline.find((y) => y?.id === x.item);
@@ -298,6 +343,9 @@ export async function pickReads(project, { which = "new", only = null, token = n
}
return { items: [...picks.keys()] };
}, { snapshotEvery: 0 }));
+ // A VERDICT ON THESE WORDS IS KEPT, exactly as `narration --pick` keeps it (cardNarrationCli.mjs keepCardVerdict).
+ const { keepCardVerdict } = await import("./cardNarrationCli.mjs");
+ for (const [id, c] of cards) await keepCardVerdict(project.dir, id, { nowKey: keysNow.get(id) ?? null, rec: c.rec });
return { picked: [...picks.values()], result };
}
diff --git a/umtool/lib/report/readsQueue.test.mjs b/umtool/lib/report/readsQueue.test.mjs
@@ -185,3 +185,40 @@ test("a bench read of the post in flight holds its step back (retryable); a read
assert.equal(ran, 0);
void readFile;
});
+
+// REVIEW 1, SHOULD 9: a Pick on a card keeps its review verdict exactly as `narration --pick` does -- a verdict given on
+// the card as it played, on the same words, moves to the reading picked.
+test("SHOULD 9: reads pick on a card keeps a verdict given on the same words", async () => {
+ const p = await readsProject(ROOT, "verdict");
+ const { narrationsOf } = await import("umtool-report-to-video/narration");
+ const { readNarrationReview, setNarrationReview } = await import("umtool-report-to-video/narration-review");
+ const m = await readManifestOf(p);
+ const n0 = narrationsOf(m).find((x) => x.id === "c-1");
+ await setNarrationReview(p.dir, "c-1", { verdict: "approved", key: n0.key, text: n0.text });
+ // Another reading of the same words kept (reading 1), and a batch whose "before" is it.
+ const n1 = narrationsOf({ ...m, timeline: m.timeline.map((e) => (e.id === "c-1" ? { ...e, narration: { ...e.narration, reading: 1 } } : e)) }).find((x) => x.id === "c-1");
+ await keepCardReading(p.dir, { ...n1, reading: 1 }, { createdAt: "2026-11-03T00:00:00.000Z" });
+ await mkdir(path.join(p.dir, "narration", "reads"), { recursive: true });
+ await writeFile(path.join(p.dir, "narration", "reads", "queue.json"), JSON.stringify({ version: 1, batches: [{ id: "b1", at: "2026-11-03T00:00:00.000Z", rows: [{ read: "c-1", item: "c-1", kind: "card", qid: "q1", before: { index: null, file: null, key: n1.key } }] }] }));
+ await pickReads(p, { which: "old", only: ["c-1"], reportsRoot: p.root });
+ assert.equal((await readManifestOf(p)).timeline[3].narration.reading, 1);
+ const row = (await readNarrationReview(p.dir)).rows["c-1"];
+ assert.deepEqual([row.verdict, row.key], ["approved", n1.key]);
+});
+
+// REVIEW 1, a nit: a bench marker holds the item's step only by the route's rule -- its job not ended, or (no job yet)
+// for two minutes -- never 45 minutes for a press that failed.
+test("a bench marker: in flight while its job runs; not once its job ended; a jobless one only for two minutes", async () => {
+ const { benchReadInFlight } = await import("./readsQueue.mjs");
+ const p = await readsProject(ROOT, "marker");
+ const e = (await readManifestOf(p)).timeline[0];
+ const marker = path.join(p.dir, "narration", "posts", "1", ".reading.json");
+ const put = (o) => writeFile(marker, JSON.stringify(o));
+ await put({ jobId: "job-1", file: "narration/posts/1/take-9.orpheus-tara.wav", at: new Date().toISOString() });
+ assert.ok(await benchReadInFlight(p.dir, e, { jobEnded: async () => false }));
+ assert.equal(await benchReadInFlight(p.dir, e, { jobEnded: async () => true }), null, "its job ended: a failed press holds nothing");
+ await put({ starting: true, at: new Date(Date.now() - 3 * 60 * 1000).toISOString() });
+ assert.equal(await benchReadInFlight(p.dir, e, { jobEnded: async () => false }), null, "no job after two minutes: stale");
+ await put({ starting: true, at: new Date().toISOString() });
+ assert.ok(await benchReadInFlight(p.dir, e, { jobEnded: async () => false }));
+});