Archilyzer · Source

archilyzer

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

commit c7b52810ac344c69592b36a318f0f4c405a60c7b
parent 168a4c8f88bb41693ddd577d400d883d23bc76af
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Sat, 21 Nov 2026 04:14:12 -0500

record-live: a part is kept only when it might hold time the landed file does not

Ruling on the Kick follow-up: when the landed file is from the start (or a
platform VOD) and covers the whole stream by the same rule that decides
superseding (its length against the ended stream's duration, else the clock,
within max(60 s, 1 %)), every other part of the stream, this run's or an
earlier one's, is inside it and is removed, listed on the row as
removedParts with why, and nobody is asked. When it does not cover the stream
(live edge only, a partial, a length that cannot be established), every other
part with bytes is kept and needs a person, as before. Whether an earlier
run's landed part was from its start is read from the channel's rows; a part
no row names is not known to be, and keeps.

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

Diffstat:
MOPERATING.md | 17++++++++++-------
Mcommon/controller/liveRecordings.ts | 1+
Mcommon/controller/recordLive.test.ts | 103+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcommon/controller/recordLive.ts | 104++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------
Mcommon/lib/liveCapture.ts | 7+++++++
Mcommon/lib/liveRecordings-server.ts | 3+++
Meditor/CHANGELOG.md | 5+++--
7 files changed, 201 insertions(+), 39 deletions(-)

diff --git a/OPERATING.md b/OPERATING.md @@ -1138,13 +1138,16 @@ pnpm ops keep-videos --json '{"slug":"example-rumble","ids":["v1abcde"],"note": A recording that falls back to the live edge says in the log and the record what it lost ("the first 2 h 14 min are NOT recorded"); that is a failure needing a person even while the live edge records. When the attempts end with one stream missing, the row says which (`missingStream`) and the parts that hold bytes are kept. -- **The landing never removes media it is not known to hold.** The longest part lands. A shorter part of the same - run, both from the start, is inside it and goes. Every other part that holds bytes — an earlier run's, one - recorded from the live edge while the landed one is from the start (or the other way round), one that cannot be - landed as it is (video with no audio), fragments a recorder left — stays in the store's staging dir, listed on the - record and the row as `keptParts` (each with its files and sizes, and why), and the row needs a person until it is - acknowledged. A later recording does not clear that; nothing removes those files automatically. On Kick, where - the VOD from its start and the channel's live edge are recorded side by side, the shorter one is kept the same way. +- **The landing never removes media it is not known to hold.** The longest part lands. When the landed file is + from the start (or a platform VOD) and covers the whole stream — the `coverage` rule below: its length against the + ended stream's `duration`, else the clock, within max(60 s, 1 %) — every other part of the stream, this run's or an + earlier one's, is inside it and is removed, with no attention raised; the row lists them as `removedParts` (stem, + bytes, why). A shorter part of the same run, both from the start, goes too. When the landed file does NOT cover + the stream (live edge only, a partial, or a stream whose length cannot be established), every other part that + holds bytes — an earlier run's, one from the live edge, one that cannot be landed as it is, fragments a recorder + left — stays in the store's staging dir, listed as `keptParts` (files, sizes, why), and the row needs a person + 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. - **An editor shutdown is not a Cancel.** A run stopped by the editor going down (a restart, a rollout) is `interrupted` (`stoppedBy: "shutdown"`), never `cancelled`, and needs a person — Record again if the stream is still live. A person's Cancel is `cancelled`; it needs a person only when the stream was must-keep (`doNotClean` or a diff --git a/common/controller/liveRecordings.ts b/common/controller/liveRecordings.ts @@ -267,6 +267,7 @@ export async function listLiveRecordings(paths: Paths, opts: ListLiveRecordingsO ...(own?.missingStream ? { missingStream: own.missingStream } : {}), ...(own?.stoppedBy ? { stoppedBy: own.stoppedBy } : {}), ...(own?.keptParts ? { keptParts: own.keptParts } : {}), + ...(own?.removedParts ? { removedParts: own.removedParts } : {}), ...(own?.coverage ? { coverage: own.coverage } : {}), attempts: own?.attempts ?? row.attempts, parts, diff --git a/common/controller/recordLive.test.ts b/common/controller/recordLive.test.ts @@ -1046,3 +1046,106 @@ test("Record again asks what the run was asked: from the start, quality, transcr { fromStart: true, maxHeight: 480, transcribe: true, doNotClean: true, note: "keep", preclip }, ); }); + +// --- Kept only when its footage might not be inside the landed file ---------------- +// +// When the landed file is from the start (or a platform VOD) and covers the +// whole stream (streamCoverage, the 2.3 rule), every other part is inside it +// and goes, recorded on the row; otherwise every other part with bytes stays. + +const leftover = async (id: string, seconds: number) => { + await mkdir(store(), { recursive: true }); + const f = path.join(store(), `.${id}.live-2026-11-20T01-00-00-000Z.ytdlp.mp4`); + await writeFile(f, `format=mov,mp4;seconds=${seconds};`); + return f; +}; + +test("covered (a): a Kick VOD that covers the stream lands, the channel's live-edge part is removed, nobody is asked", async () => { + const KICK = { handling: "transcribe", url: "https://kick.com/synthb/videos", platform: "kick", name: "Synth Kick B" } as ChannelConfig; + const slug = "synth-kick-b"; + await mkdir(path.join(CORPUS, "channels", slug, "data"), { recursive: true }); + await writeFile(path.join(CORPUS, "channels", slug, "config.json"), JSON.stringify(KICK)); + const uuid = "01a164b1-0c18-723a-a785-f9637c98aaaa"; + const s = await recordLiveRun({ + paths, + request: { slug, url: "https://kick.com/synthb" }, + plan: { url: "https://kick.com/synthb", platform: "kick", id: null, kickChannel: "synthb" }, + channelConfig: KICK, + cookiePolicy: NO_COOKIES, + onLog: () => {}, + signal: new AbortController().signal, + deps: { + kickVod: async () => ({ id: uuid, url: `https://kick.com/synthb/videos/${uuid}` }), + refresh: refreshWith({ + id: uuid, + extractor: "kick:vod", + live_status: "is_live", + uploader_id: "synthb", + // Started 5000 s ago: the VOD's 5000 s is the whole stream. + release_timestamp: Math.floor(Date.now() / 1000) - 5000, + formats: [{ protocol: "m3u8_native", height: 360, url: "https://stream.kick.com/y/360p30/playlist.m3u8" }], + }), + spawn: async ({ args }) => { + await writeFile(args[args.indexOf("-o") + 1]!, "format=mpegts;seconds=1000;"); + 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" }; + }, + land, + freeBytes: async () => 1e15, + handoff, + shuttingDown: () => false, + }, + }); + assert.equal(s.landed?.seconds, 5000); + assert.deepEqual((await readdir(path.join(paths.savedVideosDir, slug))).filter((n) => n.startsWith(`.${uuid}.`)), [], "the live-edge part went"); + const { listLiveRecordings } = await import("./liveRecordings"); + const row = (await listLiveRecordings(paths, { slug, id: uuid, all: true })).rows[0]!; + assert.equal(row.coverage?.covers, true); + assert.equal(row.keptParts, undefined); + assert.equal(row.removedParts?.length, 1); + assert.match(row.removedParts![0]!.why, /holds the whole stream/); + assert.equal(row.needsAttention, false); +}); + +test("covered (b): a from-start landing that covers the stream removes an earlier run's partial, nobody is asked", async () => { + const id = "exmplcov0b1"; + const earlier = await leftover(id, 300); + 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"); + await assert.rejects(stat(earlier), "the earlier partial is inside the landed file"); + const row = (await rowOf(id))[0]!; + assert.equal(row.coverage?.covers, true); + assert.equal(row.keptParts, undefined); + assert.equal(row.removedParts?.length, 1); + assert.equal(row.needsAttention, false); +}); + +test("not covered (c): a landing shorter than the stream keeps the earlier run's part, and needs a person", async () => { + const id = "exmplcov0c1"; + const earlier = await leftover(id, 300); + const { run } = await incidentRun(id, writesAfter(0)); // 600 s of a stream two hours old + assert.equal((await run).status, "landed"); + assert.ok((await stat(earlier)).size > 0, "kept"); + const row = (await rowOf(id))[0]!; + assert.equal(row.coverage?.covers, false); + assert.equal(row.keptParts?.length, 1); + assert.equal(row.keptParts![0]!.run, "earlier"); + assert.equal(row.needsAttention, true); +}); + +test("not covered (d): a stream whose length cannot be established keeps every other part", async () => { + const id = "exmplcov0d1"; + const earlier = await leftover(id, 300); + // No start time and no duration: the stream's length is not known. + const { run } = await incidentRun(id, writesAfter(0), { meta: YT_META(id) }); + assert.equal((await run).status, "landed"); + assert.ok((await stat(earlier)).size > 0, "kept"); + const row = (await rowOf(id))[0]!; + assert.equal(row.coverage?.streamSeconds, null); + assert.equal(row.coverage?.covers, false); + assert.equal(row.keptParts?.length, 1); + assert.equal(row.needsAttention, true); +}); diff --git a/common/controller/recordLive.ts b/common/controller/recordLive.ts @@ -79,6 +79,7 @@ import { spanWords, ytdlpLiveArgs, type KeptPart, + type RemovedPart, type LiveFailureClass, type LivePart, type LivePartFiles, @@ -91,7 +92,7 @@ import { type StreamCoverage, } from "../lib/liveCapture"; import { liveRecordingSidecar } from "../lib/mediaImport-server"; -import { rowOfRecord, upsertLiveRecordingRow } from "../lib/liveRecordings-server"; +import { loadLiveRecordingRows, rowOfRecord, upsertLiveRecordingRow } from "../lib/liveRecordings-server"; import { liveRecordingCheckCommand } from "./liveRecordings"; import { setDoNotClean } from "../lib/doNotClean-server"; import type { Paths } from "../lib/paths"; @@ -1386,21 +1387,35 @@ async function recordLiveRunInner( why, }); }; - for (const u of unlandableGroups) await keep(u.group, `not landable as it is: ${u.why}`, { ...(u.part ? { part: u.part } : {}) }); + // Every part that is not the landed one, and why it would be kept. + type Other = { group: LivePartFiles; why: string; seconds?: number | null; part?: LivePart; extra?: string[] }; + const others: Other[] = []; + 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 }); const part = partOf.get(g.stem); - await keep(g, "fragments a recorder left, not landable as they are", { ...(part ? { part } : {}) }); + others.push({ group: g, why: "fragments a recorder left, not landable as they are", ...(part ? { part } : {}) }); } + const removed: RemovedPart[] = []; + const removeGroup = async (g: LivePartFiles, why: string, extra: string[] = []) => { + let bytes = 0; + for (const f of [...new Set([...extra.map((e) => path.basename(e)), ...g.finished, ...g.streams, ...g.scratch])]) { + bytes += await sizeOf(at(f)); + await rm(at(f), { force: true }); + } + if (bytes > 0) removed.push({ stem: g.stem, bytes, why }); + }; const sayKept = () => { for (const k of kept) { say(`Kept, not landed: ${k.stem} (${formatBytes(k.bytes)}, ${k.files.length} file${k.files.length === 1 ? "" : "s"}) — ${k.why}.`); } if (kept.length) say(`${kept.length} part${kept.length === 1 ? " is" : "s are"} kept in staging, listed in pnpm ops get live-recordings ${req.slug}/${id}; nothing removes them.`); + for (const r of removed) say(`Removed: ${r.stem} (${formatBytes(r.bytes)}) — ${r.why}.`); }; if (candidates.length === 0) { + for (const o of others) await keep(o.group, o.why, o); const error = [ unlandable.length ? `nothing landable was recorded (${unlandable.join("; ")})` : null, attemptsSummary ? `${unlandable.length ? "" : "nothing was recorded — "}${attemptsSummary}` : null, @@ -1422,10 +1437,9 @@ async function recordLiveRunInner( } candidates.sort((a, b) => (b.seconds ?? -1) - (a.seconds ?? -1)); const best = candidates[0]!; - // Inside the landed file: a shorter part of THIS run, both from the start - // (both begin where the stream's record begins). Nothing else is assumed: - // an earlier run's part, or one recorded from the live edge, may hold time - // the landed one does not. + // Inside the landed file without asking how long the stream is: a shorter + // part of THIS run, both from the start (both begin where the stream's + // record begins). const contained = (c: Candidate) => c !== best && c.part !== undefined && @@ -1435,22 +1449,62 @@ async function recordLiveRunInner( c.seconds !== null && best.seconds !== null && c.seconds <= best.seconds; + const where = (p?: LivePart) => (p ? (p.fromStart ? "from its start" : "from the live edge") : "by an earlier run"); for (const c of candidates) { say(`part ${path.basename(c.file)}: ${c.seconds !== null ? `${Math.round(c.seconds)} s` : "length unknown"}${c === best ? " — landed" : ""}`); - if (c === best || contained(c)) continue; - const where = (p?: LivePart) => (p ? (p.fromStart ? "from its start" : "from the live edge") : "by an earlier run"); - await keep( - c.group, - c.part && best.part - ? `recorded ${where(c.part)}, the landed part ${where(best.part)}: it may hold time the landed part does not` - : `recorded ${where(c.part)}; the landed part was recorded ${where(best.part)}: it may hold time the landed part does not`, - { seconds: c.seconds, ...(c.part ? { part: c.part } : {}), extra: [c.file] }, - ); + if (c === best) continue; + if (contained(c)) { + await removeGroup(c.group, "a shorter part of this run from its start: inside the landed part", [c.file]); + continue; + } + others.push({ + group: c.group, + why: + c.part && best.part + ? `recorded ${where(c.part)}, the landed part ${where(best.part)}: it may hold time the landed part does not` + : `recorded ${where(c.part)}; the landed part was recorded ${where(best.part)}: it may hold time the landed part does not`, + seconds: c.seconds, + ...(c.part ? { part: c.part } : {}), + extra: [c.file], + }); } if (separate && !record.missingStream) { const bp = await probe(best.file, landSignal).catch(() => null); if (bp && !bp.videoCodec) record.missingStream = "video"; } + // DOES THE LANDED FILE HOLD THE WHOLE STREAM (streamCoverage, the rule that + // 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; + 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; + } + record.coverage = streamCoverage({ + capturedSeconds: best.seconds, + endMeta, + streamStartedAt: record.streamStartedAt ?? null, + lastEndedAt: record.parts.reduce<string | null>((m, p) => (p.endedAt && (!m || p.endedAt > m) ? p.endedAt : m), null), + wholeFromStart: landedFromStart === true && !record.missingStream, + }); + const cov = record.coverage; + // 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 + // not known — every other part with bytes is kept and needs a person. + for (const o of others) { + if (cov.covers) { + await removeGroup( + o.group, + `inside the landed file, which holds the whole stream from its start (${spanWords(cov.capturedSeconds ?? 0)} of ${spanWords(cov.streamSeconds ?? 0)}, ${cov.basis === "duration" ? "its duration" : "by the clock"})`, + o.extra ?? [], + ); + } else { + await keep(o.group, o.why, o); + } + } const landed = await landMediaFile({ paths, slug: req.slug, @@ -1466,13 +1520,9 @@ async function recordLiveRunInner( ...(deps.land ? { deps: deps.land } : {}), }); // The landed part's files were staging scratch (it is moved or copied into - // the store), and so were the streams a merge was made from, and a part - // the landed one contains. Every other part stays (above). - for (const c of candidates) { - if (c !== best && !contained(c)) continue; - await rm(c.file, { force: true }); - for (const f of [...c.group.finished, ...c.group.streams, ...c.group.scratch]) await rm(at(f), { force: true }); - } + // the store), and so were the streams a merge was made from. + await rm(best.file, { force: true }); + for (const f of [...best.group.finished, ...best.group.streams, ...best.group.scratch]) await rm(at(f), { force: true }); sayKept(); record.landedPart = best.part ? record.parts.indexOf(best.part) : undefined; record.kept = landed.kept; @@ -1480,13 +1530,7 @@ async function recordLiveRunInner( if (stopped) record.stoppedBy = stopped.by; if (kept.length) record.keptParts = kept; record.endedAt = now().toISOString(); - record.coverage = streamCoverage({ - capturedSeconds: best.seconds, - endMeta, - streamStartedAt: record.streamStartedAt ?? null, - lastEndedAt: record.parts.reduce<string | null>((m, p) => (p.endedAt && (!m || p.endedAt > m) ? p.endedAt : m), null), - wholeFromStart: fromStart && !record.fallback && !record.missingStream && best.part?.fromStart === true, - }); + if (removed.length) record.removedParts = removed; if (record.missingStream) say(`Landed without its ${record.missingStream} stream: it needs a person.`); if (!record.coverage.covers && record.coverage.streamSeconds !== null && record.coverage.capturedSeconds !== null) { say( diff --git a/common/lib/liveCapture.ts b/common/lib/liveCapture.ts @@ -469,6 +469,11 @@ export type KeptPart = { why: string; }; +// A part the landing removed, and why (a part inside the landed file: a +// shorter part of the same run from its start, or any part when the landed +// file holds the whole stream — StreamCoverage). +export type RemovedPart = { stem: string; bytes: number; why: string }; + // Whether the landed recording holds the whole stream: what supersedes an // earlier failure (lib/liveRecordings-server.ts). `basis` is where the // stream's length came from: the ended stream's own `duration`, else the @@ -529,6 +534,8 @@ export type LiveRecordingRecord = { stoppedBy?: "operator" | "shutdown"; // Parts left on disk, not landed (KeptPart). keptParts?: KeptPart[]; + // Parts the landing removed as inside the landed file (RemovedPart). + removedParts?: RemovedPart[]; // Once landed: does it hold the whole stream (StreamCoverage). coverage?: StreamCoverage; }; diff --git a/common/lib/liveRecordings-server.ts b/common/lib/liveRecordings-server.ts @@ -27,6 +27,7 @@ import type { Paths } from "./paths"; import { readJsonFile, withJsonFileLock, writeJsonAtomic } from "./jsonFile-server"; import type { KeptPart, + RemovedPart, LiveFailureClass, LivePart, LiveRecordingRecord, @@ -68,6 +69,7 @@ export type LiveRecordingRow = { missingStream?: MissingStream; stoppedBy?: "operator" | "shutdown"; keptParts?: KeptPart[]; + removedParts?: RemovedPart[]; coverage?: StreamCoverage; acknowledgedAt?: string; acknowledgedBy?: string; @@ -227,6 +229,7 @@ export function rowOfRecord( ...(rec.missingStream ? { missingStream: rec.missingStream } : {}), ...(rec.stoppedBy ? { stoppedBy: rec.stoppedBy } : {}), ...(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 } } : {}), }; } diff --git a/editor/CHANGELOG.md b/editor/CHANGELOG.md @@ -14,8 +14,9 @@ - Why an attempt failed decides what follows: a stream that has ended, gone private, is members-only, or a full disk is not retried; a 429 or YouTube's bot check gets one more try after 15 minutes, then stops; the row says which (`failureClass`). An attempt where only one of the two streams recorded is retried too. - - The landing no longer deletes a part it is not known to hold (an earlier run's, one from the live edge, one it - cannot land): those stay in staging, listed with their sizes, until acknowledged. + - The landing no longer deletes a part it is not known to hold. When the landed file covers the whole stream from + its start (or is a platform VOD that does), the other parts go, listed on the row. Otherwise they stay in staging, + listed with their sizes, until acknowledged. - An editor shutdown leaves a recording `interrupted` (it needs you), never `cancelled`; cancelling a must-keep stream needs you too. A stalled recording is said beside the failures. Only a recording that holds the whole stream from its start clears an earlier failure. `--wait-started` exits 3 when only the live edge records.