Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 44284b72e1c6f4fff3e0f8953ad6ba5291e54a29
parent ee840110e67c29ee010f75f94972136ef72d546d
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Sat, 21 Nov 2026 13:21:14 -0500

record-live: try from the start again beside a live-edge recording

When the from-start attempts recorded nothing and the run fell back to the
live edge, the stream's start was given up for good. Now, from the first
live-edge attempt, a from-start try runs beside it every 15 min
(jittered), one at a time, at most 8 times, each in its own part; the
live-edge recorder is never touched. 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,
or when they are spent.

The record and the channel's row carry startRecovery (tries, state, the
last failure). When the landed file is a from-start try and holds the
whole stream, the start is "recovered": the row no longer needs a person,
the live-edge part goes under the covered rule, and it supersedes earlier
failures. Otherwise the start stays lost and needs a person, as before.

Co-Authored-By: Claude <noreply@anthropic.com>

Diffstat:
Mcommon/controller/liveRecordings.ts | 19++++++++++++++++++-
Mcommon/controller/recordLive.test.ts | 140+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcommon/controller/recordLive.ts | 110++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
Mcommon/lib/liveCapture.ts | 39+++++++++++++++++++++++++++++++++++++++
Mcommon/lib/liveRecordings-server.ts | 23+++++++++++++++++------
5 files changed, 320 insertions(+), 11 deletions(-)

diff --git a/common/controller/liveRecordings.ts b/common/controller/liveRecordings.ts @@ -141,6 +141,19 @@ function reasonOf(v: Omit<LiveRecordingView, "reason" | "check">, stallMinutes: if (v.status === "landed" && v.coverage && !v.coverage.covers && v.coverage.streamSeconds !== null && v.coverage.capturedSeconds !== null && !v.fallback) { extra.push(`holds ${spanWords(v.coverage.capturedSeconds)} of a ${spanWords(v.coverage.streamSeconds)} stream (${v.coverage.basis === "duration" ? "its duration" : "by the clock"})`); } + const rs = v.startRecovery; + if (rs) { + const words: Record<string, string> = { + waiting: `start recovery: ${rs.tries} of ${rs.max} tries made, the next within ${spanWords(rs.everyMs / 1000)}`, + trying: `start recovery: try ${rs.tries} of ${rs.max} records now`, + recorded: `start recovery: try ${rs.tries} recorded from its start (not proven whole)`, + recovered: "start recovered: a from-start try holds the whole stream", + "gave-up": `start recovery gave up after ${rs.tries} tries${rs.failureClass ? ` [${rs.failureClass}]` : ""}`, + exhausted: `start recovery: all ${rs.max} tries failed`, + stopped: `start recovery stopped after ${rs.tries} tries (the live edge ended first)`, + }; + extra.unshift(words[rs.state] ?? `start recovery: ${rs.state}`); + } const tail = extra.length ? `; ${extra.join("; ")}` : ""; const cls = v.failureClass && v.failureClass !== "unknown" ? ` [${v.failureClass}]` : ""; switch (v.status) { @@ -155,7 +168,9 @@ function reasonOf(v: Omit<LiveRecordingView, "reason" | "check">, stallMinutes: case "cancelled": return `cancelled${v.mustKeep ? " (a must-keep stream: is that what you wanted?)" : ""}${tail}`; case "landed": - return (v.fallback === "live-edge" ? `landed from the live edge: ${lostWords}` : "landed") + tail; + return ( + (v.fallback === "live-edge" && rs?.state !== "recovered" ? `landed from the live edge: ${lostWords}` : "landed") + tail + ); case "recording": { const parts = [v.fallback === "live-edge" ? `recording from the live edge: ${lostWords}` : "recording"]; if (v.bytes !== null) parts.push(`${Math.round(v.bytes / 1024 / 1024)} MB so far`); @@ -269,6 +284,7 @@ export async function listLiveRecordings(paths: Paths, opts: ListLiveRecordingsO ...(own?.keptParts ? { keptParts: own.keptParts } : {}), ...(own?.removedParts ? { removedParts: own.removedParts } : {}), ...(own?.coverage ? { coverage: own.coverage } : {}), + ...(own?.startRecovery ? { startRecovery: own.startRecovery } : {}), attempts: own?.attempts ?? row.attempts, parts, slug, @@ -285,6 +301,7 @@ export async function listLiveRecordings(paths: Paths, opts: ListLiveRecordingsO fallback: own?.fallback ?? row.fallback, keptParts: own?.keptParts ?? row.keptParts, missingStream: own?.missingStream ?? row.missingStream, + startRecovery: own?.startRecovery ?? row.startRecovery, }), }; const shown = diff --git a/common/controller/recordLive.test.ts b/common/controller/recordLive.test.ts @@ -654,6 +654,10 @@ async function incidentRun( request?: Record<string, unknown>; meta?: Record<string, unknown>; deps?: Record<string, unknown>; + // Slice 2's tries beside the live edge: their 15 min waits pass at once + // ("immediate", recorded in `waits`), or never come before the run ends + // (the default: no try is made). + recovery?: "immediate"; } = {}, ) { await ytChannel(); @@ -682,6 +686,10 @@ async function incidentRun( waits.push(ms); opts.onWait?.(ms); }, + recoveryWait: + opts.recovery === "immediate" + ? async (ms: number) => void waits.push(ms) + : (_ms: number, sig: AbortSignal) => new Promise<void>((r) => (sig.aborted ? r() : sig.addEventListener("abort", () => r(), { once: true }))), jitter: (ms) => ms, land, freeBytes: async () => 1e15, @@ -1175,3 +1183,135 @@ test("a landing that fails removes nothing: the covered landing's other part and assert.equal(row.keptParts?.length, 2); assert.equal(row.needsAttention, true); }); + +// --- SLICE 2: the start recovered beside a live-edge recording --------------------- +// +// From its start failed three times, the run records from the live edge, and +// BESIDE it — never touching it — tries from its start again every 15 min, one +// try at a time, at most 8 times. The waits are recorded, never slept. + +const RECOVERY_WAIT = 15 * 60_000; +const isRecovery = (args: string[]) => /\.ytdlp-recover-r\d+$/.test(outOf(args)); +// The live-edge recorder: records 1800 s, and runs until `ended` resolves. +const edgeUntil = (ended: Promise<unknown>, seconds = 1800) => async (args: string[]) => { + await writeFile(`${outOf(args)}.mp4`, `format=mov,mp4;seconds=${seconds};`); + await ended; + return { exitCode: 0, stderrTail: "", signalled: false }; +}; +const failEmpty = { exitCode: 1, stderrTail: EMPTY, signalled: false }; + +test("slice 2: the live edge records, a from-start try beside it recovers the start: landed whole, the live-edge part goes, nobody is asked", async () => { + const id = "exmplrecov1"; + let endStream!: () => void; + const ended = new Promise<void>((r) => (endStream = r)); + let active = 0; + let maxActive = 0; + const edge = edgeUntil(ended); + let recoveries = 0; + const { run, calls, waits, log } = await incidentRun(id, async (args) => { + if (!fromStartArg(args)) return edge(args); + active++; + maxActive = Math.max(maxActive, active); + try { + if (!isRecovery(args)) return failEmpty; + recoveries++; + if (recoveries === 1) return failEmpty; + // The second try catches up and runs to the stream's end. + await writeFile(`${outOf(args)}.mp4`, "format=mov,mp4;seconds=7200;"); + endStream(); + await new Promise((r) => setTimeout(r, 30)); + return { exitCode: 0, stderrTail: "", signalled: false }; + } finally { + active--; + } + }, { recovery: "immediate" }); + const s = await run; + assert.equal(s.status, "landed"); + assert.equal(recoveries, 2, "two tries: the first failed, the second recorded"); + assert.equal(calls.length, 6, "3 from its start, 1 live edge, 2 recovery tries"); + assert.equal(maxActive, 1, "never two from-start recorders at once"); + assert.equal(waits.filter((w) => w === RECOVERY_WAIT).length, 2, "each try after a 15 min wait"); + assert.equal(s.landed?.seconds, 7200, "the recovered from-start part lands"); + assert.ok(log.some((l) => /tried again beside the live edge/.test(l))); + const row = (await rowOf(id))[0]!; + assert.equal(row.fallback, "live-edge"); + assert.equal(row.startRecovery?.state, "recovered"); + assert.equal(row.startRecovery?.tries, 2); + assert.equal(row.coverage?.covers, true); + assert.equal(row.keptParts, undefined, "the live-edge part is inside the landed whole"); + assert.equal(row.removedParts?.length, 1); + assert.equal(row.needsAttention, false, "the start is not lost"); + assert.match(row.reason, /start recovered/); +}); + +test("slice 2: bounded — 8 failed tries beside the live edge, one at a time, then no more; the start stays lost and needs a person", async () => { + const id = "exmplrecov2"; + let recoveries = 0; + let active = 0; + let maxActive = 0; + const { run, calls } = await incidentRun(id, async (args) => { + if (!fromStartArg(args)) { + await writeFile(`${outOf(args)}.mp4`, "format=mov,mp4;seconds=1800;"); + // The stream runs until the tries are spent (or 3 s, whichever first). + for (let i = 0; i < 300 && recoveries < 8; i++) await new Promise((r) => setTimeout(r, 10)); + await new Promise((r) => setTimeout(r, 50)); + return { exitCode: 0, stderrTail: "", signalled: false }; + } + active++; + maxActive = Math.max(maxActive, active); + if (isRecovery(args)) recoveries++; + await new Promise((r) => setTimeout(r, 2)); + active--; + return failEmpty; + }, { recovery: "immediate" }); + const s = await run; + assert.equal(s.status, "landed"); + assert.equal(recoveries, 8, "at most 8 tries"); + assert.equal(calls.length, 3 + 1 + 8); + assert.equal(maxActive, 1); + const row = (await rowOf(id))[0]!; + assert.equal(row.startRecovery?.state, "exhausted"); + assert.match(row.startRecovery?.lastError ?? "", /downloaded file is empty/); + assert.equal(row.needsAttention, true, "the start is still lost"); +}); + +test("slice 2: a try that says the stream is private stops the tries; the stream ending while a try waits stops them too", async () => { + const gone = "exmplrecov3"; + let tries = 0; + const a = await incidentRun(gone, async (args) => { + if (!fromStartArg(args)) { + await writeFile(`${outOf(args)}.mp4`, "format=mov,mp4;seconds=1800;"); + for (let i = 0; i < 100 && tries < 1; i++) await new Promise((r) => setTimeout(r, 10)); + await new Promise((r) => setTimeout(r, 100)); + return { exitCode: 0, stderrTail: "", signalled: false }; + } + if (isRecovery(args)) { + tries++; + return { exitCode: 1, stderrTail: `ERROR: [youtube] ${gone}: Private video\n`, signalled: false }; + } + return failEmpty; + }, { recovery: "immediate" }); + await a.run; + assert.equal(tries, 1, "not tried again"); + const r3 = (await rowOf(gone))[0]!; + assert.equal(r3.startRecovery?.state, "gave-up"); + assert.equal(r3.startRecovery?.failureClass, "private"); + + // The stream ends while the first try is still 15 min away: no try. + const early = "exmplrecov4"; + const b = await incidentRun( + early, + async (args) => { + if (fromStartArg(args)) return failEmpty; + await writeFile(`${outOf(args)}.mp4`, "format=mov,mp4;seconds=1800;"); + await new Promise((r) => setTimeout(r, 20)); + return { exitCode: 0, stderrTail: "", signalled: false }; + }, + // (the default: the 15 min never comes before the stream ends) + ); + assert.equal((await b.run).status, "landed"); + assert.equal(b.calls.filter(isRecovery).length, 0); + const r4 = (await rowOf(early))[0]!; + assert.equal(r4.startRecovery?.state, "stopped"); + assert.equal(r4.needsAttention, true); +}); diff --git a/common/controller/recordLive.ts b/common/controller/recordLive.ts @@ -62,6 +62,8 @@ import { BROWSER_FALLBACK_PLATFORMS, LIVE_DEFAULT_MAX_HEIGHT, LIVE_RATE_LIMIT_WAIT_MS, + LIVE_RECOVERY_EVERY_MS, + LIVE_RECOVERY_MAX_TRIES, classifyAttempt, extractionRefused, ffmpegLiveArgs, @@ -89,6 +91,7 @@ import { type MediaSegment, type MissingStream, type PlaylistReach, + type StartRecovery, type StreamCoverage, } from "../lib/liveCapture"; import { liveRecordingSidecar } from "../lib/mediaImport-server"; @@ -571,6 +574,9 @@ export type RecordLiveDeps = { // The wait between two recorder attempts (default: a sleep a Cancel ends), // and the stretch applied to it (default jitterMs, pacing.jitter). wait?: (ms: number, signal: AbortSignal) => Promise<void>; + // The wait before each start-recovery try beside a live-edge recording + // (slice 2; default: `wait`). + recoveryWait?: (ms: number, signal: AbortSignal) => Promise<void>; jitter?: (ms: number) => number; // Whether the editor is shutting down (default: the job registry's): a run // stopped then is `interrupted`, never `cancelled`. @@ -1087,9 +1093,12 @@ async function recordLiveRunInner( tag: string, mode: "from-start" | "index0" | "now", extraNote = "", - ): Promise<RecorderOutcome> => { + opts: { recovery?: boolean } = {}, + ): Promise<RecorderOutcome & { part: LivePart; stem: string }> => { const file = separate ? stemPath(tag) : partPath(tag); const part = begin("ytdlp", url, file, mode !== "now"); + if (opts.recovery) part.recovery = true; + const stem = part.stem!; await save(); const args = ytdlpLiveArgs({ url, @@ -1109,7 +1118,7 @@ async function recordLiveRunInner( const o = await runRecorder({ bin: paths.ytdlpBin, args, cwd: channelDir, onLog, signal, label: tag }); finish(part, `${extraNote}yt-dlp exit ${o.exitCode ?? "null"}${o.signalled ? " (stopped)" : ""}`); await save(); - return o; + return { ...o, part, stem }; }; const sizeOf = (f: string) => stat(f).then((s) => s.size, () => 0); const filesOf = async (stem: string): Promise<LivePartFiles | null> => @@ -1191,13 +1200,94 @@ async function recordLiveRunInner( let edgeFailures = 0; let lastReason: string | null = null; let rateLimitRetried = false; + // SLICE 2 — THE START, TRIED AGAIN BESIDE THE LIVE EDGE (lib/liveCapture.ts + // LIVE_RECOVERY_*): one from-start try every 15 min (jittered), one at a + // time, at most 8, each its own part (`ytdlp-recover-r<N>`); the + // live-edge recorder is never signalled by it. It stops when the + // live-edge recording ends (a try still waiting is not made), on a + // failure no try can help, on a second rate limit, on a Cancel, or when + // the tries are spent. A try that records and ends while the live edge + // still records died mid-stream: the next try follows, inside the bound. + let recovery: Promise<void> | null = null; + const recoveryStop = new AbortController(); + let edgeDone = false; + const recoverStart = async (useIndex0: boolean): Promise<void> => { + const rs: StartRecovery = { tries: 0, max: LIVE_RECOVERY_MAX_TRIES, everyMs: LIVE_RECOVERY_EVERY_MS, state: "waiting" }; + record.startRecovery = rs; + const waitStop = AbortSignal.any([signal, recoveryStop.signal]); + say( + `From its start is tried again beside the live edge: every ${spanWords(LIVE_RECOVERY_EVERY_MS / 1000)}, ` + + `at most ${LIVE_RECOVERY_MAX_TRIES} times, one at a time; the live-edge recording is not touched.`, + ); + let limited = false; + while (rs.tries < rs.max) { + await (deps.recoveryWait ?? waitFor)(stretch(LIVE_RECOVERY_EVERY_MS), waitStop); + if (waitStop.aborted || edgeDone) { + rs.state = "stopped"; + say(`Start recovery: the live-edge recording ${signal.aborted ? "was stopped" : "ended"} before try ${rs.tries + 1}; no more tries.`); + break; + } + rs.tries++; + rs.state = "trying"; + const o = await ytdlpPart(plan.url, `ytdlp-recover-r${rs.tries}`, useIndex0 ? "index0" : "from-start", `start recovery ${rs.tries}/${rs.max}; `, { + recovery: true, + }); + const bytes = await bytesOf(o.stem); + const missing = separate && !o.signalled && bytes > 0 ? await missingStreamOf(o.stem) : null; + const cls = classifyAttempt({ ...o, bytes, partial: missing !== null }); + if (cls === "recorded") { + if (edgeDone || signal.aborted) { + rs.state = "recorded"; + say(`Start recovery: try ${rs.tries} recorded from its start to the stream's end.`); + break; + } + say(`Start recovery: try ${rs.tries} recorded from its start and stopped while the stream is live; its part is kept, the next try follows.`); + rs.state = "waiting"; + await save(); + continue; + } + if (cls === "stopped") { + rs.state = "stopped"; + break; + } + const errLine = lastErrorLine(o.stderrTail) ?? `yt-dlp exit ${o.exitCode ?? "null"}`; + const failure: LiveFailureClass = + cls === "partial" ? "partial" : cls === "argv" ? "argv" : cls === "unsupported" ? "unsupported" : liveFailureClass(o.stderrTail); + o.part.error = missing !== null ? `the ${missing === "unknown" ? "video or audio" : missing} stream recorded nothing (${errLine})` : errLine; + o.part.failureClass = failure; + if (missing !== null) o.part.missingStream = missing; + rs.lastError = o.part.error; + rs.failureClass = failure; + if (cls === "final" || cls === "argv" || cls === "unsupported" || (cls === "rate-limited" && limited)) { + rs.state = "gave-up"; + say(`Start recovery: try ${rs.tries} recorded nothing (${o.part.error}) [${failure}]: no more tries.`); + break; + } + if (cls === "rate-limited") limited = true; + rs.state = "waiting"; + say( + `Start recovery: try ${rs.tries} of ${rs.max} recorded nothing (${o.part.error})` + + (rs.tries < rs.max ? `; the next in ${spanWords(LIVE_RECOVERY_EVERY_MS / 1000)}.` : "."), + ); + await save(); + } + if (rs.state === "waiting" || rs.state === "trying") { + rs.state = "exhausted"; + say(`Start recovery: all ${rs.max} tries made; the stream's start is NOT recorded.`); + } + await save(); + }; for (let slot = 0; slot < schedule.length && !signal.aborted; ) { const step = schedule[slot]!; const n = (record.attempts ?? 0) + 1; const mode = step.mode === "live-edge" ? "now" : index0 ? "index0" : "from-start"; const tag = `ytdlp${mode === "index0" ? "-index0" : ""}${mode === "now" && fromStart ? "-edge" : ""}${n > 1 && !(mode === "index0" && n === 2) ? `-a${n}` : ""}`; + // SLICE 2: the first live-edge attempt after a fallback starts the + // from-start tries beside it (their first is 15 min away). + if (mode === "now" && fromStart && record.fallback === "live-edge" && recovery === null) recovery = recoverStart(index0); const o = await ytdlpPart(plan.url, tag, mode, mode === "index0" ? "--no-live-from-start + -live_start_index 0; " : ""); - const last = parts[parts.length - 1]!; + // This attempt's own part (a try beside it may have begun one since). + const last = { part: o.part, stem: o.stem }; const bytes = await bytesOf(last.stem); const missing = separate && !o.signalled && bytes > 0 ? await missingStreamOf(last.stem) : null; const cls = classifyAttempt({ ...o, bytes, partial: missing !== null }); @@ -1287,8 +1377,14 @@ async function recordLiveRunInner( } await waitFor(stretch(next.waitMs), signal); } + // The live-edge recording is over: a recovery try still WAITING stops + // (the stream ended, or the live edge failed); one in flight is awaited, + // never stopped — it may hold the only copy. + edgeDone = true; + recoveryStop.abort(); + if (recovery) await recovery; if (lastReason !== null && record.failureClass !== undefined) { - const tries = record.attempts ?? 0; + const tries = (record.attempts ?? 0) - (record.startRecovery?.tries ?? 0); const split = fromStartFailures && edgeFailures ? ` (${fromStartFailures} from its start, ${edgeFailures} from the live edge)` : ""; attemptsSummary = `${tries} attempt${tries === 1 ? "" : "s"}${split}: ${lastReason}`; } @@ -1499,6 +1595,12 @@ async function recordLiveRunInner( wholeFromStart: landedFromStart === true && !record.missingStream, }); const cov = record.coverage; + // 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)}).`); + } // Covered: every other part of the stream, this run's or an earlier one's, // is inside the landed file by definition, and goes (recorded, with why). // Not covered — a live-edge landing, a partial, a stream whose length is diff --git a/common/lib/liveCapture.ts b/common/lib/liveCapture.ts @@ -449,6 +449,8 @@ export type LivePart = { // nothing: the stream that is missing ("unknown": the one that wrote could // not be read). missingStream?: MissingStream; + // A from-start try beside a live-edge recording (StartRecovery). + recovery?: boolean; }; export type MissingStream = "video" | "audio" | "unknown"; @@ -538,6 +540,43 @@ export type LiveRecordingRecord = { removedParts?: RemovedPart[]; // Once landed: does it hold the whole stream (StreamCoverage). coverage?: StreamCoverage; + // After a fallback to the live edge: the from-start tries beside it + // (StartRecovery). + startRecovery?: StartRecovery; +}; + +// --- recovering the start beside a live-edge recording ---------------------------- +// +// A run that fell back to the live edge (its from-start attempts recorded +// nothing) tries from its start again BESIDE the live-edge recorder, which is +// never touched: every LIVE_RECOVERY_EVERY_MS (stretched by pacing.jitter), one +// try at a time, at most LIVE_RECOVERY_MAX_TRIES. YouTube keeps a live stream's +// start for days, so a refusal that passes (20 Nov 2026: the same argv worked +// hours later) still gets the whole stream. Each failed try costs what the +// failed from-start attempt did: one extraction and its probes, at the pace. +export const LIVE_RECOVERY_EVERY_MS = 15 * 60_000; +export const LIVE_RECOVERY_MAX_TRIES = 8; + +// waiting the next try is due (or the first) +// trying a try records now +// recorded a try recorded from its start and the stream ended: the +// landing decides whether it holds the whole stream +// recovered the landed file is a from-start try and holds the whole stream +// gave-up a failure no try can help (ended, private, members, the disk, +// the argv, from-its-start unsupported, a second rate limit) +// exhausted every try was made +// stopped the live-edge recording ended (or a Cancel) before a try +// recorded +export type StartRecoveryState = "waiting" | "trying" | "recorded" | "recovered" | "gave-up" | "exhausted" | "stopped"; + +export type StartRecovery = { + tries: number; + max: number; + everyMs: number; + state: StartRecoveryState; + // The last failed try's reason and class. + lastError?: string; + failureClass?: LiveFailureClass; }; const LIVE_STATUSES: ReadonlySet<string> = new Set(["recording", "landed", "failed", "cancelled", "interrupted"]); diff --git a/common/lib/liveRecordings-server.ts b/common/lib/liveRecordings-server.ts @@ -34,6 +34,7 @@ import type { LiveRecordingStatus, LostSpan, MissingStream, + StartRecovery, StreamCoverage, } from "./liveCapture"; @@ -71,6 +72,7 @@ export type LiveRecordingRow = { keptParts?: KeptPart[]; removedParts?: RemovedPart[]; coverage?: StreamCoverage; + startRecovery?: StartRecovery; acknowledgedAt?: string; acknowledgedBy?: string; // The run (its jobId, else its startedAt) that later landed this id. @@ -139,7 +141,10 @@ export async function loadLiveRecordingRows(paths: Pick<Paths, "channelsDir">, s // cancelled when the stream was must-keep (a // person's Cancel of any other stream // is quiet) -// recorded from the live edge the stream's start is lost +// recorded from the live edge the stream's start is lost — unless +// a from-start try beside it was +// landed and holds the whole stream +// (startRecovery "recovered") // one stream missing it landed without video or audio // parts kept on disk (keptParts) until acknowledged, whatever lands // later: a later recording does not @@ -148,14 +153,14 @@ 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">>, + Partial<Pick<LiveRecordingRow, "mustKeep" | "keptParts" | "missingStream" | "startRecovery">>, ): boolean { if (r.acknowledgedAt) return false; if (r.keptParts && r.keptParts.length > 0) return true; if (r.supersededBy) return false; if (r.status === "failed" || r.status === "interrupted") return true; if (r.status === "cancelled" && r.mustKeep === true) return true; - if (r.fallback === "live-edge") return true; + if (r.fallback === "live-edge" && r.startRecovery?.state !== "recovered") return true; return r.missingStream !== undefined; } @@ -231,14 +236,20 @@ export function rowOfRecord( ...(rec.keptParts && rec.keptParts.length ? { keptParts: rec.keptParts.map((k) => ({ ...k, files: k.files.map((f) => ({ ...f })) })) } : {}), ...(rec.removedParts && rec.removedParts.length ? { removedParts: rec.removedParts.map((r) => ({ ...r })) } : {}), ...(rec.coverage ? { coverage: { ...rec.coverage } } : {}), + ...(rec.startRecovery ? { startRecovery: { ...rec.startRecovery } } : {}), }; } // Whether a row holds the whole stream: landed, from its start, with video and // audio, and as long as the stream within the coverage's tolerance -// (controller/recordLive.ts streamCoverage). Only such a run supersedes. -export function rowCoversStream(r: Pick<LiveRecordingRow, "status" | "fromStart" | "fallback" | "missingStream" | "coverage">): boolean { - return r.status === "landed" && r.fromStart && !r.fallback && !r.missingStream && r.coverage?.covers === true; +// (controller/recordLive.ts streamCoverage). Only such a run supersedes. A run +// that fell back to the live edge qualifies only when a from-start try beside +// it was the landed file and covers (startRecovery "recovered"). +export function rowCoversStream( + r: Pick<LiveRecordingRow, "status" | "fromStart" | "fallback" | "missingStream" | "coverage"> & Partial<Pick<LiveRecordingRow, "startRecovery">>, +): boolean { + const startHeld = !r.fallback || r.startRecovery?.state === "recovered"; + return r.status === "landed" && r.fromStart && startHeld && !r.missingStream && r.coverage?.covers === true; } // Writes (or rewrites) the run's row. A run that lands the WHOLE stream