Archilyzer · Source

archilyzer

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

commit dce39d1f94f3deb89e81ca2b7e47a37131ed3590
parent 776c915250ed855b3c429c251c22057c5205eb48
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Tue, 24 Nov 2026 12:49:23 -0500

record-live: REVIEW-8 4-6: offline cleared at the end, the raw copy asks the landing's own room, Verify again takes the lock; docs

- 4: record.offline is cleared where the restart loop ends, whether by a
  landing or a cancel.
- 5: the raw-source copy asks its size plus the landing's 2 GB margin
  (LAND_MEDIA_DISK_MARGIN_BYTES), not the recorders' 20 GB floor.
- 6: "Verify again" takes each stem's lock and refuses while a recorder
  holds it; its own lock is never among the removals.
- OPERATING.md: Record live is on the channel page under the Cleanup stage,
  "Media for the whole channel", and on a video page under "Media tools".

Tests red on 776c91525.

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

Diffstat:
MOPERATING.md | 3++-
Mcommon/controller/recordLive.test.ts | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcommon/controller/recordLive.ts | 25++++++++++++++++++++++++-
3 files changed, 89 insertions(+), 2 deletions(-)

diff --git a/OPERATING.md b/OPERATING.md @@ -1400,7 +1400,8 @@ pnpm ops import-media --json '{"slug":"example-archive","path":"/mnt/old/talk.mk pnpm ops keep-videos --json '{"slug":"example-rumble","ids":["v1abcde"],"note":"keep"}' ``` -- `record-live` (the channel page's Media → **Record live**, or a video's Media tools) records until the stream +- `record-live` (the channel page → the Cleanup stage → **Media for the whole channel** → Record live, or a video's page + → **Media tools**) records until the stream ends — hours, one job per stream on its own queue — then lands the recording as the video's source. From the start by default: Rumble's DVR playlist holds a stream's first 4 hours (past that, the last 4), which yt-dlp's `--live-from-start` reads (the private fork's Rumble support). When Rumble refuses yt-dlp, the page is opened in a diff --git a/common/controller/recordLive.test.ts b/common/controller/recordLive.test.ts @@ -5175,3 +5175,66 @@ test("REVIEW-8 2: a resume stopped inside an append (a torn tail the repair allo assert.ok(!log.some((l) => /after the resume, .* the file is kept as it is/.test(l))); assert.equal(row.needsAttention, false); }); + +test("REVIEW-8 4: `offline` does not outlive the outage — a resume failed for the network, then the stream ended: the landed row is not 'NOTHING is recording'", { timeout: 60_000 }, async () => { + const id = "exmplr8off1"; + let live = true; + const { run } = await incidentRun( + id, + resumableYtdlp(async ({ n, write }) => { + if (n === 1) { + await write(3000); + return "die"; + } + live = false; + return { exitCode: 1, stderrTail: "ERROR: [youtube] x: Unable to download webpage: The read operation timed out\n", signalled: false }; + }), + { deps: { ...FAST_WATCH, join: null, merge: fakeMerge }, refresh: { stillLive: () => live } }, + ); + await run.catch(() => {}); + const row = (await rowOf(id))[0]!; + assert.equal(row.offline, undefined); + assert.doesNotMatch(row.reason, /NOTHING is recording/); +}); + +test("REVIEW-8 5: a raw source's copy asks the room the landing needs (its size plus 2 GB), not the 20 GB floor", { timeout: 60_000 }, async () => { + const id = "exmplr8rom1"; + const { run } = await incidentRun( + id, + async (args) => { + await writeFile(`${outOf(args)}.${FAKE_A}`, `format=mp4;seconds=7200;v=none;${"x".repeat(5000)}`); + return okExit; + }, + // The floor is 3 GB here and the disk has a little more: the recorder + // starts, and the copy (5 kB + 2 GB) fits. + { meta: { ...YT_META(id), duration: 7200 }, deps: { join: null, merge: fakeMerge, minFreeBytes: 3e9, freeBytes: async () => 3e9 + 100 } }, + ); + await run.catch(() => {}); + const row = (await rowOf(id))[0]!; + assert.doesNotMatch(row.error ?? "", /landed by a copy/); + assert.equal(await storedSeconds(id), 7200); +}); + +test("REVIEW-8 6: 'Verify again' takes the stem's lock — refused while a recorder holds it, nothing removed", { timeout: 60_000 }, async () => { + const id = "exmplr8vlk1"; + let live = true; + const r = await incidentRun( + id, + resumableYtdlp(async ({ write }) => { + await write(7200); + live = false; + return "end"; + }), + { deps: { ...FAST_WATCH, join: null, merge: fakeMerge, verifyMerged: async () => ({ ok: false, why: "a transient read error" }) }, refresh: { stillLive: () => live } }, + ); + await r.run; + const stem = outOf(r.calls[0]!); + await writeFile(`${stem}.rec.lock`, JSON.stringify({ pid: 2 ** 22 + 99, recorderPid: process.pid, at: new Date().toISOString() })); + const before = (await left(id)).length; + const { reverifyLiveLanding } = await import("./recordLive"); + const out = await reverifyLiveLanding({ paths, slug: YT_SLUG, id, channelConfig: YT_CONFIG, deps: { verifyMerged: async () => ({ ok: true }) } }); + assert.equal(out.ok, false); + assert.match((out as { error: string }).error, /recorder holds/); + assert.equal((await left(id)).length, before, "nothing removed"); + await rm(`${stem}.rec.lock`, { force: true }); +}); diff --git a/common/controller/recordLive.ts b/common/controller/recordLive.ts @@ -147,6 +147,7 @@ import { readHandoffFacts, transcriptionHandoffLines, type LandMediaDeps, + LAND_MEDIA_DISK_MARGIN_BYTES, } from "./landMedia"; import { refreshVideoMetadata, type RefreshRunner } from "./refreshVideoMetadata"; import { findVideoSourceUrl } from "./undownloadedVideos"; @@ -3322,6 +3323,11 @@ async function recordLiveRunInner( } else if (bytes > 0) emptyInRow = 0; cur = { o, bytes, mode: "now", partial }; } + // REVIEW-8 4: the outage is over with the recording, whatever ended it. + if (record.offline) { + delete record.offline; + await save(); + } // The main recording is over. The insurance: with the stream read as // ended, it is stopped after a grace (its live edge is at the end too); // otherwise it runs on by itself — it may be the only recorder left. @@ -3896,7 +3902,9 @@ async function recordLiveRunInner( // needed nothing — checked first, said plainly; everything is kept. if (rawSource) { const free = await (deps.freeBytes ?? getFreeBytes)(storeRoot).catch(() => 0); - const need = bestBytes + minFree; + // (REVIEW-8 5: the room the landing itself asks — the size plus its 2 GB + // margin — not the recorders' 20 GB floor.) + const need = bestBytes + LAND_MEDIA_DISK_MARGIN_BYTES; if (free < need) { return notLanded( `${path.basename(best.file)} is landed by a copy (it is kept until the stored file is checked against it), which needs ${formatBytes(need)} free on the store's disk; it has ${formatBytes(free)} — everything is kept, free some space and Record again or land it by hand`, @@ -4210,6 +4218,17 @@ export async function reverifyLiveLanding(o: { new AbortController().signal, ).catch((e: Error) => ({ ok: false as const, why: e.message })); const stems = [...new Set(livePartFiles(o.id, against).map((g) => g.stem))]; + // REVIEW-8 6: never under a recorder that still writes these files. + const locks: StemLock[] = []; + for (const st of stems) { + const lk = await takeStemLock(slugStore, st); + if (!lk.ok) { + for (const l of locks) await l.release(); + return { ok: false, error: `${o.slug}/${o.id}: ${lk.why} — not checked again while it records` }; + } + locks.push(lk); + } + try { const dropped = (await Promise.all(stems.map((st) => readStemMarks(slugStore, st)))).some((m) => m.dropped); if (verdict.ok && dropped) verdict = { ok: false, why: "its fragments were dropped for want of disk: it cannot be proven whole by its track spans alone" }; if (verdict.ok && !dropped) { @@ -4228,6 +4247,7 @@ export async function reverifyLiveLanding(o: { const names = await readdir(slugStore).catch(() => [] as string[]); for (const g of livePartFiles(o.id, names).filter((x) => stems.includes(x.stem))) { for (const f of [...g.finished, ...g.streams, ...g.scratch]) { + if (f.endsWith(".rec.lock")) continue; // (ours: released below) await rm(path.join(slugStore, f), { force: true }); removed.push(f); } @@ -4251,6 +4271,9 @@ export async function reverifyLiveLanding(o: { : `${o.slug}/${o.id}: NOT verified (${(verdict as { why: string }).why}); nothing is removed.`, ); return { ok: true, verified: verdict.ok, ...(verdict.ok ? {} : { why: (verdict as { why: string }).why }), removed }; + } finally { + for (const l of locks) await l.release(); + } } // Every refusal before any job; then the job.