Archilyzer · Source

archilyzer

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

commit 5c7438ec9dff9a32aa042bc3a58ebbe6d0becdc4
parent 21cfb2746af992c5c1350e1ca38af6c221ca9998
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Tue, 24 Nov 2026 12:39:36 -0500

record-live: REVIEW-8 1: a state read failing for a non-network reason resumes the part in place again, with the insurance

A read that fails for anything but the network (a 429, the bot check, an
extractor error) no longer abandons the resumable part for a fresh one from
fragment 0. It is resumed in place as on 50aedbcc2, its files checked after
the resume; a network failure still waits offline first. The behind check
uses the last read that READ (a failed one says nothing) and says when it
skips. A fresh part says why no resume was made only when one was refused,
never "nothing on disk can be reused" untried. Test red on 21cfb2746.

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

Diffstat:
Mcommon/controller/recordLive.test.ts | 36++++++++++++++++++++++++++++++++++++
Mcommon/controller/recordLive.ts | 27+++++++++++++++++++++------
2 files changed, 57 insertions(+), 6 deletions(-)

diff --git a/common/controller/recordLive.test.ts b/common/controller/recordLive.test.ts @@ -5093,3 +5093,39 @@ test("REVIEW-7 8: a raw source that must be copied with too little room — not assert.match(row.error ?? "", /landed by a copy .* needs .* free/); assert.ok((await left(id)).some((n) => n.endsWith(`.${FAKE_A}`)), "kept"); }); + +// --- REVIEW-8 ------------------------------------------------------------------------------ + +test("REVIEW-8 1: one state read failing for a NON-network reason does not abandon the resumable part — resumed in place (with the insurance when it is far behind), never 'nothing on disk can be reused'", { timeout: 60_000 }, async () => { + const id = "exmplr8one1"; + let live = true; + const { run, calls, log } = await incidentRun( + id, + resumableYtdlp(async ({ n, write, print, args, signal }) => { + if (isInsurance(args)) { + await write(60); + await Promise.race([abortOf(signal), new Promise((r) => setTimeout(r, 2000))]); + return { exitCode: null, stderrTail: "", signalled: true }; + } + if (n === 1) { + await write(3000); + return "die"; + } + print(FRAG_LINE(10, 7200)); + await write(7200); + await new Promise((r) => setTimeout(r, 200)); + live = false; + return "end"; + }), + { + request: { doNotClean: false, insurance: undefined }, + deps: { ...FAST_WATCH, stallMs: 60_000, join: null, merge: fakeMerge, insurancePollMs: 5 }, + refresh: { failReads: [2], failWith: "ERROR: [youtube] x: Failed to extract any player response; please report this issue", stillLive: () => live }, + }, + ); + await run.catch(() => {}); + const mains = calls.filter((c) => !isInsurance(c)); + assert.equal(outOf(mains[1]!), outOf(mains[0]!), "the same files resumed, not a fresh part"); + assert.ok(!log.some((l) => /nothing on disk can be reused with proof/.test(l))); + assert.ok(calls.some(isInsurance), "the insurance beside the part found far behind"); +}); diff --git a/common/controller/recordLive.ts b/common/controller/recordLive.ts @@ -1281,7 +1281,7 @@ async function recordLiveRunInner( let endedByRefusal = false; // REVIEW-7: what the LAST state read said (its live_status), or the class // of its failure — `post_live` and a network failure decide what follows. - const lastRead: { status: string | null; failClass: LiveFailureClass | null } = { status: null, failClass: null }; + const lastRead: { status: string | null; failClass: LiveFailureClass | null; goodStatus: string | null } = { status: null, failClass: null, goodStatus: null }; const liveNow = async (confirm = true): Promise<"live" | "ended" | "unknown"> => { try { await refresh(); @@ -1327,6 +1327,7 @@ async function recordLiveRunInner( const ls = (await readMeta(videoDir))?.live_status; lastRead.status = typeof ls === "string" ? ls : null; lastRead.failClass = null; + if (lastRead.status) lastRead.goodStatus = lastRead.status; if (ls === "is_live") return "live"; if (ls === "was_live" || ls === "post_live" || ls === "not_live") { endRead = true; @@ -1435,6 +1436,7 @@ async function recordLiveRunInner( const liveStatus = typeof meta?.live_status === "string" ? meta.live_status : null; // (The run's first read is the first "last read".) lastRead.status = liveStatus; + lastRead.goodStatus = liveStatus; // A restart of a stream that has ended records nothing: what the // interrupted run left in staging lands (the slice-1 landing), or, with // nothing there, the row says so. @@ -2302,11 +2304,15 @@ async function recordLiveRunInner( say(`${mainStem}: how far behind the live edge it is cannot be told (the stream's start time is not known): no live-edge insurance by the behind rule.`); return; } - // REVIEW-7 7: a live-edge recorder only beside a stream that reads LIVE - // (a boot run on a post_live stream behind must not start one). - if (lastRead.status !== "is_live") return; const behind = ((now().getTime() - startMs) / 1000) * (1 - fp.frag / fp.total); if (behind <= LIVE_INSURANCE_BEHIND_SECONDS) return; + // REVIEW-7 7: a live-edge recorder only beside a stream that reads LIVE + // (a boot run on a post_live stream behind must not start one) — by the + // last read that READ (REVIEW-8 1: a failed one says nothing), and said. + if (lastRead.goodStatus !== "is_live") { + say(`${mainStem} is about ${spanWords(behind)} behind, but the stream did not last read live (${lastRead.goodStatus ?? "unknown"}): no live-edge recorder beside it.`); + return; + } if (req.insurance === false) return; if (!(deps.insuranceWhenBehind ?? liveInsuranceWhenBehind())) { say(`${mainStem} is about ${spanWords(behind)} behind the live edge; no live-edge recorder beside it (settings.liveRecording.insuranceWhenBehind is off).`); @@ -2883,6 +2889,8 @@ async function recordLiveRunInner( // DESIGN-4 3: aborts per stem at one fragment; where a fresh part's // predecessor could not get past; whether the last fresh part wrote nothing. const abortTries = new Map<string, { fragment: number; n: number }>(); + // Why the last resume was not made (the fresh part says it, only when known). + let noResumeWhy: string | null = null; const netTries = new Map<string, number>(); let endResumed = false; let freshAbortAt: number | null = null; @@ -3060,7 +3068,13 @@ async function recordLiveRunInner( // no recovery. Only when that is impossible (no state, an unreadable // one, a stream past 120 h, or the resume writes nothing) does the // live-edge fallback below run. - if (cur.mode === "from-start" && !resumeFailed.has(cur.o.stem) && state === "live") { + // (REVIEW-8 1: a read that failed for anything but the network — a 429, + // the bot check, an extractor error — does not abandon the part: it is + // resumed in place as before, its files checked after the resume. A + // network failure never gets here: it waits offline above.) + const resumeRead = state === "live" || (state === "unknown" && lastRead.failClass !== "network"); + if (cur.mode === "from-start" && !resumeFailed.has(cur.o.stem) && !resumeRead) noResumeWhy = `the last state read says ${lastRead.status ?? "nothing"}`; + if (cur.mode === "from-start" && !resumeFailed.has(cur.o.stem) && resumeRead) { let st = await resumeStateOf(cur.o.stem); // DESIGN-5 7: finished by yt-dlp itself (exit 0, merged) while live — // reuse what is downloaded, not fragment 0 again. @@ -3156,6 +3170,7 @@ async function recordLiveRunInner( resumeFailed.add(o.stem); } else { say(`${cur.o.part.stem} cannot be resumed in place (${st.why}).`); + noResumeWhy = st.why; resumeFailed.add(cur.o.stem); } } @@ -3172,7 +3187,7 @@ async function recordLiveRunInner( const sm = record.streamStartedAt ? Date.parse(record.streamStartedAt) : NaN; const age = Number.isFinite(sm) ? (now().getTime() - sm) / 1000 : null; say( - `Restart ${k} (${why}): nothing on disk can be reused with proof — a FRESH part from the stream's start (a new stem: YouTube serves it whole under 119 h)` + + `Restart ${k} (${why}): ${noResumeWhy ? `no resume in place (${noResumeWhy}) — ` : ""}a FRESH part from the stream's start (a new stem: YouTube serves it whole under 119 h)` + (age !== null ? `; the stream is ${spanWords(age)} old: about ${spanWords(age)} of it is fetched again from fragment 0 before the live edge` : "") + `; the earlier part is kept for the landing.`, );