Archilyzer · Source

archilyzer

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

commit 0c22ef9e240cd8693852c5a9a9e8fab143dca143
parent c832eb79eda5ffd8171b2745c82add17ba9815ed
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Sat, 21 Nov 2026 14:39:18 -0500

record-live: a partial attempt is not restarted on top of the schedule; a join waits for the heavy slot and room

Found reading the slices back: when every attempt of the schedule
recorded only one of the two streams, the restarts treated the last one
as a recorder that died with bytes and, the stream still live, started up
to 3 more an hour. A partial attempt is now never restarted there (the
schedule already tried); a test pins it, failing before.

The join's cut and concat are stream copies of hours: they now go through
the heavy slot as the landing's remux does, and a join is made only with
as much room again as its parts plus the recording's 20 GB floor on the
store's disk; otherwise the longest lands and the rest are kept.

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

Diffstat:
Mcommon/controller/liveJoin.ts | 16+++++++++-------
Mcommon/controller/recordLive.test.ts | 12++++++++++++
Mcommon/controller/recordLive.ts | 27++++++++++++++++++++++-----
3 files changed, 43 insertions(+), 12 deletions(-)

diff --git a/common/controller/liveJoin.ts b/common/controller/liveJoin.ts @@ -317,13 +317,19 @@ export async function joinLiveParts(o: { // --- the real tools: ffmpeg/ffprobe ----------------------------------------------- -export function ffmpegJoinDeps(bins: { ffmpegBin: string; ffprobeBin: string }, signal?: AbortSignal): JoinDeps { +// `run`: how ffmpeg's cut and concat are run (record-live: the heavy slot, +// controller/recordLive.ts runFfmpegHeavy); default, ffmpeg directly. +export function ffmpegJoinDeps( + bins: { ffmpegBin: string; ffprobeBin: string; run?: (args: string[]) => Promise<void> }, + signal?: AbortSignal, +): JoinDeps { const opt = signal ? { cancelSignal: signal } : {}; + const ffmpeg = bins.run ?? (async (args: string[]) => void (await execa(bins.ffmpegBin, args, opt))); return { decode: (file, from, seconds, rate) => decodeExcerpt({ ffmpegBin: bins.ffmpegBin, file, from, seconds, sampleRate: rate, ...(signal ? { signal } : {}) }), cut: async (file, from, out) => { - await execa(bins.ffmpegBin, ["-nostdin", "-hide_banner", "-loglevel", "error", "-y", "-ss", from.toFixed(3), "-i", file, "-map", "0", "-c", "copy", "-avoid_negative_ts", "make_zero", out], opt); + await ffmpeg(["-nostdin", "-hide_banner", "-loglevel", "error", "-y", "-ss", from.toFixed(3), "-i", file, "-map", "0", "-c", "copy", "-avoid_negative_ts", "make_zero", out]); // Where the copy starts: its length against the whole's. const whole = await probeJoinStreams(bins.ffprobeBin, file); const part = await probeJoinStreams(bins.ffprobeBin, out); @@ -335,11 +341,7 @@ export function ffmpegJoinDeps(bins: { ffmpegBin: string; ffprobeBin: string }, await writeFile(list, files.map((f) => `file '${f.replace(/'/g, "'\\''")}'`).join("\n") + "\n"); try { const mkv = /\.mkv$/i.test(out); - await execa( - bins.ffmpegBin, - ["-nostdin", "-hide_banner", "-loglevel", "error", "-y", "-f", "concat", "-safe", "0", "-i", list, "-map", "0", "-c", "copy", ...(mkv ? ["-f", "matroska"] : ["-f", "mpegts"]), out], - opt, - ); + await ffmpeg(["-nostdin", "-hide_banner", "-loglevel", "error", "-y", "-f", "concat", "-safe", "0", "-i", list, "-map", "0", "-c", "copy", ...(mkv ? ["-f", "matroska"] : ["-f", "mpegts"]), out]); } finally { await rm(list, { force: true }); } diff --git a/common/controller/recordLive.test.ts b/common/controller/recordLive.test.ts @@ -1867,3 +1867,15 @@ test("slice 5: an unprovable join — the sound does not match, or the joined fi assert.equal(row2.keptParts?.length, 1); assert.deepEqual((await left(id2)).map((n) => /ytdlp-edge-a4\.mp4$/.test(n)), [true]); }); + +test("slice 3: attempts that each recorded only one of the two streams are not restarted after the schedule, even with the stream live", async () => { + const id = "exmplpart02"; + const videoOnly: Attempt = async (args) => { + await writeFile(`${outOf(args)}.f247.webm`, "format=webm;seconds=45;a=none;"); + return { exitCode: 1, stderrTail: "2: ERROR: The downloaded file is empty\n", signalled: false }; + }; + const { run, calls } = await incidentRun(id, videoOnly, { deps: FAST_WATCH, refresh: { stillLive: () => true } }); + await assert.rejects(run, /audio stream recorded nothing/); + assert.equal(calls.length, 6, "the schedule only: no restart on top of it"); + assert.equal((await rowOf(id))[0]!.restarts, undefined); +}); diff --git a/common/controller/recordLive.ts b/common/controller/recordLive.ts @@ -1492,7 +1492,9 @@ async function recordLiveRunInner( // 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. // The main recording's last attempt (what the restarts below look at). - let lastMain: { o: Awaited<ReturnType<typeof ytdlpPart>>; bytes: number; mode: "from-start" | "index0" | "now" } | null = null; + // `partial`: only one of its two streams wrote (never restarted here: + // the schedule above already tried). + let lastMain: { o: Awaited<ReturnType<typeof ytdlpPart>>; bytes: number; mode: "from-start" | "index0" | "now"; partial: boolean } | null = null; let recovery: Promise<void> | null = null; const recoveryStop = new AbortController(); let edgeDone = false; @@ -1589,8 +1591,8 @@ async function recordLiveRunInner( // 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); - lastMain = { o, bytes, mode }; const missing = separate && !o.signalled && bytes > 0 ? await missingStreamOf(last.stem) : null; + lastMain = { o, bytes, mode, partial: missing !== null }; // Stopped by the watchdog with nothing written: an attempt that // recorded nothing (the schedule goes on). With bytes: the restarts // below decide. @@ -1703,7 +1705,7 @@ async function recordLiveRunInner( let cur = lastMain; while (cur && !signal.aborted && !pathB) { const stalledWithBytes = cur.o.stalled && cur.bytes > 0; - const exitedWithBytes = !cur.o.signalled && cur.bytes > 0; + const exitedWithBytes = !cur.o.signalled && cur.bytes > 0 && !cur.partial; const failedRestart = cur.o.part.restart !== undefined && cur.bytes === 0 && !(cur.o.signalled && !cur.o.stalled); if (!stalledWithBytes && !exitedWithBytes && !failedRestart) break; const why = cur.o.stalled ? "stalled" : exitedWithBytes ? "exited while the stream was live" : "recorded nothing"; @@ -1747,6 +1749,7 @@ async function recordLiveRunInner( onLine: onMainLine, }); const bytes = await bytesOf(o.stem); + const partial = separate && !o.signalled && bytes > 0 ? (await missingStreamOf(o.stem)) !== null : false; if (bytes === 0 && !o.signalled) { const c = classifyAttempt({ ...o, bytes }); o.part.error = lastErrorLine(o.stderrTail) ?? `yt-dlp exit ${o.exitCode ?? "null"}`; @@ -1757,7 +1760,7 @@ async function recordLiveRunInner( break; } } - cur = { o, bytes, mode: cur.mode }; + cur = { o, bytes, mode: cur.mode, partial }; } // 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); @@ -2008,13 +2011,27 @@ async function recordLiveRunInner( const p = c.part ?? earlier.get(c.group.stem); return p && c.seconds !== null ? [{ c, jp: { stem: c.group.stem, file: c.file, seconds: c.seconds, fromStart: p.fromStart, startedAt: p.startedAt ?? null } }] : []; }); + // The joined file needs as much room again as its parts (staging is the + // store's disk). + let room = true; if (placed.length >= 2) { + let need = 0; + for (const x of placed) need += await sizeOf(x.c.file); + const free = await (deps.freeBytes ?? getFreeBytes)(storeRoot).catch(() => 0); + if (free < need + RECORD_LIVE_MIN_FREE_BYTES) { + room = false; + say(`Not joined: the store's disk has ${formatBytes(free)} free, a join of these parts needs ${formatBytes(need + RECORD_LIVE_MIN_FREE_BYTES)}. The longest lands; the rest are kept.`); + } + } + if (placed.length >= 2 && room) { const joinStem = stemPath("joined"); const r = await joinLiveParts({ parts: placed.map((x) => x.jp), streamStartedAt: record.streamStartedAt ?? null, outStem: joinStem, - deps: deps.join ?? ffmpegJoinDeps({ ffmpegBin: paths.ffmpegBin, ffprobeBin: paths.ffprobeBin }, landSignal), + // The cut and the concat are stream copies of hours: the heavy slot, + // as the landing's remux. + deps: deps.join ?? ffmpegJoinDeps({ ffmpegBin: paths.ffmpegBin, ffprobeBin: paths.ffprobeBin, run: (args) => runFfmpegHeavy(paths, args, landSignal) }, landSignal), say, }).catch((err: Error) => ({ ok: false as const, why: err.message })); if (r.ok) {