Archilyzer · Source

archilyzer

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

commit a7465e423884d4c1fa05bd5232e04172cd0de235
parent be64cfe0d213e142a86820f4b35eedc22c25f67d
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Sat, 21 Nov 2026 20:46:37 -0500

record-live: from the start only on proof, never the only video, and the store read fails closed

REVIEW-LF-1:
- 1: "from the start" for the coverage, the store's replacement and the
  removals now needs proof: a part marked provenStart when it was
  recorded (yt-dlp --live-from-start, a Kick VOD from its first segment).
  An index-0 part, the browser path, or a part of a row written before the
  mark is not proven, so it never replaces a stored container nor puts a
  proven from-start part up for removal on length alone.
- 2: a part holding video is never "inside" an audio-only landed part, nor
  inside a file merged here from separate streams (its length is the
  longer stream's).
- note 3: the store check fails closed: a pointer that does not read, a
  stored file that cannot be reached, or a source-media file no pointer
  names counts as stored, and nothing lands over it.
- note 6: a run asked to keep the stream marks it (and applies a pending
  keep) also when nothing landed.
- note 7: with a container stored, the zero-byte files of an empty group
  and a fragments-only group's .ytdl are not removed before the landing.

Tests: one per fix, red first; the Kick case asserts covered (a)'s row
guarantees and the 60 s boundary both sides; "landing 1.1" with a part
meant for removal; 2.3's empty-store guarantee restored.

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

Diffstat:
MOPERATING.md | 7+++++--
Mcommon/controller/recordLive.test.ts | 167++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
Mcommon/controller/recordLive.ts | 95+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------
Mcommon/lib/liveCapture.ts | 5+++++
4 files changed, 246 insertions(+), 28 deletions(-)

diff --git a/OPERATING.md b/OPERATING.md @@ -1452,8 +1452,11 @@ pnpm ops keep-videos --json '{"slug":"example-rumble","ids":["v1abcde"],"note": until acknowledged. A later recording does not clear that; nothing removes kept files automatically. On Kick, a VOD that covers the stream removes the channel's live-edge part; one that does not keeps it. A part not from the start (a live-edge part, one no row describes) goes only when the landed file is from the start and at least the - ENDED stream's own duration less 60 s — never on a coverage by the clock; an index-0 part is never "inside" a longer - one by itself. **A recording already in the store** (an earlier run's landing, a shutdown's included) is replaced + ENDED stream's own duration less 60 s — never on a coverage by the clock. Only a part PROVEN to begin at the start + (yt-dlp `--live-from-start`, a platform VOD read from its first segment: `provenStart`) counts as from the start for + a removal, a replacement or the coverage; an index-0 part, the browser path and a part of a row written before the + mark do not. A part with a picture is never "inside" an audio-only landed part, nor one merged here from separate + streams. A stored container that cannot be read, or a `source-media` file no pointer names, counts as stored. **A recording already in the store** (an earlier run's landing, a shutdown's included) is replaced only by a file that holds the whole stream from its start; otherwise nothing lands, every part stays listed (`keptParts`), the run is `failed` ("not landed: …") and needs a person — and whenever the landing keeps the stored container, nothing is removed. diff --git a/common/controller/recordLive.test.ts b/common/controller/recordLive.test.ts @@ -1093,7 +1093,7 @@ test("covered (b): a from-start landing that covers the stream removes an earlie fromStart: true, attempts: 1, mustKeep: true, - parts: [{ method: "ytdlp", url: ytUrl(id), fromStart: true, startedAt: "2026-11-20T01:00:00.000Z", stem: path.basename(earlier).replace(/\.mp4$/, "") }], + parts: [{ method: "ytdlp", url: ytUrl(id), fromStart: true, provenStart: true, startedAt: "2026-11-20T01:00:00.000Z", stem: path.basename(earlier).replace(/\.mp4$/, "") }], }); const { run } = await incidentRun(id, writesAfter(0), { meta: { ...YT_META(id), release_timestamp: Math.floor(Date.now() / 1000) - 590 } }); assert.equal((await run).status, "landed"); @@ -1164,7 +1164,7 @@ const okExit = { exitCode: 0, stderrTail: "", signalled: false }; const failEmpty = { exitCode: 1, stderrTail: EMPTY, signalled: false }; const left = async (id: string) => (await readdir(store()).catch(() => [] as string[])).filter((n) => n.startsWith(`.${id}.`)); // Run 1: `seconds` from its start, landed by an editor shutdown. -async function landedAtShutdown(id: string, seconds: number) { +async function landedAtShutdown(id: string, seconds: number, request: Record<string, unknown> = {}) { const ac = new AbortController(); const r = await incidentRun( id, @@ -1173,7 +1173,7 @@ async function landedAtShutdown(id: string, seconds: number) { ac.abort(); return { exitCode: null, stderrTail: "", signalled: true }; }, - { signal: ac.signal, deps: { shuttingDown: () => true } }, + { signal: ac.signal, request, deps: { shuttingDown: () => true } }, ); assert.equal((await r.run).status, "interrupted"); assert.equal(await storedSeconds(id), seconds); @@ -1245,12 +1245,16 @@ test("landing: a live-edge part goes only when the landed file is from the start const slug = "synth-kick-c"; await mkdir(path.join(CORPUS, "channels", slug, "data"), { recursive: true }); await writeFile(path.join(CORPUS, "channels", slug, "config.json"), JSON.stringify(KICK)); - for (const [uuid, duration, gone] of [ - ["01a164b1-0c18-723a-a785-f9637c98bbb1", null, false], - ["01a164b1-0c18-723a-a785-f9637c98bbb2", 5000, true], + // The VOD's length against the ended stream's duration: by the clock + // nothing is proven; with a duration the live-edge part goes at exactly + // duration - 60 s, not a second short (the tolerance, 100 s here, covers both). + for (const [uuid, duration, vod, gone] of [ + ["01a164b1-0c18-723a-a785-f9637c98bbb1", null, 5000, false], + ["01a164b1-0c18-723a-a785-f9637c98bbb2", 10000, 9940, true], + ["01a164b1-0c18-723a-a785-f9637c98bbb3", 10000, 9939, false], ] as const) { let reads = 0; - const meta = { id: uuid, extractor: "kick:vod", uploader_id: "synthc", release_timestamp: Math.floor(Date.now() / 1000) - 5000, formats: [{ protocol: "m3u8_native", height: 360, url: "https://stream.kick.com/y/360p30/playlist.m3u8" }] }; + const meta = { id: uuid, extractor: "kick:vod", uploader_id: "synthc", release_timestamp: Math.floor(Date.now() / 1000) - (duration ?? 5000), formats: [{ protocol: "m3u8_native", height: 360, url: "https://stream.kick.com/y/360p30/playlist.m3u8" }] }; await recordLiveRun({ paths, request: { slug, url: "https://kick.com/synthc" }, @@ -1274,8 +1278,8 @@ test("landing: a live-edge part goes only when the landed file is from the start return { exitCode: 0, stderrTail: "", signalled: false }; }, poll: async (o) => { - await writeFile(o.output, "format=mpegts;seconds=5000;"); - return { segments: 500, seconds: 5000, gaps: 0, firstSeq: 0, ended: "the VOD has not grown" }; + await writeFile(o.output, `format=mpegts;seconds=${vod};`); + return { segments: 500, seconds: vod, gaps: 0, firstSeq: 0, ended: "the VOD has not grown" }; }, land, freeBytes: async () => 1e15, @@ -1284,6 +1288,149 @@ test("landing: a live-edge part goes only when the landed file is from the start }, }); const files = (await readdir(path.join(paths.savedVideosDir, slug))).filter((n) => n.startsWith(`.${uuid}.`)); - assert.equal(files.length === 0, gone, `${uuid}: the channel's live-edge part ${gone ? "goes" : "is kept (coverage by the clock proves nothing)"}`); + assert.equal(files.length === 0, gone, `${uuid}: the channel's live-edge part ${gone ? "goes" : "is kept"}`); + const { listLiveRecordings } = await import("./liveRecordings"); + const row = (await listLiveRecordings(paths, { slug, id: uuid, all: true })).rows[0]!; + if (gone) { + // (covered (a)'s guarantees: removed, said why, nothing kept, nobody asked.) + assert.equal(row.coverage?.covers, true); + assert.equal(row.removedParts?.length, 1); + assert.match(row.removedParts![0]!.why, /holds the whole stream/); + assert.equal(row.keptParts, undefined); + assert.equal(row.needsAttention, false); + } else { + assert.equal(row.keptParts?.length, 1); + assert.equal(row.needsAttention, true); + } } }); + +// --- REVIEW-LF-1 ------------------------------------------------------------------ + +// An earlier run's row describing one part of the stream (a leftover in staging). +async function rowFor(id: string, stem: string, part: Record<string, unknown>) { + const { upsertLiveRecordingRow } = await import("../lib/liveRecordings-server"); + await ytChannel(); + await upsertLiveRecordingRow(paths, YT_SLUG, { + id, + url: ytUrl(id), + platform: "youtube", + startedAt: "2026-11-20T01:00:00.000Z", + status: "failed", + fromStart: true, + attempts: 1, + mustKeep: true, + parts: [{ method: "ytdlp", url: ytUrl(id), fromStart: true, startedAt: "2026-11-20T01:00:00.000Z", stem, ...part }], + } as never); +} +const UNSUPPORTED = "ERROR: [youtube] x: --live-from-start is passed, but there are no formats that can be downloaded from the start\n"; +// From its start unsupported: an index-0 part records `seconds`. +const index0Run = (seconds: number) => async (args: string[], n: number) => { + if (n === 1) return { exitCode: 1, stderrTail: UNSUPPORTED, signalled: false }; + await writeFile(`${outOf(args)}.mp4`, `format=mov,mp4;seconds=${seconds};`); + return okExit; +}; + +test("LF finding 1: an index-0 part is not proven from the start — it never replaces a stored container nor removes a proven from-start part, on length alone", async () => { + // (a) A stored container from the start; an index-0 run "covers" by length. + const a = "exmpllfidx2"; + await landedAtShutdown(a, 3600); + const r = await incidentRun(a, index0Run(7200), { meta: { ...YT_META(a), live_status: "post_live", duration: 7210 } }); + await assert.rejects(r.run, /not landed/); + assert.equal(await storedSeconds(a), 3600, "the stored start stays"); + // (b) An earlier proven from-start part; an index-0 landing that "covers" leaves it. + const b = "exmpllfidx3"; + const earlier = await leftover(b, 300); + await rowFor(b, path.basename(earlier).replace(/\.mp4$/, ""), { provenStart: true }); + const rb = await incidentRun(b, index0Run(7200), { meta: { ...YT_META(b), live_status: "post_live", duration: 7210 } }); + assert.equal((await rb.run).status, "landed"); + assert.ok((await stat(earlier)).size > 0, "the proven from-start part is kept"); + assert.equal((await rowOf(b)).find((x) => x.status === "landed")!.coverage?.covers, false); +}); + +test("LF finding 2: a part holding video is never 'inside' a longer audio-only landed part", async () => { + const id = "exmpllfvid1"; + const ac = new AbortController(); + const { run } = await incidentRun( + id, + async (args, n) => { + if (n === 1) { + // Only its audio stream wrote (3 h of backlog); the video failed. + await writeFile(`${outOf(args)}.f140.m4a`, "format=mp4;seconds=10800;v=none;"); + return { exitCode: 1, stderrTail: "1: ERROR: The downloaded file is empty\n", signalled: false }; + } + // Both streams, merged, 1 h — then a Cancel. + await writeFile(`${outOf(args)}.mp4`, "format=mov,mp4;seconds=3600;"); + ac.abort(); + return { exitCode: null, stderrTail: "", signalled: true }; + }, + { signal: ac.signal, request: { doNotClean: false, note: undefined } }, + ); + await run; + assert.ok((await left(id)).some((n) => /ytdlp-a2\.mp4$/.test(n)), `the only video stays: ${(await left(id)).join(", ")}`); +}); + +test("LF note 3: no pointer, but a source-media file in the store: a container is stored (fail closed) — nothing lands over it", async () => { + const id = "exmpllfstr1"; + const { savedVideoDir } = await import("../lib/savedVideo"); + const dir = savedVideoDir(paths, YT_CONFIG, YT_SLUG, id); + await mkdir(dir, { recursive: true }); + await writeFile(path.join(dir, "source-media.mp4"), "format=mov,mp4;seconds=9000;"); + const r = await incidentRun(id, writesAfter(0), { meta: { ...YT_META(id), release_timestamp: Math.floor(Date.now() / 1000) - 590 } }); + await assert.rejects(r.run, /not landed/); + assert.equal(await readFile(path.join(dir, "source-media.mp4"), "utf8"), "format=mov,mp4;seconds=9000;", "the unnamed container is untouched"); +}); + +test("LF note 6: a run asked to keep the stream marks it even when nothing landed", async () => { + const id = "exmpllfkep1"; + await landedAtShutdown(id, 3600, { doNotClean: false, note: undefined }); + assert.equal(await isDoNotClean(dataDir(id)), false); + const r = await incidentRun(id, async (args, n) => { + if (n <= 3) return failEmpty; + await writeFile(`${outOf(args)}.mp4`, "format=mov,mp4;seconds=2000;"); + return okExit; + }); + await assert.rejects(r.run, /not landed/); + assert.equal(await isDoNotClean(dataDir(id)), true); +}); + +test("LF note 5: a row's part with no proven-start mark (an older row) is not removed under coverage; marked, it is", async () => { + const id = "exmpllfold1"; + const earlier = await leftover(id, 300); + await rowFor(id, path.basename(earlier).replace(/\.mp4$/, ""), {}); + const r = await incidentRun(id, writesAfter(0), { meta: { ...YT_META(id), release_timestamp: Math.floor(Date.now() / 1000) - 590 } }); + assert.equal((await r.run).status, "landed"); + assert.ok((await stat(earlier)).size > 0, "kept: not proven from its start"); +}); + +test("LF 9/10: landing 1.1 with a part meant for removal — kept when the store keeps its own", async () => { + const id = "exmpllf1102"; + const one = await incidentRun(id, async (args) => { + await writeFile(`${outOf(args)}.mp4`, "format=mov,mp4;seconds=7300;"); + return okExit; + }); + assert.equal((await one.run).status, "landed"); + const earlier = await leftover(id, 300); + await rowFor(id, path.basename(earlier).replace(/\.mp4$/, ""), { provenStart: true }); + const two = await incidentRun(id, async (args) => { + await writeFile(`${outOf(args)}.mp4`, "format=mov,mp4;seconds=7200;"); + return okExit; + }); + await assert.rejects(two.run, /not landed/); + assert.ok((await stat(earlier)).size > 0); + const row = (await rowOf(id)).find((x) => x.status === "failed" && /not landed/.test(x.error ?? ""))!; + assert.ok(row.keptParts?.some((k) => /kept: nothing was landed/.test(k.why)), "the part meant for removal is kept and says so"); + assert.equal(row.removedParts, undefined); +}); + +test("LF 9: with an empty store a short from-start partial lands and does not supersede (2.3's guarantee)", async () => { + const id = "exmpllf2301"; + const first = await incidentRun(id, writesAfter(Infinity)); + await assert.rejects(first.run); + const short = await incidentRun(id, writesAfter(0)); + assert.equal((await short.run).status, "landed"); + assert.ok(short.log.some((l) => /does not supersede/.test(l))); + const rows = await rowOf(id); + assert.equal(rows.find((r) => r.status === "landed")!.coverage?.covers, false); + assert.equal(rows.find((r) => r.status === "failed")!.needsAttention, true); +}); diff --git a/common/controller/recordLive.ts b/common/controller/recordLive.ts @@ -98,7 +98,7 @@ import { setDoNotClean } from "../lib/doNotClean-server"; import type { Paths } from "../lib/paths"; import { detectPlatform } from "../lib/platform"; import { savedVideoDir, savedVideoPath, savedVideoRoot } from "../lib/savedVideo"; -import { loadSavedVideo } from "../lib/savedVideo-server"; +import { loadSavedVideo, savedVideoPointerPath } from "../lib/savedVideo-server"; import { assertSavedVideosStoreWritable } from "../lib/savedVideoStore"; import { getFreeBytes } from "../lib/diskSpace"; import { formatBytes } from "../lib/format"; @@ -1094,6 +1094,9 @@ async function recordLiveRunInner( const file = separate ? stemPath(tag) : partPath(tag); const part = begin("ytdlp", url, file, mode !== "now"); if (mode === "index0") part.index0 = true; + // Proven from the stream's start: yt-dlp `--live-from-start` (the + // extractor's own generator from fragment 0). + if (mode === "from-start") part.provenStart = true; await save(); const args = ytdlpLiveArgs({ url, @@ -1155,6 +1158,8 @@ async function recordLiveRunInner( if (vodFmt) { const file = partPath("vod"); const part = begin("vod-poll", vodFmt.url, file, true); + // The platform's VOD of the stream, read from its first segment. + part.provenStart = true; await save(); poll = (deps.poll ?? pollEventPlaylist)({ playlistUrl: vodFmt.url, @@ -1335,9 +1340,43 @@ async function recordLiveRunInner( const merge = deps.merge ?? ((args: string[], s: AbortSignal) => runFfmpegHeavy(paths, args, s)); const at = (n: string) => path.join(slugStore, n); // Every part on disk now — this run's and an earlier run's — by its stem. + // WHAT THE STORE HOLDS for this id, failing CLOSED: a pointer that does not + // read, a stored file that cannot be reached, or a source-media file no + // pointer names is "stored, not proven" — never an empty store. + const storeState = async (): Promise<{ kind: "empty" } | { kind: "stored"; path: string } | { kind: "unknown"; why: string }> => { + const pointerFile = savedVideoPointerPath(videoDir); + const pst = await stat(pointerFile).then( + () => "there" as const, + (e: NodeJS.ErrnoException) => (e.code === "ENOENT" ? ("absent" as const) : ("error" as const)), + ); + if (pst === "error") return { kind: "unknown", why: "the store's pointer cannot be read" }; + const pointer = pst === "there" ? await loadSavedVideo(videoDir).catch(() => null) : null; + if (pst === "there" && !pointer) return { kind: "unknown", why: "the store's pointer does not read" }; + if (pointer) { + const sp = savedVideoPath(pointer); + const st = await stat(sp).then( + (x) => (x.isFile() ? ("file" as const) : ("other" as const)), + (e: NodeJS.ErrnoException) => (e.code === "ENOENT" ? ("absent" as const) : ("error" as const)), + ); + if (st === "file") return { kind: "stored", path: sp }; + if (st !== "absent") return { kind: "unknown", why: `the stored file ${path.basename(sp)} cannot be reached` }; + } + const names = await readdir(storeDir).then( + (x) => x, + (e: NodeJS.ErrnoException) => (e.code === "ENOENT" ? [] : null), + ); + if (names === null) return { kind: "unknown", why: "the store's folder cannot be read" }; + const sm = names.find((n) => n.startsWith("source-media.")); + return sm ? { kind: "unknown", why: `${sm} is in the store with no pointer naming it` } : { kind: "empty" }; + }; + // With a container stored, no file of a part is removed before the landing + // decides (the zero-byte files, a fragments-only group's state). + const storeHeld = (await storeState()).kind !== "empty"; const groups = livePartFiles(id, await readdir(slugStore).catch(() => [] as string[])); const partOf = new Map(parts.map((p) => [p.stem, p.part])); - type Candidate = { file: string; seconds: number | null; part?: LivePart; group: LivePartFiles }; + // video: it holds a picture; merged: record-live merged it from separate + // streams here (its length is the longer stream's). + type Candidate = { file: string; seconds: number | null; part?: LivePart; group: LivePartFiles; video: boolean; merged: boolean }; const candidates: Candidate[] = []; const unlandable: string[] = []; const unlandableGroups: { group: LivePartFiles; why: string; part?: LivePart }[] = []; @@ -1360,10 +1399,13 @@ async function recordLiveRunInner( if (got && "error" in got) { unlandable.push(`${g.stem}: ${got.error}`); unlandableGroups.push({ group: g, why: got.error, ...(part ? { part } : {}) }); - } else if (got) candidates.push({ file: got.file, seconds: got.seconds, group: g, ...(part ? { part } : {}) }); + } else if (got) { + const video = Boolean((await probe(got.file, landSignal).catch(() => null))?.videoCodec); + candidates.push({ file: got.file, seconds: got.seconds, group: g, video, merged: got.merged === true, ...(part ? { part } : {}) }); + } else { empty.push(g); - for (const f of [...g.finished, ...g.streams, ...g.scratch]) if ((await sizeOf(at(f))) === 0) await rm(at(f), { force: true }); + if (!storeHeld) for (const f of [...g.finished, ...g.streams, ...g.scratch]) if ((await sizeOf(at(f))) === 0) await rm(at(f), { force: true }); } } for (const u of unlandable) say(`Not landable: ${u}`); @@ -1397,7 +1439,7 @@ async function recordLiveRunInner( for (const u of unlandableGroups) others.push({ group: u.group, why: `not landable as it is: ${u.why}`, ...(u.part ? { part: u.part } : {}) }); for (const g of empty) { // Fragments a recorder left hold media too; yt-dlp's resume state does not. - for (const f of g.scratch) if (/\.ytdl$/i.test(f)) await rm(at(f), { force: true }); + if (!storeHeld) for (const f of g.scratch) if (/\.ytdl$/i.test(f)) await rm(at(f), { force: true }); const part = partOf.get(g.stem); others.push({ group: g, why: "fragments a recorder left, not landable as they are", ...(part ? { part } : {}) }); } @@ -1452,15 +1494,21 @@ async function recordLiveRunInner( // first LISTED segment) unless the playlist was read to reach the start: on // a DVR window that slides, a later one starts later. Those go only by the // coverage rule. - const sure = (p: LivePart) => !p.index0 || record.reach?.fromStart === true; + // PROVEN from the start: a part marked so when it was recorded (yt-dlp + // `--live-from-start`, a platform VOD from its first segment). An index-0 + // part, the browser path, and a part of a row written before the mark are + // not proven, whatever `fromStart` says. + const proven = (p: Pick<LivePart, "fromStart" | "provenStart"> | undefined) => p?.fromStart === true && p.provenStart === true; + // Never a part with a picture beside a landed part with none, nor beside a + // landed file merged here from separate streams (its length is the longer + // stream's: its picture may be shorter). const contained = (c: Candidate) => c !== best && c.part !== undefined && best.part !== undefined && - c.part.fromStart && - best.part.fromStart && - sure(c.part) && - sure(best.part) && + proven(c.part) && + proven(best.part) && + !(c.video && (!best.video || best.merged)) && c.seconds !== null && best.seconds !== null && c.seconds <= best.seconds; @@ -1496,11 +1544,13 @@ async function recordLiveRunInner( // also decides superseding). Its own record says whether it was from the // start: this run's part, or an earlier run's by the channel's rows (a part // no row names is not known to be). - let landedFromStart: boolean | null = best.part ? best.part.fromStart : null; + // Proven, not merely marked fromStart (REVIEW-LF-1 1): this run's part, or + // an earlier run's by its row. + let landedFromStart: boolean | null = best.part ? proven(best.part) : null; if (landedFromStart === null) { const rows = await loadLiveRecordingRows(paths, req.slug).catch(() => []); const p = rows.filter((r) => r.id === id).flatMap((r) => r.parts).find((x) => x.stem === best.group.stem); - landedFromStart = p ? p.fromStart : null; + landedFromStart = p ? proven(p) : null; } record.coverage = streamCoverage({ capturedSeconds: best.seconds, @@ -1524,7 +1574,7 @@ async function recordLiveRunInner( const endedDuration = cov.basis === "duration" ? cov.streamSeconds : null; const mayHoldEnd = (o: Other): boolean => { const p = o.part ?? placeOf.get(o.group.stem); - if (p?.fromStart && sure(p)) return false; + if (proven(p)) return false; return !(landedFromStart === true && best.seconds !== null && endedDuration !== null && best.seconds >= endedDuration - 60); }; for (const o of others) { @@ -1573,6 +1623,16 @@ async function recordLiveRunInner( if (kept.length) record.keptParts = kept; sayKept(); await save(); + // The operator's keep marks hold whatever landed (as main did). + if (req.doNotClean) { + await setDoNotClean(videoDir, true, { + by: "live-recording", + via: "record-live", + ...(opts.jobId ? { jobId: opts.jobId } : {}), + ...(req.note ? { note: req.note } : {}), + }).catch((e: Error) => say(`"Do not clean" could not be set (${e.message}).`)); + } + await applyPendingKeep(paths, req.slug, id, onLog, opts.jobId).catch((e: Error) => say(`The pending keep could not be applied (${e.message}).`)); summary.status = record.status; say(`${RECORD_LIVE_RESULT_MARKER}${JSON.stringify(summary)}`); if (!cancelled) throw new Error(record.error); @@ -1582,9 +1642,12 @@ async function recordLiveRunInner( // included) is replaced only by a file that holds the whole stream from its // start (the coverage rule): "longer" is not containment — a live-edge part // after a restart is longer and holds none of the stored start. - const pointer = await loadSavedVideo(videoDir).catch(() => null); - const storedPath = pointer ? savedVideoPath(pointer) : null; - if (storedPath && (await stat(storedPath).then((x) => x.isFile(), () => false)) && !cov.covers) { + const store = await storeState(); + if (store.kind === "unknown") { + return notLanded(`${store.why}: a container may be stored, and nothing lands over it unproven`); + } + if (store.kind === "stored" && !cov.covers) { + const storedPath = store.path; const storedSeconds = (await probe(storedPath, landSignal).catch(() => null))?.seconds ?? null; return notLanded( `the store already holds a recording of this stream (${storedSeconds !== null ? spanWords(storedSeconds) : "length unknown"}), ` + diff --git a/common/lib/liveCapture.ts b/common/lib/liveCapture.ts @@ -452,6 +452,11 @@ export type LivePart = { // Recorded `--no-live-from-start` with ffmpeg at the playlist's first listed // segment: from the start only if the playlist reaches it. index0?: boolean; + // Proven to begin at the stream's start: yt-dlp `--live-from-start`, or a + // platform VOD read from its first segment. A part without it (index-0, the + // browser path, rows written before the mark) is never taken as holding + // the start for a removal or a replacement. + provenStart?: boolean; }; export type MissingStream = "video" | "audio" | "unknown";