commit 97ba85133f3884e87d468f5941d2ceb60d89c270
parent 4bb8bbd815285c9650cc849a8a55b05e93cce9f4
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Sat, 21 Nov 2026 21:21:18 -0500
record-live: the shutdown-resume flow pinned; a waiting part is nobody's to land; a stale transcript asked again
- The boot pass's resume clears the stem from the interrupted row's
awaitingResume; a part an earlier run left waiting (its state there)
is not landed, removed or counted by a run that did not resume it, is
listed on that run's row, and the row needs a person.
- A whole file that replaces a stored shorter container asks for the
transcription again when the transcript is the short one's, told by the
transcript itself: its last cue ends no later than the replaced length
plus 60 s while the new file runs on more than 60 s past it
(transcriptRedo "shorter", the job on the row). Not tellable (the
transcript does not read or parse, holds no cues, the replaced length
is unknown): "unknown", nothing asked, the row needs a person; so does
a "shorter" whose ask was refused or could not be made.
- The slice-2 "recovered by coverage" branch is gone: a recovery part is
never proven, so it could not be reached; the docs say what happens.
- Tests: the exact flow shutdown -> real boot pass -> resume in place ->
the stream ends -> one whole file lands, nothing left; a waiting part
untouched by a later Record again; a boot resume of an unproven part
earns no mark; a shutdown's stored landing replaced by a whole
from-start run (REVIEW-LF-4 4); the transcript redo's four cases.
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
7 files changed, 374 insertions(+), 16 deletions(-)
diff --git a/OPERATING.md b/OPERATING.md
@@ -1476,9 +1476,9 @@ pnpm ops keep-videos --json '{"slug":"example-rumble","ids":["v1abcde"],"note":
2 h; each failed try costs one extraction, as the failed attempt did). The tries stop when the live-edge recording
ends (a try still waiting is not made, one in flight is awaited), on a failure no try can help (`ended`, `private`,
`members`, `disk`, `argv`, from-the-start unsupported), on a second rate limit, on a Cancel. The row's
- `startRecovery` says the tries and their state; when the landed file is a from-start try that holds the whole
- stream the start is `recovered`, the row no longer needs a person, and the live-edge part goes under the coverage
- rule below. Otherwise the start stays lost.
+ `startRecovery` says the tries and their state. A try's part is never PROVEN from the start (`provenStart`, the
+ landing rules above): it lands when it is the longest, but it never covers the stream nor removes the live-edge
+ part, which stays listed; the row needs a person to say the start is held.
- **A from-start recorder is RESUMED in place.** yt-dlp keeps a `.ytdl` state file beside each stream file of a
`--live-from-start` download (downloader/fragment.py) and, run again with the same output, continues from the saved
fragment. So a from-start recorder that dies, stalls, or is stopped by an editor shutdown is restarted as the SAME
@@ -1486,10 +1486,19 @@ pnpm ops keep-videos --json '{"slug":"example-rumble","ids":["v1abcde"],"note":
download (`resumes` on the part). A resumed part keeps the proof of start its original run earned
(`provenStart`); a live-edge or recovery part never has one. The watchdog and a shutdown stop it with SIGTERM, which leaves the state; a
person's Cancel is SIGINT, which finishes the file. At a shutdown such a part is not landed: it waits in staging
- (`awaitingResume`) and the boot's restart resumes it. Only when a resume is impossible (no state: the file was
+ (`awaitingResume`) and the boot's restart resumes it (the interrupted row then no longer lists it). Such a part is
+ never landed, removed or counted inside another by any run that did not resume it: a later Record again lists it
+ as waiting too, and its row needs a person. Only when a resume is impossible (no state: the file was
finished; an unreadable state; a stream past 120 h; a resume that writes nothing) does the live-edge fallback below
run. A state read refused as private or removed is read again a minute later; confirmed, the row says the stream
went private or was removed while recording and what is held (`endedBy`, needing a person).
+- **A whole file that replaces a shorter stored one asks for the transcription again when the transcript is the short
+ one's.** Told by the transcript itself: its last cue ends no later than the replaced container's length plus 60 s
+ while the new container runs on more than 60 s past it, so it holds nothing of the rest (`transcriptRedo` on the
+ row, verdict `shorter`: the transcription is asked, the job on the row). When that cannot be told — the transcript
+ does not read or parse, holds no cues, or the replaced file's length is not known — the verdict is `unknown`, nothing
+ is asked, and the row needs a person; so does a `shorter` whose ask was refused. A transcript whose speech runs past
+ the replaced file's end is left as it is.
- **A stalled or dead recorder is restarted while the stream is live.** Every path-A recorder (and every try beside
the live edge) has a watchdog: its part's files, scratch included, are compared every minute; no growth for
`liveRecording.stallMinutes` (10) stops THAT recorder (SIGINT), and its part stays. After a stall with bytes, or a
diff --git a/common/controller/liveRecordings.ts b/common/controller/liveRecordings.ts
@@ -181,7 +181,20 @@ function reasonOf(v: Omit<LiveRecordingView, "reason" | "check">, stallMinutes:
const held = (v.parts ?? []).reduce((n, p) => Math.max(n, p.seconds ?? 0), 0);
extra.unshift(`the stream went private or was removed while recording (${v.endedBy.message})${held ? `; ${spanWords(held)} are held` : "; what was recorded is held"}`);
}
- if (v.awaitingResume && v.awaitingResume.length) extra.push(`${v.awaitingResume.length} part(s) wait in staging, with their state, to be resumed`);
+ if (v.awaitingResume && v.awaitingResume.length) {
+ extra.push(
+ `${v.awaitingResume.length} part(s) wait in staging, with their state, to be resumed` +
+ (v.status === "interrupted" ? "" : " — not resumed by this run: a person decides"),
+ );
+ }
+ if (v.transcriptRedo) {
+ const t = v.transcriptRedo;
+ extra.push(
+ t.verdict === "shorter"
+ ? `the transcript was the replaced shorter file's (${t.why}): ${t.jobId ? `transcription asked again (job ${t.jobId})` : `transcription NOT asked again${t.error ? ` (${t.error})` : ""} — a person decides`}`
+ : `the transcript may be the replaced shorter file's — not known (${t.why}): a person decides whether to transcribe again`,
+ );
+ }
if (v.spaceHeld && v.spaceHeld.length) extra.push(`NOT started for want of disk: ${v.spaceHeld.map((x) => x.what).join(", ")}`);
if (v.restarts && v.restarts.count > 0) extra.push(`its recorder was restarted ${v.restarts.count} time${v.restarts.count === 1 ? "" : "s"} (stalled or died while live)`);
if (v.restarts?.refused) extra.push(`NOT restarted again though the stream was live: ${v.restarts.refused}`);
@@ -346,6 +359,7 @@ export async function listLiveRecordings(paths: Paths, opts: ListLiveRecordingsO
...(own?.spaceHeld ? { spaceHeld: own.spaceHeld } : {}),
...(own?.endedBy ? { endedBy: own.endedBy } : {}),
...(own?.awaitingResume ? { awaitingResume: own.awaitingResume } : {}),
+ ...(own?.transcriptRedo ? { transcriptRedo: own.transcriptRedo } : {}),
attempts: own?.attempts ?? row.attempts,
parts,
slug,
@@ -368,6 +382,8 @@ export async function listLiveRecordings(paths: Paths, opts: ListLiveRecordingsO
lost: own?.lost ?? row.lost,
endedBy: own?.endedBy ?? row.endedBy,
spaceHeld: own?.spaceHeld ?? row.spaceHeld,
+ awaitingResume: own?.awaitingResume ?? row.awaitingResume,
+ transcriptRedo: own?.transcriptRedo ?? row.transcriptRedo,
}),
};
const shown =
diff --git a/common/controller/recordLive.test.ts b/common/controller/recordLive.test.ts
@@ -675,6 +675,7 @@ async function incidentRun(
// A number: that many pass at once, the rest never come.
recovery?: "immediate" | number;
refresh?: Parameters<typeof refreshWith>[1];
+ requestTranscription?: (slug: string, id: string) => Promise<{ ok: boolean; jobId?: string; error?: string }>;
} = {},
) {
await ytChannel();
@@ -692,6 +693,7 @@ async function incidentRun(
onLog: (l) => void log.push(l),
signal: opts.signal ?? new AbortController().signal,
jobId: `job-${id}`,
+ ...(opts.requestTranscription ? { requestTranscription: opts.requestTranscription } : {}),
deps: {
refresh: refreshWith(opts.meta ?? ytLiveMeta(id), opts.refresh ?? {}),
fetchText: async () => {
@@ -1243,6 +1245,7 @@ test("slice 2: the live edge records, a from-start try beside it records from th
// but it is not taken as the whole stream — the live-edge part is kept and
// a person decides.
assert.equal(row.parts.find((p) => p.recovery && (p.seconds ?? 0) > 0)?.provenStart, undefined);
+ assert.ok(row.parts.filter((p) => !p.fromStart).every((p) => p.provenStart === undefined), "nor a live-edge part");
assert.equal(row.coverage?.covers, false);
assert.equal(row.startRecovery?.state, "recorded");
assert.ok(row.keptParts?.some((k) => /ytdlp-edge-a4$/.test(k.stem)), "the live-edge part is kept");
@@ -3349,3 +3352,230 @@ test("LF3 note 5: a proven, same-kind, shorter part of this run IS removed after
assert.ok(!files.some((n) => /-a2\.f140|ytdlp\.f140/.test(n)), `removed from staging: ${files.join(", ")}`);
assert.equal(files.filter((n) => /edge/.test(n)).length, 3, "the live-edge parts (not proven) are kept");
});
+
+// --- The flows this lane is for (REVIEW-LF-4 notes 2 and 4) ----------------------
+
+const choughOf = (endSeconds: number) => JSON.stringify({ chunk_data: [{ start_time: 0, end_time: 30, text: "hello" }, { start_time: endSeconds - 20, end_time: endSeconds, text: "the last words" }] });
+
+test("flow: an editor shutdown stops a from-start run, the BOOT PASS resumes it in place, the stream ends, ONE whole file lands and nothing is left", { timeout: 60_000 }, async () => {
+ const id = "exmplflowa1";
+ const ac = new AbortController();
+ const first = await incidentRun(
+ id,
+ resumableYtdlp(async ({ write, signal }) => {
+ await write(3000);
+ setTimeout(() => ac.abort(), 10);
+ await abortOf(signal);
+ return { exitCode: null, stderrTail: "", signalled: true };
+ }),
+ { signal: ac.signal, deps: { ...FAST_WATCH, join: null, shuttingDown: () => true } },
+ );
+ assert.equal((await first.run).status, "interrupted");
+ const stem = outOf(first.calls[0]!);
+ const row1 = (await rowOf(id))[0]!;
+ assert.deepEqual(row1.awaitingResume, [path.basename(stem)], "the part waits, with its state, to be resumed");
+ assert.equal(row1.parts[0]!.provenStart, true, "a YouTube from-start part under 120 h old: proven as it was recorded");
+ assert.equal(await storedSeconds(id), null, "nothing landed at the shutdown");
+ // The editor comes back: the boot pass (the real one) restarts the row.
+ await new Promise((r) => setTimeout(r, 20));
+ const { restartInterruptedLiveRecordings } = await import("./liveRecordingBoot");
+ let live = true;
+ let second: Awaited<ReturnType<typeof incidentRun>> | null = null;
+ const outcomes = await restartInterruptedLiveRecordings({
+ paths,
+ bootedAt: Date.now(),
+ isRunning: () => false,
+ orphanLooks: 1,
+ sleep: async () => {},
+ // (The pass walks the whole test corpus: only this test's row is started.)
+ start: async (_slug, body, resumeOf) => {
+ if (body.url !== ytUrl(id)) return { ok: false, error: "another test's row" };
+ second = await incidentRun(
+ id,
+ resumableYtdlp(async ({ resumedFrom, write }) => {
+ assert.equal(resumedFrom, 600, "from the saved fragment");
+ await write(7200);
+ live = false;
+ return "end";
+ }),
+ { request: { ...body, resumeOf }, deps: { ...FAST_WATCH, join: null }, refresh: { stillLive: () => live } },
+ );
+ return { ok: true, jobId: "job-boot" };
+ },
+ });
+ assert.deepEqual(outcomes.filter((o) => o.id === id).map((o) => o.state), ["asked"]);
+ const s2 = await second!.run;
+ assert.equal(s2.status, "landed");
+ assert.equal(outOf(second!.calls[0]!), stem, "the same stem, resumed in place");
+ assert.equal(await storedSeconds(id), 7200, "one whole file in the store");
+ assert.deepEqual(await left(id), [], "nothing left in staging: no part, no state");
+ const rows = await rowOf(id);
+ const run2 = rows.find((r) => r.resumeOf)!;
+ assert.equal(run2.parts.length, 1);
+ assert.equal(run2.parts[0]!.provenStart, true, "the resumed part keeps the mark the original run earned");
+ assert.equal(run2.parts[0]!.resumes, 1);
+ assert.equal(run2.coverage?.covers, true);
+ assert.equal(run2.needsAttention, false);
+ const old = rows.find((r) => r.startedAt === row1.startedAt)!;
+ assert.equal(old.awaitingResume, undefined, "the old row no longer says a part waits");
+ assert.equal(old.needsAttention, false, "the interruption is superseded by the whole");
+});
+
+test("flow: a part waiting to be resumed is not landed, removed or counted by a later run that does not resume it; that run says so and needs a person", { timeout: 60_000 }, async () => {
+ const id = "exmplflowa2";
+ const ac = new AbortController();
+ const first = await incidentRun(
+ id,
+ resumableYtdlp(async ({ write, signal }) => {
+ await write(3000);
+ setTimeout(() => ac.abort(), 10);
+ await abortOf(signal);
+ return { exitCode: null, stderrTail: "", signalled: true };
+ }),
+ { signal: ac.signal, deps: { ...FAST_WATCH, join: null, shuttingDown: () => true } },
+ );
+ await first.run;
+ const waiting = (await left(id)).sort();
+ assert.ok(waiting.some((n) => n.endsWith(".ytdl")));
+ // A person's Record again (no resume): its own whole from-start file.
+ let live = true;
+ const again = await incidentRun(
+ id,
+ async (args) => {
+ await writeFile(`${outOf(args)}.mp4`, "format=mov,mp4;seconds=7200;");
+ live = false;
+ return okExit;
+ },
+ { deps: { ...FAST_WATCH, join: null }, refresh: { stillLive: () => live } },
+ );
+ assert.equal((await again.run).status, "landed");
+ assert.equal(await storedSeconds(id), 7200);
+ const after = await left(id);
+ for (const n of waiting) assert.ok(after.includes(n), `${n} is still in staging as it was`);
+ const row = (await rowOf(id)).find((r) => r.status === "landed")!;
+ assert.equal(row.removedParts, undefined, "not removed by the coverage rule");
+ assert.deepEqual(row.awaitingResume, [path.basename(outOf(first.calls[0]!))]);
+ assert.equal(row.needsAttention, true, "a part with its state waits in staging: a person decides");
+ assert.match(row.reason, /wait in staging/);
+});
+
+async function replacedOverShutdown(id: string, transcript: string | null, requestTranscription?: (slug: string, id: string) => Promise<{ ok: boolean; jobId?: string; error?: string }>) {
+ await landedAtShutdown(id, 3600);
+ if (transcript !== null) await writeFile(path.join(dataDir(id), "transcript.json"), transcript);
+ let live = true;
+ const r = await incidentRun(
+ id,
+ async (args) => {
+ await writeFile(`${outOf(args)}.mp4`, "format=mov,mp4;seconds=7200;");
+ live = false;
+ return okExit;
+ },
+ // (The hand-off reads a transcript there, as the real one does.)
+ { deps: { join: null, handoff: async () => ({ ...(await handoff()), hasTranscript: transcript !== null }) }, refresh: { stillLive: () => live }, ...(requestTranscription ? { requestTranscription } : {}) },
+ );
+ const s = await r.run;
+ return { s, log: r.log, row: (await rowOf(id)).find((x) => x.status === "landed")! };
+}
+
+test("flow (REVIEW-LF-4 4): a shutdown's landing from the start is stored, then a WHOLE from-start run replaces it — nobody is asked", async () => {
+ const id = "exmplflowb1";
+ const { s, row } = await replacedOverShutdown(id, null);
+ assert.equal(s.status, "landed");
+ assert.equal(await storedSeconds(id), 7200, "the whole replaced the shutdown's short landing");
+ assert.equal(row.kept, "new");
+ assert.equal(row.coverage?.covers, true);
+ assert.equal(row.transcriptRedo, undefined, "no transcript: the ordinary hand-off asks");
+ assert.equal(row.needsAttention, false);
+ assert.ok((await rowOf(id)).every((r) => !r.needsAttention), "the interruption is superseded");
+});
+
+test("flow (REVIEW-LF-4 2): the replaced short landing's transcript ends inside it → the transcription is asked again", async () => {
+ const id = "exmplflowb2";
+ const asked: string[] = [];
+ const { row, log } = await replacedOverShutdown(id, choughOf(3580), async (_slug, vid) => {
+ asked.push(vid);
+ return { ok: true, jobId: "job-redo" };
+ });
+ assert.deepEqual(asked, [id], "asked once");
+ assert.equal(row.transcriptRedo?.verdict, "shorter");
+ assert.equal(row.transcriptRedo?.replacedSeconds, 3600);
+ assert.equal(row.transcriptRedo?.lastCueEnd, 3580);
+ assert.equal(row.transcriptRedo?.jobId, "job-redo");
+ assert.equal(row.needsAttention, false, "asked: nobody needs to");
+ assert.ok(log.some((l) => /transcript .*shorter file/i.test(l)));
+});
+
+test("flow (REVIEW-LF-4 2): asked again but nothing to ask with, or the ask refused → the row needs a person", async () => {
+ const id = "exmplflowb3";
+ const { row } = await replacedOverShutdown(id, choughOf(3580));
+ assert.equal(row.transcriptRedo?.verdict, "shorter");
+ assert.equal(row.needsAttention, true);
+ assert.match(row.reason, /transcript/);
+ const id2 = "exmplflowb4";
+ const r2 = await replacedOverShutdown(id2, choughOf(3580), async () => ({ ok: false, error: "the lane is held" }));
+ assert.equal(r2.row.transcriptRedo?.error, "the lane is held");
+ assert.equal(r2.row.needsAttention, true);
+});
+
+test("flow (REVIEW-LF-4 2): a transcript that cannot be read → not known which file it came from: the row says so and asks a person, nothing is queued", async () => {
+ const id = "exmplflowb5";
+ const asked: string[] = [];
+ const { row } = await replacedOverShutdown(id, "{ not json", async (_s, vid) => {
+ asked.push(vid);
+ return { ok: true, jobId: "job-x" };
+ });
+ assert.deepEqual(asked, []);
+ assert.equal(row.transcriptRedo?.verdict, "unknown");
+ assert.equal(row.needsAttention, true);
+ assert.match(row.reason, /transcript/);
+});
+
+test("flow (REVIEW-LF-4 2): a transcript whose speech runs past the short file's end was not made from it → nothing is asked", async () => {
+ const id = "exmplflowb6";
+ const asked: string[] = [];
+ const { row } = await replacedOverShutdown(id, choughOf(7150), async (_s, vid) => {
+ asked.push(vid);
+ return { ok: true, jobId: "job-y" };
+ });
+ assert.deepEqual(asked, []);
+ assert.equal(row.transcriptRedo, undefined);
+ assert.equal(row.needsAttention, false);
+});
+
+test("flow: a boot resume of a part its original run did NOT prove (a row written before the mark) earns no mark: it lands, unproven, covering nothing", { timeout: 60_000 }, async () => {
+ const id = "exmplflowa3";
+ const ac = new AbortController();
+ const first = await incidentRun(
+ id,
+ resumableYtdlp(async ({ write, signal }) => {
+ await write(3000);
+ setTimeout(() => ac.abort(), 10);
+ await abortOf(signal);
+ return { exitCode: null, stderrTail: "", signalled: true };
+ }),
+ { signal: ac.signal, deps: { ...FAST_WATCH, join: null, shuttingDown: () => true } },
+ );
+ await first.run;
+ const t0 = (await rowOf(id))[0]!.startedAt;
+ const { patchLiveRecordingRow } = await import("../lib/liveRecordings-server");
+ await patchLiveRecordingRow(paths, YT_SLUG, id, t0, (r) => {
+ for (const p of r.parts) delete p.provenStart;
+ r.restart = { at: t0, by: "boot", state: "asked" };
+ });
+ let live = true;
+ const second = await incidentRun(
+ id,
+ resumableYtdlp(async ({ resumedFrom, write }) => {
+ assert.equal(resumedFrom, 600);
+ await write(7200);
+ live = false;
+ return "end";
+ }),
+ { request: { resumeOf: t0 }, deps: { ...FAST_WATCH, join: null }, refresh: { stillLive: () => live } },
+ );
+ assert.equal((await second.run).status, "landed");
+ const run2 = (await rowOf(id)).find((r) => r.resumeOf)!;
+ assert.equal(run2.parts[0]!.resumes, 1, "resumed in place");
+ assert.equal(run2.parts[0]!.provenStart, undefined, "the mark is not earned by a resume");
+ assert.equal(run2.coverage?.covers, false);
+});
diff --git a/common/controller/recordLive.ts b/common/controller/recordLive.ts
@@ -107,10 +107,14 @@ import {
type PlaylistReach,
type StartRecovery,
type StreamCoverage,
+ type LiveTranscriptRedo,
} from "../lib/liveCapture";
+import { WHISPER_FILENAME } from "../lib/videoStatus";
+import { parseTranscriptJson } from "../lib/whisper";
+import { readStoredText } from "../lib/storedText-server";
import { liveJoinsSidecar, liveRecordingSidecar } from "../lib/mediaImport-server";
import { ffmpegJoinDeps, joinLiveParts, type JoinDeps } from "./liveJoin";
-import { loadLiveRecordingRows, rowOfRecord, upsertLiveRecordingRow } from "../lib/liveRecordings-server";
+import { loadLiveRecordingRows, patchLiveRecordingRow, rowOfRecord, upsertLiveRecordingRow } from "../lib/liveRecordings-server";
import { liveRecordingCheckCommand, liveStallMinutes } from "./liveRecordings";
import { markLiveBootRestart } from "./liveRecordingBoot";
import { isDoNotClean, setDoNotClean } from "../lib/doNotClean-server";
@@ -2003,6 +2007,14 @@ async function recordLiveRunInner(
// The mark the interrupted run earned travels with its file.
bootResume = { stem: p.stem, formats: st.formats, ...(p.provenStart ? { provenStart: true } : {}) };
say(`Restart after the editor restart: ${p.stem} is resumed in place from fragment ${st.fragment}.`);
+ // This run holds it now: the interrupted row no longer lists it
+ // as waiting.
+ const resumed = p.stem;
+ await patchLiveRecordingRow(paths, req.slug, id, resumeOf, (r) => {
+ if (!r.awaitingResume?.includes(resumed)) return false;
+ r.awaitingResume = r.awaitingResume.filter((x) => x !== resumed);
+ if (!r.awaitingResume.length) delete r.awaitingResume;
+ }).catch((e: Error) => say(`The interrupted row could not be updated (${e.message}).`));
break;
}
}
@@ -2800,12 +2812,9 @@ async function recordLiveRunInner(
}
}
}
- // SLICE 2: a from-start try beside the live edge is the landed file and holds
- // the whole stream — the start is not lost after all.
- if (record.startRecovery && best.part?.recovery === true && cov.covers) {
- record.startRecovery.state = "recovered";
- say(`The start is recovered: a from-start try beside the live edge holds the whole stream (${spanWords(cov.capturedSeconds ?? 0)}).`);
- }
+ // (SLICE 2: a from-start try beside the live edge never carries the proof of
+ // start — main's rule — so its landing never "recovers" the start by the
+ // coverage rule: the live-edge part stays and a person decides.)
// Covered: every other part of the stream, this run's or an earlier one's,
// is inside the landed file, and goes (recorded, with why) — except a part
// that may hold the stream's END: one not from the start (a live-edge part,
@@ -2983,7 +2992,22 @@ async function recordLiveRunInner(
videoDir,
transcribeJob: req.transcribe === true,
});
- if (req.transcribe === true && !facts.hasTranscript && opts.requestTranscription) {
+ // A SHORTER STORED CONTAINER WAS REPLACED (REVIEW-LF-4 2): a transcript
+ // that ends inside it is that file's, and is asked for again.
+ const redo = landed.existingSeconds !== undefined ? await transcriptOfReplaced(videoDir, landed.existingSeconds, landed.newSeconds ?? null) : null;
+ if (redo) {
+ record.transcriptRedo = { ...redo, at: now().toISOString() };
+ if (redo.verdict === "shorter") {
+ say(`The transcript is the replaced shorter file's (${redo.why}): the transcription is asked again.`);
+ const r = opts.requestTranscription ? await opts.requestTranscription(req.slug, id) : { ok: false, error: "no transcription can be asked from here" };
+ if (r.ok && r.jobId) record.transcriptRedo.jobId = r.jobId;
+ else record.transcriptRedo.error = r.error ?? "no job";
+ say(r.ok ? `transcribe-one job ${r.jobId}` : `The transcription was not asked again: ${r.error ?? "no job"} — it needs a person.`);
+ } else {
+ say(`The transcript may be the replaced shorter file's; that cannot be told (${redo.why}): nothing is asked, it needs a person.`);
+ }
+ await save();
+ } else if (req.transcribe === true && !facts.hasTranscript && opts.requestTranscription) {
const r = await opts.requestTranscription(req.slug, id);
say(r.ok ? `transcribe-one job ${r.jobId}` : `The transcribe-one job was not queued: ${r.error ?? "no job"}`);
}
@@ -2992,6 +3016,52 @@ async function recordLiveRunInner(
return summary;
}
+// WAS THE VIDEO'S TRANSCRIPT MADE FROM THE FILE A LANDING JUST REPLACED
+// (REVIEW-LF-4 2)? Told by the transcript itself, against the two lengths: its
+// last cue ends inside the replaced container (no later than its length plus
+// 60 s) while the new container runs on more than 60 s past that — so it
+// holds nothing of the rest, whichever file it was made from, and is the
+// short one's. A transcript whose speech runs past the replaced file's end
+// was not made from it; a new file not longer than the old leaves nothing to
+// redo; no transcript.json, nothing to redo (the ordinary hand-off asks).
+// Not tellable — the transcript does not read or holds no cues, or the
+// replaced length is not known — "unknown": a person decides.
+export const TRANSCRIPT_REDO_TOLERANCE_SECONDS = 60;
+export async function transcriptOfReplaced(
+ videoDir: string,
+ replacedSeconds: number | null,
+ newSeconds: number | null,
+): Promise<Omit<LiveTranscriptRedo, "at"> | null> {
+ const tol = TRANSCRIPT_REDO_TOLERANCE_SECONDS;
+ let src: string;
+ try {
+ // (Its plain form, else its stored, compressed one.)
+ src = await readStoredText(videoDir, WHISPER_FILENAME, "utf8");
+ } catch (err) {
+ if ((err as NodeJS.ErrnoException).code === "ENOENT") return null;
+ return { verdict: "unknown", why: `${WHISPER_FILENAME} does not read (${(err as Error).message})`, replacedSeconds, lastCueEnd: null };
+ }
+ if (replacedSeconds === null || newSeconds === null) {
+ return { verdict: "unknown", why: `the ${replacedSeconds === null ? "replaced" : "new"} file's length is not known`, replacedSeconds, lastCueEnd: null };
+ }
+ if (newSeconds <= replacedSeconds + tol) return null;
+ let lastCueEnd = 0;
+ try {
+ const cues = parseTranscriptJson(src);
+ if (!cues.length) return { verdict: "unknown", why: `${WHISPER_FILENAME} holds no cues`, replacedSeconds, lastCueEnd: null };
+ for (const c of cues) if (typeof c.end === "number" && c.end > lastCueEnd) lastCueEnd = c.end;
+ } catch (err) {
+ return { verdict: "unknown", why: `${WHISPER_FILENAME} does not parse (${(err as Error).message})`, replacedSeconds, lastCueEnd: null };
+ }
+ if (lastCueEnd > replacedSeconds + tol) return null;
+ return {
+ verdict: "shorter",
+ why: `its last cue ends at ${spanWords(lastCueEnd)}, inside the replaced ${spanWords(replacedSeconds)}; the new file is ${spanWords(newSeconds)}`,
+ replacedSeconds,
+ lastCueEnd,
+ };
+}
+
// Every refusal before any job; then the job.
export async function runRecordLiveJob(
opts: Omit<RecordLiveJobOpts, "plan">,
diff --git a/common/lib/liveCapture.ts b/common/lib/liveCapture.ts
@@ -586,6 +586,8 @@ export type LiveRecordingRecord = {
// DESIGN-3: parts an editor shutdown stopped with their state kept, waiting
// in staging (not landed) for the boot's restart to resume them.
awaitingResume?: string[];
+ // The transcript was the replaced shorter file's (LiveTranscriptRedo).
+ transcriptRedo?: LiveTranscriptRedo;
// Spawns that did not start because the store's disk was under the floor
// (RECORD_LIVE_MIN_FREE_BYTES): what, when, and how much was free.
spaceHeld?: LiveSpaceHeld[];
@@ -635,6 +637,24 @@ export const LIVE_JOINS_FILENAME = "live-joins.json";
export type LiveSpaceHeld = { what: string; at: string; freeBytes: number };
+// A landing that REPLACED a shorter stored container while the video's
+// transcript does not reach past that container's end (REVIEW-LF-4 2): the
+// transcript is the short file's, and the transcription is asked again.
+// "shorter": its last cue ends inside the replaced file's length (within
+// 60 s) and the new file runs on past it; "unknown": which file it came from
+// cannot be told (it does not read, holds no cues, or the replaced file's
+// length is not known) — nothing is asked, a person decides. jobId: the
+// transcription asked; error: why it was not.
+export type LiveTranscriptRedo = {
+ verdict: "shorter" | "unknown";
+ why: string;
+ replacedSeconds: number | null;
+ lastCueEnd: number | null;
+ at: string;
+ jobId?: string;
+ error?: string;
+};
+
// data/<id>/live-joins.json: the landed container was joined from parts.
export type LiveJoinsRecord = {
landedAt: string;
diff --git a/common/lib/liveRecordings-server.ts b/common/lib/liveRecordings-server.ts
@@ -38,6 +38,7 @@ import type {
LiveJoin,
LiveRestarts,
LiveSpaceHeld,
+ LiveTranscriptRedo,
MissingStream,
StartRecovery,
StreamCoverage,
@@ -88,6 +89,7 @@ export type LiveRecordingRow = {
spaceHeld?: LiveSpaceHeld[];
endedBy?: { class: LiveFailureClass; message: string; at: string };
awaitingResume?: string[];
+ transcriptRedo?: LiveTranscriptRedo;
// What the landing kept: this run's file stored ("new"), or the store's.
kept?: "new" | "existing";
acknowledgedAt?: string;
@@ -177,11 +179,17 @@ export async function loadLiveRecordingRows(paths: Pick<Paths, "channelsDir">, s
// recording that holds the whole stream (supersededBy).
export function rowNeedsAttention(
r: Pick<LiveRecordingRow, "status" | "fallback" | "acknowledgedAt" | "supersededBy"> &
- Partial<Pick<LiveRecordingRow, "mustKeep" | "keptParts" | "missingStream" | "startRecovery" | "restarts" | "restart" | "fromStart" | "joins" | "spaceHeld" | "lost" | "endedBy">>,
+ Partial<Pick<LiveRecordingRow, "mustKeep" | "keptParts" | "missingStream" | "startRecovery" | "restarts" | "restart" | "fromStart" | "joins" | "spaceHeld" | "lost" | "endedBy" | "awaitingResume" | "transcriptRedo">>,
): boolean {
if (r.acknowledgedAt) return false;
if (r.keptParts && r.keptParts.length > 0) return true;
if (r.supersededBy) return false;
+ // Parts left in staging with their state, to be resumed: a resume, or a
+ // person (DESIGN-3; a later run that did not resume them lists them too).
+ if (r.awaitingResume && r.awaitingResume.length) return true;
+ // The transcript is (or may be) the replaced shorter file's and no
+ // transcription was asked (REVIEW-LF-4 2).
+ if (r.transcriptRedo && (r.transcriptRedo.verdict === "unknown" || !r.transcriptRedo.jobId)) return true;
if (r.status === "failed" || r.status === "interrupted") return true;
if (r.status === "cancelled" && r.mustKeep === true) return true;
if (r.fallback === "live-edge" && r.startRecovery?.state !== "recovered") return true;
@@ -266,6 +274,7 @@ export function rowOfRecord(
...(rec.kept ? { kept: rec.kept } : {}),
...(rec.endedBy ? { endedBy: { ...rec.endedBy } } : {}),
...(rec.awaitingResume && rec.awaitingResume.length ? { awaitingResume: [...rec.awaitingResume] } : {}),
+ ...(rec.transcriptRedo ? { transcriptRedo: { ...rec.transcriptRedo } } : {}),
...(rec.spaceHeld && rec.spaceHeld.length ? { spaceHeld: rec.spaceHeld.map((x) => ({ ...x })) } : {}),
...(rec.failureClass ? { failureClass: rec.failureClass } : {}),
...(rec.missingStream ? { missingStream: rec.missingStream } : {}),
diff --git a/editor/CHANGELOG.md b/editor/CHANGELOG.md
@@ -5,8 +5,8 @@
recorder, a restart after the editor's, and parts joined.**
- A from-start recorder that dies, stalls or is stopped by an editor shutdown is RESUMED in place from yt-dlp's
own `.ytdl` state: the same part, no gap, no second download; the live-edge restart is only the fallback.
- - After a fallback to the live edge, from its start is tried again beside it every 15 min, at most 8 times; a try
- that lands the whole stream recovers the start.
+ - After a fallback to the live edge, from its start is tried again beside it every 15 min, at most 8 times; a try's
+ part lands when it is the longest, but it is never proven from the start: the live-edge part stays for a person.
- A recorder whose files stop growing for `liveRecording.stallMinutes`, or that exits while the stream still reads
live, is restarted as a new part from the live edge (at most 6 an hour, 24 a run); its earlier part stays for the
landing, and a stream that reads live is never left unrecorded quietly: a span the kept parts do not reach is
@@ -17,6 +17,10 @@
live (`liveRecording.autoRestartOnBoot`); ended, what is in staging lands; unreadable, nothing starts.
- Parts that together hold more than the longest are joined `-c copy` when proven (length and sound at each join),
the joins on the row and in `live-joins.json`; a gap is stated and needs a person.
+ - A part resumed in place keeps the proof of start its original run earned; a part waiting to be resumed is never
+ landed, removed or counted by a run that did not resume it.
+ - A whole file that replaces a stored shorter landing asks for the transcription again when the transcript's last
+ cue ends inside the shorter file (`transcriptRedo`); when that cannot be told, the row needs a person.
- **A live recording's landing never deletes around, or replaces, a recording already in the store that it is not
proven to hold.**
- When the landing keeps the container already stored, nothing is removed: the part and every part meant for