commit a0c8587a5b9b9f88551c8a085645cc2d9062a86f
parent 88b0fadf72f1da3fe340bb553f067006715c3d57
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Sat, 21 Nov 2026 18:00:12 -0500
record-live: a stream that reads live is never left unrecorded quietly; restarts are live-edge recorders
REVIEW-2 of live-guard-2:
- 3.1/3.2: a recorder that exits or stalls while an earlier part holds the
past is followed by a LIVE-EDGE recorder (own stem, the earlier part kept
for the landing and the join), never a from-start pass and never a quiet
landing. The stream is taken as ended only on evidence: the state read
says so, or three live-edge recorders in a row capture nothing (loud when
it still reads live). Every further death restarts again within 6 an
hour and 24 a run; past them, or with the state unreadable after an exit,
the row says the stream may be live and is NOT recorded.
- 3.3: a failure is classified from the recorder's last words (its output
after its last progress line, exitTail), never an old line of the 32 kB
tail; the state is always read before a conclusion, and a rate limit's
15 min wait is made only when it reads live.
- 3.4: the floor before every spawn is max(20 GB, twice the largest part
of this run so far).
- 4.1: the insurance on a rate limit: one more start after 15 min, then
stopped, never the 60 s pause.
- 1.1: a part not from the start (this run's, an earlier run's by its row,
or one no row describes) is removed only when its span is inside the
landed file on the stream's clock against the ended stream's duration;
never on a coverage by the clock.
Replaced tests: REVIEW 2.2 (it asserted the quiet landing) and REVIEW 3.2
(no from-start restart is made any more); the slice-3 stall and bound tests
now expect live-edge restarts and 6 an hour; test data whose live-edge
parts outran the stream on its clock was made physical.
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
3 files changed, 379 insertions(+), 157 deletions(-)
diff --git a/common/controller/recordLive.test.ts b/common/controller/recordLive.test.ts
@@ -1128,12 +1128,16 @@ test("covered (a): a Kick VOD that covers the stream lands, the channel's live-e
extractor: "kick:vod",
live_status: "is_live",
uploader_id: "synthb",
- // Started 5000 s ago: the VOD's 5000 s is the whole stream.
+ // Started 5000 s ago: the VOD's 5000 s is the whole stream, its own
+ // duration once ended.
release_timestamp: Math.floor(Date.now() / 1000) - 5000,
+ duration: 5000,
formats: [{ protocol: "m3u8_native", height: 360, url: "https://stream.kick.com/y/360p30/playlist.m3u8" }],
}),
+ // The channel's live edge: its last 30 s, inside the VOD on the
+ // stream's clock.
spawn: async ({ args }) => {
- await writeFile(args[args.indexOf("-o") + 1]!, "format=mpegts;seconds=1000;");
+ await writeFile(args[args.indexOf("-o") + 1]!, "format=mpegts;seconds=30;");
return { exitCode: 0, stderrTail: "", signalled: false };
},
poll: async (o) => {
@@ -1160,6 +1164,21 @@ test("covered (a): a Kick VOD that covers the stream lands, the channel's live-e
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);
+ // Its run's row says it was recorded from the start (a part no row
+ // describes is kept: REVIEW-2 1.1).
+ 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".replace(/T01-00-00/, "T01:00:00"),
+ status: "failed",
+ 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$/, "") }],
+ });
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");
@@ -1225,7 +1244,7 @@ test("a landing that fails removes nothing: the covered landing's other part and
const RECOVERY_WAIT = 15 * 60_000;
const isRecovery = (args: string[]) => /\.ytdlp-recover-r\d+$/.test(outOf(args));
// The live-edge recorder: records 1800 s, and runs until `ended` resolves.
-const edgeUntil = (ended: Promise<unknown>, seconds = 1800) => async (args: string[]) => {
+const edgeUntil = (ended: Promise<unknown>, seconds = 30) => async (args: string[]) => {
await writeFile(`${outOf(args)}.mp4`, `format=mov,mp4;seconds=${seconds};`);
await ended;
return { exitCode: 0, stderrTail: "", signalled: false };
@@ -1256,8 +1275,9 @@ test("slice 2: the live edge records, a from-start try beside it recovers the st
} finally {
active--;
}
- // The third 15 min wait never comes: the stream ends first.
- }, { recovery: 2 });
+ // The third 15 min wait never comes: the stream ends first. The ended
+ // stream's own duration proves the live edge's 30 s inside the whole.
+ }, { recovery: 2, meta: { ...ytLiveMeta(id), duration: 7200 } });
const s = await run;
assert.equal(s.status, "landed");
assert.equal(recoveries, 2, "two tries: the first failed, the second recorded");
@@ -1385,7 +1405,7 @@ test("slice 3: a stalled recorder is stopped, the stream still live, a new part
const s = await run;
assert.equal(s.status, "landed");
assert.equal(calls.length, 2, "the stalled recorder, then one restart");
- assert.ok(fromStartArg(calls[1]!), "restarted from its start, as the stalled part was");
+ assert.ok(!fromStartArg(calls[1]!), "restarted at the live edge: the stalled part holds the past (REVIEW-2)");
assert.match(outOf(calls[1]!), /\.ytdlp-r1$/, "the restart's own stem");
assert.ok(waits.includes(30_000), "a pause before the restart");
assert.ok(log.some((l) => /stalled/.test(l)));
@@ -1393,7 +1413,8 @@ test("slice 3: a stalled recorder is stopped, the stream still live, a new part
assert.equal(row.parts[0]!.stalled, true);
assert.equal(row.restarts?.count, 1);
assert.equal(s.landed?.seconds, 7200);
- assert.equal(row.needsAttention, false);
+ assert.ok(row.keptParts?.some((k) => /\.ytdlp$/.test(k.stem)), "the stalled from-start part is kept: the join or a person decides");
+ assert.equal(row.needsAttention, true);
});
test("slice 3: a recorder that exits with bytes while the stream still reads live (twice, 60 s apart) is restarted; a normal end is not", async () => {
@@ -1422,7 +1443,7 @@ test("slice 3: a recorder that exits with bytes while the stream still reads liv
assert.deepEqual(plain.waits, []);
});
-test("slice 3: restarts are bounded (3 an hour); past it the run lands what it has and the row needs a person", async () => {
+test("slice 3: restarts are bounded (6 an hour); past it the run lands what it has and the row needs a person", { timeout: 60_000 }, async () => {
const id = "exmplbound1";
// Each recorder writes and then stalls.
const { run, calls } = await incidentRun(
@@ -1432,10 +1453,10 @@ test("slice 3: restarts are bounded (3 an hour); past it the run lands what it h
);
const s = await run;
assert.equal(s.status, "landed");
- assert.equal(calls.length, 4, "the first recorder and 3 restarts, no more");
+ assert.equal(calls.length, 7, "the first recorder and 6 restarts, no more");
const row = (await rowOf(id))[0]!;
- assert.equal(row.restarts?.count, 3);
- assert.match(row.restarts?.refused ?? "", /3 restarts in the last hour/);
+ assert.equal(row.restarts?.count, 6);
+ assert.match(row.restarts?.refused ?? "", /6 restarts in the last hour.*NOT recorded/);
assert.equal(row.needsAttention, true);
assert.ok((row.keptParts?.length ?? 0) + (row.removedParts?.length ?? 0) >= 3, "every part is accounted for");
});
@@ -1585,6 +1606,7 @@ test("slice 3 resume: ended with nothing left says so and still needs a person;
const isInsurance = (args: string[]) => /\.ytdlp-insure(?:-r\d+)?$/.test(outOf(args));
const FAST_INSURE = { insurancePollMs: 5, insuranceMarginMs: 10, insuranceGraceMs: 10 };
function insuranceFake(o: { mainSeconds?: number; edgeSeconds?: number; caughtUp?: boolean } = {}) {
+ // (The insurance's part is 30 s by default: the live edge at the stream's end.)
let started!: () => void;
const insStarted = new Promise<void>((r) => (started = r));
let stoppedBy: "signal" | null = null;
@@ -1594,7 +1616,7 @@ function insuranceFake(o: { mainSeconds?: number; edgeSeconds?: number; caughtUp
const attempt: Attempt = async (args, _n, signal, onLine) => {
if (isInsurance(args)) {
assert.equal(fromStartArg(args), false, "the insurance records the live edge");
- await writeFile(`${outOf(args)}.mp4`, `format=mov,mp4;seconds=${o.edgeSeconds ?? 600};`);
+ await writeFile(`${outOf(args)}.mp4`, `format=mov,mp4;seconds=${o.edgeSeconds ?? 30};`);
started();
await Promise.race([
new Promise<void>((r) => signal.addEventListener("abort", () => r(), { once: true })),
@@ -1629,7 +1651,11 @@ function insuranceFake(o: { mainSeconds?: number; edgeSeconds?: number; caughtUp
test("slice 4: a stream marked keep gets the insurance by default; it stops once every stream has caught up, and covered by the whole it goes at landing", { timeout: 60_000 }, async () => {
const id = "exmplinsur1";
const f = insuranceFake();
- const { run, calls, waits } = await incidentRun(id, f.attempt, { request: { insurance: undefined }, deps: FAST_INSURE });
+ const { run, calls, waits } = await incidentRun(id, f.attempt, {
+ request: { insurance: undefined },
+ deps: FAST_INSURE,
+ meta: { ...ytLiveMeta(id), duration: 7200 },
+ });
const s = await run;
assert.equal(s.status, "landed");
assert.equal(calls.length, 2, "the from-start recorder and the insurance");
@@ -1655,7 +1681,7 @@ test("slice 4: the default is by keep mark (asked, or on the record before); the
const { setDoNotClean } = await import("../lib/doNotClean-server");
const dir = path.join(CORPUS, "channels", YT_SLUG, "data", "exmplinsur4");
await mkdir(dir, { recursive: true });
- await setDoNotClean(dir, true, "keep this one");
+ await setDoNotClean(dir, true, { by: "live-recording", via: "record-live", note: "keep this one" });
const pre = insuranceFake({ caughtUp: false });
const b = await incidentRun("exmplinsur4", pre.attempt, { request: { insurance: undefined, doNotClean: false, note: undefined }, deps: FAST_INSURE });
await b.run;
@@ -2166,24 +2192,6 @@ test("REVIEW 2.1(b): a part that died WITH bytes on a 429 is classified and reco
assert.match(row.parts[0]!.error ?? "", /429/);
});
-test("REVIEW 2.2: an ended stream that still reads live — no from-start pass once a part covers the stream, and at most ONE extra otherwise", { timeout: 60_000 }, async () => {
- // (a) The first pass holds the stream to now (by the clock): no restart.
- const a = await incidentRun("exmplrv2201", async (args) => {
- await writeFile(`${outOf(args)}.mp4`, "format=mov,mp4;seconds=7200;");
- return okExit;
- }, { deps: FAST_WATCH, refresh: { stillLive: () => true } });
- await a.run;
- assert.equal(a.calls.length, 1, "it already covers the stream: no second whole-stream download");
- // (b) Short of it, and the stream reads live for ever: one extra pass, then stop.
- const b = await incidentRun("exmplrv2202", async (args) => {
- await writeFile(`${outOf(args)}.mp4`, "format=mov,mp4;seconds=3000;");
- return okExit;
- }, { deps: FAST_WATCH, refresh: { stillLive: () => true } });
- await b.run;
- assert.equal(b.calls.length, 2, "the first pass and ONE extra from-start pass");
- assert.match((await rowOf("exmplrv2202"))[0]!.restarts?.refused ?? "", /from-start pass/);
-});
-
test("REVIEW 2.3: the free-space floor is read before a start-recovery try and the insurance start; a spawn that would breach it does not start, and the row says so", { timeout: 60_000 }, async () => {
// A recovery try with no room: the disk is full after the run's start.
let reads = 0;
@@ -2260,49 +2268,6 @@ test("REVIEW 3.1: an insurance recorder that dies early reads 'died', never 'to
assert.ok(!log.some((l) => /recorded the live edge to the end/.test(l)));
});
-test("REVIEW 3.2: a from-start restart re-arms an insurance that had stopped after the catch-up", { timeout: 60_000 }, async () => {
- const id = "exmplrv3201";
- let live = true;
- let starts = 0;
- let stoppedCount = 0;
- const { run, calls } = await incidentRun(
- id,
- async (args, n, signal, onLine) => {
- if (isInsurance(args)) {
- starts++;
- await writeFile(`${outOf(args)}.mp4`, "format=mov,mp4;seconds=60;");
- await abortOf(signal);
- stoppedCount++;
- return { exitCode: null, stderrTail: "", signalled: true };
- }
- if (n === 1) {
- await writeFile(`${outOf(args)}.mp4`, "format=mov,mp4;seconds=3000;");
- onLine?.("1: [download] 10.0% (frag 100/3000)");
- await until(() => starts >= 1);
- onLine?.("1: [download] 99.9% (frag 2990/3000)");
- await until(() => stoppedCount >= 1);
- // Then it stalls, and the watchdog stops it.
- await abortOf(signal);
- return { exitCode: null, stderrTail: "", signalled: true };
- }
- // The restart from the start: behind again.
- await writeFile(`${outOf(args)}.mp4`, "format=mov,mp4;seconds=7200;");
- onLine?.("1: [download] 10.0% (frag 100/3600)");
- await until(() => starts >= 2);
- live = false;
- onLine?.("1: [download] 99.9% (frag 3590/3600)");
- await until(() => stoppedCount >= 2);
- return okExit;
- },
- { request: { insurance: undefined }, deps: { ...FAST_INSURE, watchMs: 10, stallMs: 1500 }, refresh: { stillLive: () => live } },
- );
- await run;
- assert.equal(calls.filter(isInsurance).length, 2, "a second insurance beside the restarted from-start recording");
- const row = (await rowOf(id))[0]!;
- assert.equal(row.restarts?.count, 1);
- assert.equal(row.insurance?.starts, 2);
-});
-
test("REVIEW 3.3: an unreadable state at boot is read three times over about ten minutes; read live, it records; never readable, the row says the stream may be live and unrecorded", { timeout: 60_000 }, async () => {
const t0 = "2026-11-21T08:00:00.000Z";
// Read on the third try: it records.
@@ -2331,3 +2296,200 @@ test("REVIEW 3.3: an unreadable state at boot is read three times over about ten
await assert.rejects(rc.run);
assert.deepEqual(rc.waits, []);
});
+
+// --- REVIEW-2 of live-guard-2: a stream that reads live is never left unrecorded quietly --
+//
+// A recorder that exits or stalls while an earlier part holds the past is
+// restarted at the LIVE EDGE (its own stem; the earlier part kept); the
+// stream is taken as ended only on evidence: the state read says so, or three
+// live-edge recorders in a row capture nothing.
+
+const isEdge = (args: string[]) => !fromStartArg(args);
+
+test("REVIEW2 3.1: a caught-up from-start recorder that exits while the stream reads live is restarted at the live edge, never landed quietly", { timeout: 60_000 }, async () => {
+ const id = "exmplr2a301";
+ let live = true;
+ const { run, calls } = await incidentRun(
+ id,
+ async (args, n) => {
+ if (n === 1) {
+ await writeFile(`${outOf(args)}.mp4`, "format=mov,mp4;seconds=7200;");
+ return { exitCode: 1, stderrTail: "ERROR: [download] Got error: Connection reset by peer\n", signalled: false };
+ }
+ await writeFile(`${outOf(args)}.mp4`, "format=mov,mp4;seconds=900;");
+ live = false;
+ return okExit;
+ },
+ { deps: { ...FAST_WATCH, join: null }, refresh: { stillLive: () => live } },
+ );
+ await run;
+ assert.equal(calls.length, 2, "restarted");
+ assert.ok(isEdge(calls[1]!), "at the live edge: the past is held by the first part");
+ assert.ok((await left(id)).some((n) => /\.ytdlp-r1\.mp4$/.test(n)) || (await rowOf(id))[0]!.parts.some((p) => p.restart === 1));
+});
+
+test("REVIEW2 3.2: a second and a third death while the stream reads live restart again, at the live edge; when the bounds are spent the row says the stream is live and unrecorded", { timeout: 60_000 }, async () => {
+ const id = "exmplr2a302";
+ let live = true;
+ const deaths = { exitCode: 1, stderrTail: "ERROR: [download] Got error: Connection reset by peer\n", signalled: false };
+ const a = await incidentRun(
+ id,
+ async (args, n) => {
+ await writeFile(`${outOf(args)}.mp4`, `format=mov,mp4;seconds=${n === 1 ? 3000 : 400};`);
+ if (n === 3) live = false;
+ return n === 3 ? okExit : deaths;
+ },
+ { deps: { ...FAST_WATCH, join: null }, refresh: { stillLive: () => live } },
+ );
+ await a.run;
+ assert.equal(a.calls.length, 3, "two deaths, two restarts");
+ assert.ok(a.calls.slice(1).every(isEdge), "every restart at the live edge");
+ // Dying for ever while live: the bound, then loud.
+ const id2 = "exmplr2a303";
+ const b = await incidentRun(
+ id2,
+ async (args) => {
+ await writeFile(`${outOf(args)}.mp4`, "format=mov,mp4;seconds=300;");
+ return deaths;
+ },
+ { deps: { ...FAST_WATCH, join: null }, refresh: { stillLive: () => true } },
+ );
+ await b.run;
+ assert.equal(b.calls.length, 1 + 6, "the first recorder and 6 restarts (the hour's bound)");
+ const row = (await rowOf(id2))[0]!;
+ assert.match(row.restarts?.refused ?? "", /reads live and is NOT recorded/);
+ assert.equal(row.needsAttention, true);
+});
+
+test("REVIEW2 3.1: three live-edge recorders in a row that capture nothing are the evidence the stream ended; still reading live, the row is loud", { timeout: 60_000 }, async () => {
+ const id = "exmplr2a304";
+ const { run, calls } = await incidentRun(
+ id,
+ async (args, n) => {
+ if (n === 1) {
+ await writeFile(`${outOf(args)}.mp4`, "format=mov,mp4;seconds=3000;");
+ return { exitCode: 1, stderrTail: "ERROR: [download] Got error: Connection reset by peer\n", signalled: false };
+ }
+ return { exitCode: 1, stderrTail: "ERROR: [download] Got error: Connection reset by peer\n", signalled: false };
+ },
+ { deps: { ...FAST_WATCH, join: null }, refresh: { stillLive: () => true } },
+ );
+ assert.equal((await run).status, "landed");
+ assert.equal(calls.length, 4, "the first, then three empty live-edge recorders");
+ const row = (await rowOf(id))[0]!;
+ assert.match(row.restarts?.refused ?? "", /three live-edge recorders in a row captured nothing/);
+ assert.equal(row.needsAttention, true);
+});
+
+test("REVIEW2 3.3: the class is read from the recorder's last output — a 429 retried an hour ago does not delay a normal end; ended/private text is checked by a state read", { timeout: 60_000 }, async () => {
+ // (a) A stale 429, then fragments, then the normal end.
+ const a = await incidentRun(
+ "exmplr2a305",
+ async (args) => {
+ await writeFile(`${outOf(args)}.mp4`, "format=mov,mp4;seconds=600;");
+ return {
+ exitCode: 1,
+ stderrTail: "ERROR: [download] Got error: HTTP Error 429: Too Many Requests\n[download] 40.0% (frag 400/1000)\n[download] 100.0% (frag 1000/1000)\nERROR: fragment 1001 not found\n",
+ signalled: false,
+ };
+ },
+ { deps: { ...FAST_WATCH, join: null } },
+ );
+ assert.equal((await a.run).status, "landed");
+ assert.ok(!a.waits.includes(15 * 60_000), "no 15 min wait for an old 429");
+ // (b) "Private video" with bytes, but the stream reads live: restarted.
+ let live = true;
+ const b = await incidentRun(
+ "exmplr2a306",
+ async (args, n) => {
+ if (n === 1) {
+ await writeFile(`${outOf(args)}.mp4`, "format=mov,mp4;seconds=3000;");
+ return { exitCode: 1, stderrTail: "ERROR: [youtube] x: Private video. Sign in if you've been granted access\n", signalled: false };
+ }
+ await writeFile(`${outOf(args)}.mp4`, "format=mov,mp4;seconds=300;");
+ live = false;
+ return okExit;
+ },
+ { deps: { ...FAST_WATCH, join: null }, refresh: { stillLive: () => live } },
+ );
+ await b.run;
+ assert.equal(b.calls.length, 2, "the state was read, it is live: restarted");
+});
+
+test("REVIEW2 3.4: the floor before a spawn is max(the floor, twice the largest part so far)", { timeout: 60_000 }, async () => {
+ const id = "exmplr2a307";
+ const { run, calls } = await incidentRun(
+ id,
+ async (args) => {
+ await writeFile(`${outOf(args)}.mp4`, `format=mov,mp4;seconds=3000;${"x".repeat(2000)}`);
+ return { exitCode: 1, stderrTail: "ERROR: Connection reset by peer\n", signalled: false };
+ },
+ // A floor of 1 kB; 3 kB free; the part is ~2 kB: twice it is not there.
+ { deps: { ...FAST_WATCH, join: null, minFreeBytes: 1000, freeBytes: async () => 3000 }, refresh: { stillLive: () => true } },
+ );
+ await run;
+ assert.equal(calls.length, 1, "no restart: twice the largest part is not free");
+ const row = (await rowOf(id))[0]!;
+ assert.ok(row.spaceHeld?.length);
+ assert.equal(row.needsAttention, true);
+});
+
+test("REVIEW2 4.1: the insurance on a rate limit: ONE retry after 15 min, then stop", { timeout: 60_000 }, async () => {
+ const id = "exmplr2a308";
+ let insurers = 0;
+ const { run, waits } = await incidentRun(
+ id,
+ async (args) => {
+ if (isInsurance(args)) {
+ insurers++;
+ return { exitCode: 1, stderrTail: "ERROR: [youtube] x: HTTP Error 429: Too Many Requests\n", signalled: false };
+ }
+ await writeFile(`${outOf(args)}.mp4`, "format=mov,mp4;seconds=7200;");
+ await until(() => insurers >= 3, 1500);
+ return okExit;
+ },
+ { request: { insurance: undefined }, deps: { ...FAST_INSURE, join: null } },
+ );
+ await run;
+ assert.equal(insurers, 2, "the first and one retry");
+ assert.ok(waits.includes(15 * 60_000));
+ const row = (await rowOf(id))[0]!;
+ assert.match(row.insurance?.reason ?? "", /rate/);
+});
+
+test("REVIEW2 1.1: a part holding the stream's end is kept by its place on the stream's clock, not by wall-clock ends; never removed on a clock-basis coverage", { timeout: 60_000 }, async () => {
+ // The main from-start part (7140 s) and the insurance end together; the
+ // stream's own duration is 7200 s: 7140 + 72 covers by the tolerance, but
+ // the insurance (from stream second 6000, 1210 s) reaches 7210.
+ const id = "exmplr2a309";
+ const start = Math.floor(Date.now() / 1000) - 7200;
+ let insStarted = false;
+ const { run } = await incidentRun(
+ id,
+ async (args, _n, signal) => {
+ if (isInsurance(args)) {
+ insStarted = true;
+ await writeFile(`${outOf(args)}.mp4`, "format=mov,mp4;seconds=1210;");
+ await abortOf(signal);
+ return { exitCode: null, stderrTail: "", signalled: true };
+ }
+ await writeFile(`${outOf(args)}.mp4`, "format=mov,mp4;seconds=7140;");
+ await until(() => insStarted);
+ return okExit;
+ },
+ {
+ request: { insurance: true },
+ meta: { ...YT_META(id), release_timestamp: start },
+ deps: { ...FAST_INSURE, join: null },
+ refresh: {},
+ },
+ );
+ // The ended stream says 7200 s; its insurance part started 6000 s in.
+ const rows = await rowOf(id);
+ void rows;
+ await run;
+ const row = (await rowOf(id))[0]!;
+ const ins = row.parts.find((p) => p.insurance)!;
+ assert.ok(ins, "the insurance ran");
+ assert.ok(row.keptParts?.some((k) => /ytdlp-insure$/.test(k.stem)), "kept: it may hold the end");
+});
diff --git a/common/controller/recordLive.ts b/common/controller/recordLive.ts
@@ -181,6 +181,9 @@ export const RECORDER_GRACE_MS = 60_000;
// The store's disk must have this much free before a recording starts (four
// hours of 720p is ~6 GB, of 1080p ~9 GB).
export const RECORD_LIVE_MIN_FREE_BYTES = 20 * 1024 ** 3;
+// Live-edge recorders in a row that capture nothing: the evidence a stream
+// that still reads live has ended (REVIEW-2 3.1 of live-guard-2).
+export const LIVE_EDGE_EMPTY_TO_END = 3;
// A restart after the editor's: the stream's state read again after these
// waits when it could not be read (three reads over about ten minutes).
export const LIVE_BOOT_STATE_READ_WAITS_MS: readonly number[] = [120_000, 480_000];
@@ -336,7 +339,20 @@ export function recordLiveQueueKey(slug: string, id: string | null, kickChannel?
// --- the recorder process ----------------------------------------------------------
-export type RecorderOutcome = { exitCode: number | null; stderrTail: string; signalled: boolean };
+// `exitTail`: what the recorder printed (both streams) after its last
+// progress line — its last words near the exit, what a failure is classified
+// from (REVIEW-2 3.3 of live-guard-2); never a line from hours earlier.
+export type RecorderOutcome = { exitCode: number | null; stderrTail: string; signalled: boolean; exitTail?: string };
+
+// The recorder's last words: its own exitTail, else (a stub's stderr) the
+// lines after the last progress line, at most the last 20.
+export function recentOutput(o: Pick<RecorderOutcome, "stderrTail" | "exitTail">): string {
+ if (o.exitTail !== undefined) return o.exitTail;
+ const lines = o.stderrTail.split(/[\r\n]+/).map((l) => l.trim()).filter(Boolean);
+ let i = lines.length;
+ while (i > 0 && !isProgressLine(lines[i - 1]!)) i--;
+ return lines.slice(Math.max(i, lines.length - 20)).join("\n");
+}
export type RecorderSpawn = (opts: {
bin: string;
@@ -369,6 +385,7 @@ export const spawnRecorder: RecorderSpawn = ({ bin, args, cwd, onLog, signal, la
onLog(`[${label}] $ ${bin} ${args.map((a) => (/\s/.test(a) ? JSON.stringify(a) : a)).join(" ")}\n`);
const child = spawn(bin, args, { cwd, stdio: ["ignore", "pipe", "pipe"] });
let tail = "";
+ let sinceProgress = "";
let lastProgress = 0;
let signalled = false;
let killTimer: NodeJS.Timeout | null = null;
@@ -379,6 +396,8 @@ export const spawnRecorder: RecorderSpawn = ({ bin, args, cwd, onLog, signal, la
const l = line.trim();
if (!l) continue;
onLine?.(l);
+ if (isProgressLine(l)) sinceProgress = "";
+ else sinceProgress = (sinceProgress + l + "\n").slice(-8 * 1024);
if (isProgressLine(l)) {
const now = Date.now();
if (now - lastProgress < PROGRESS_EVERY_MS) continue;
@@ -404,7 +423,7 @@ export const spawnRecorder: RecorderSpawn = ({ bin, args, cwd, onLog, signal, la
child.on("close", (code) => {
if (killTimer) clearTimeout(killTimer);
signal.removeEventListener("abort", onAbort);
- resolve({ exitCode: code, stderrTail: tail, signalled });
+ resolve({ exitCode: code, stderrTail: tail, signalled, exitTail: sinceProgress });
});
});
@@ -630,6 +649,8 @@ export type RecordLiveDeps = {
// Joining parts at the landing (controller/liveJoin.ts; default ffmpeg's);
// null never joins.
join?: JoinDeps | null;
+ // The free-space floor (default RECORD_LIVE_MIN_FREE_BYTES).
+ minFreeBytes?: number;
};
export type RecordLiveJobOpts = {
@@ -929,6 +950,8 @@ async function recordLiveRunInner(
const runRecorder = deps.spawn ?? spawnRecorder;
const getText = deps.fetchText ?? fetchText;
const watchMs = deps.watchMs ?? LIVE_WATCH_MS;
+ // The free-space floor (tests set a small one).
+ const minFree = deps.minFreeBytes ?? RECORD_LIVE_MIN_FREE_BYTES;
const stallMs = deps.stallMs ?? liveStallMinutes() * 60_000;
const fromStart = req.fromStart !== false;
const maxHeight = req.maxHeight === undefined ? LIVE_DEFAULT_MAX_HEIGHT : req.maxHeight;
@@ -1141,9 +1164,9 @@ async function recordLiveRunInner(
await ensureStoreRoot(paths, storeRoot, "nothing recorded");
await assertSavedVideosStoreWritable(paths, storeDir);
const free = await (deps.freeBytes ?? getFreeBytes)(storeRoot);
- if (free < RECORD_LIVE_MIN_FREE_BYTES) {
+ if (free < minFree) {
throw new Error(
- `the store's disk has ${formatBytes(free)} free; a live recording needs ${formatBytes(RECORD_LIVE_MIN_FREE_BYTES)} — nothing recorded`,
+ `the store's disk has ${formatBytes(free)} free; a live recording needs ${formatBytes(minFree)} — nothing recorded`,
);
}
} catch (err) {
@@ -1372,11 +1395,17 @@ async function recordLiveRunInner(
// a try, a restart or the insurance starts only with
// RECORD_LIVE_MIN_FREE_BYTES free on the store's disk; one that would breach
// it does not start, and the row says so (spaceHeld, needing a person).
+ // The floor scales with the stream (REVIEW-2 3.4): max(the floor, twice the
+ // largest part of this run so far) — a new part may grow as large, and a
+ // landing's merge needs as much again.
const roomFor = async (what: string): Promise<boolean> => {
+ let largest = 0;
+ for (const p of parts) largest = Math.max(largest, await allBytesOf(p.stem));
+ const need = Math.max(minFree, 2 * largest);
const free = await (deps.freeBytes ?? getFreeBytes)(storeRoot).catch(() => 0);
- if (free >= RECORD_LIVE_MIN_FREE_BYTES) return true;
+ if (free >= need) return true;
(record.spaceHeld ??= []).push({ what, at: now().toISOString(), freeBytes: free });
- say(`${what}: NOT started — the store's disk has ${formatBytes(free)} free, at least ${formatBytes(RECORD_LIVE_MIN_FREE_BYTES)} are needed.`);
+ say(`${what}: NOT started — the store's disk has ${formatBytes(free)} free, at least ${formatBytes(need)} are needed.`);
await save();
return false;
};
@@ -1530,6 +1559,8 @@ async function recordLiveRunInner(
// restart put the main behind again.
const insureLoop = async (): Promise<void> => {
const ins: LiveInsurance = { mode: decided!.mode, by: decided!.by, state: "waiting", starts: 0 };
+ let insLimited = false;
+ let rateWait: number | null = null;
record.insurance = ins;
await save();
const notStarted = async (reason: string) => {
@@ -1553,7 +1584,10 @@ async function recordLiveRunInner(
if (!(await waitRearm())) return;
continue;
}
- await waitFor(stretch(LIVE_INSURANCE_DELAY_MS), waitStop);
+ // After a rate limit: ONE more start after LIVE_RATE_LIMIT_WAIT_MS
+ // (REVIEW-2 4.1), never the 60 s pause.
+ await waitFor(stretch(rateWait ?? LIVE_INSURANCE_DELAY_MS), waitStop);
+ rateWait = null;
if (signal.aborted || mainDoneCtl.signal.aborted) return notStarted("the from-start recording ended before it began");
if (stopNow.signal.aborted) continue;
if ((ins.starts ?? 0) >= LIVE_INSURANCE_MAX_STARTS) {
@@ -1573,8 +1607,9 @@ async function recordLiveRunInner(
const tag = ins.starts === 1 ? "ytdlp-insure" : `ytdlp-insure-r${ins.starts}`;
const o = await ytdlpPart(plan.url, tag, "now", "insurance; ", { insurance: true, noWait: true, stop: stopNow.signal });
const bytes = await bytesOf(o.stem);
- const errLine = lastErrorLine(o.stderrTail);
- const cls = !o.signalled && o.exitCode !== 0 ? liveFailureClass(o.stderrTail) : null;
+ const last = recentOutput(o);
+ const errLine = lastErrorLine(last);
+ const cls = !o.signalled && o.exitCode !== 0 ? liveFailureClass(last) : null;
if (signal.aborted) ins.state = "stopped";
else if (insuranceStopFor === "fallback") {
ins.state = "stopped";
@@ -1585,6 +1620,16 @@ async function recordLiveRunInner(
else if (cls === "ended" || cls === "private" || cls === "members" || cls === "disk") {
ins.state = bytes > 0 ? "ended" : "failed";
ins.reason = errLine ?? `yt-dlp exit ${o.exitCode ?? "null"}`;
+ } else if (cls === "rate-limited") {
+ if (insLimited) {
+ ins.state = "stopped";
+ ins.reason = `rate-limited again after the ${spanWords(LIVE_RATE_LIMIT_WAIT_MS / 1000)} wait (${errLine ?? "429"}): not started again`;
+ } else {
+ insLimited = true;
+ rateWait = LIVE_RATE_LIMIT_WAIT_MS;
+ ins.state = "died";
+ ins.reason = `rate-limited (${errLine ?? "429"}): ONE more start after ${spanWords(LIVE_RATE_LIMIT_WAIT_MS / 1000)}`;
+ }
} else {
ins.state = "died";
ins.reason = o.stalled
@@ -1835,31 +1880,33 @@ async function recordLiveRunInner(
// when a stream is over), an exit lands. Bounded: 3 in any hour, 12 in
// the run, and the store's disk must have room.
let cur = lastMain;
- // A rate limit gets ONE more restart after LIVE_RATE_LIMIT_WAIT_MS, as
- // slice 1's attempts do; a second is not restarted (REVIEW-1 2.1).
+ // SLICE 3 as REVIEW-2 of live-guard-2 ruled: A STREAM THAT READS LIVE IS
+ // NEVER LEFT UNRECORDED QUIETLY, and a restart never re-downloads what
+ // a kept part already holds. A recorder that exited or stalled is
+ // followed by a LIVE-EDGE recorder (its own stem; the earlier part kept
+ // for the landing and the join): an earlier part holds the past. (When
+ // no part holds the stream's START, the slice-2 tries beside the live
+ // edge are the from-start path, with their own bound.) The stream is
+ // taken as ended only on evidence: the state read says so, or three
+ // live-edge recorders in a row capture nothing. Bounds: 6 restarts in
+ // any hour and 24 in the run; past them, or when the state cannot be
+ // read after an exit, the row says the stream may be live and NOT
+ // recorded, and needs a person.
let restartLimited = false;
- // After a recorder ENDED with bytes and the stream still reading live,
- // at most one more from-start pass (REVIEW-1 2.2): a stream that has
- // ended may read live for a while, and each pass is the whole stream.
- let extraPasses = 0;
- const secondsOf = async (stem: string): Promise<number> => {
- const g = await filesOf(stem);
- let best = 0;
- for (const f of g ? [...g.finished, ...g.streams] : []) best = Math.max(best, (await probe(path.join(slugStore, f)).catch(() => null))?.seconds ?? 0);
- return best;
- };
+ let emptyInRow = 0;
while (cur && !signal.aborted && !pathB) {
const stalledWithBytes = cur.o.stalled && 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";
- // What the recorder said, classified — also for a part WITH bytes.
- const cls: LiveFailureClass | null =
- !cur.o.signalled && cur.o.exitCode !== 0 ? liveFailureClass(cur.o.stderrTail) : null;
+ // What the recorder said LAST (its output after its last progress
+ // line), classified — also for a part with bytes (REVIEW-2 3.3).
+ const said = recentOutput(cur.o);
+ const cls: LiveFailureClass | null = !cur.o.signalled && cur.o.exitCode !== 0 ? liveFailureClass(said) : null;
if (cls && cls !== "unknown") {
cur.o.part.failureClass = cls;
- cur.o.part.error ??= lastErrorLine(cur.o.stderrTail) ?? `yt-dlp exit ${cur.o.exitCode ?? "null"}`;
+ cur.o.part.error ??= lastErrorLine(said) ?? `yt-dlp exit ${cur.o.exitCode ?? "null"}`;
await save();
}
const restarts = (record.restarts ??= { count: 0, at: [] });
@@ -1868,25 +1915,24 @@ async function recordLiveRunInner(
await save();
say(words);
};
- if (cls === "disk" || cls === "ended" || cls === "private" || cls === "members") {
- if (cls === "disk") await refuse("the store's disk cannot take it", "NOT restarted: the store's disk cannot take it; what was recorded lands.");
- else say(`Not restarted: the recorder said the stream is ${cls === "ended" ? "over" : cls === "private" ? "private or removed" : "members-only"}.`);
+ if (cls === "disk") {
+ await refuse("the store's disk cannot take it", "NOT restarted: the store's disk cannot take it; what was recorded lands, and the row needs a person.");
break;
}
- let pause = LIVE_RESTART_WAIT_MS;
- if (cls === "rate-limited") {
- if (restartLimited) {
- await refuse("rate-limited again after the 15 min wait", "NOT restarted: rate-limited again after the 15 min wait; what was recorded lands, and the row needs a person.");
- break;
+ if (emptyInRow >= LIVE_EDGE_EMPTY_TO_END) {
+ const st = await liveNow();
+ if (st !== "ended") {
+ await refuse(
+ "three live-edge recorders in a row captured nothing",
+ "Three live-edge recorders in a row captured nothing: the stream is taken as ended, though it still reads live — it may be live and NOT recorded; the row needs a person.",
+ );
}
- restartLimited = true;
- say(`${cur.o.part.stem}: refused by a rate limit or the bot check — ONE restart after ${spanWords(LIVE_RATE_LIMIT_WAIT_MS / 1000)}, then no more.`);
- await waitFor(stretch(LIVE_RATE_LIMIT_WAIT_MS), signal);
- if (signal.aborted) break;
- pause = 0;
+ break;
}
+ // The state is ALWAYS read before a conclusion (never stderr text
+ // alone): the platform's word decides.
let state = await liveNow();
- if (state === "live" && exitedWithBytes) {
+ if (state === "live" && exitedWithBytes && cls !== "rate-limited") {
say(`${cur.o.part.stem}: its recorder exited while the stream reads live; read again in ${spanWords(LIVE_RESTART_CONFIRM_MS / 1000)} before restarting.`);
await waitFor(stretch(LIVE_RESTART_CONFIRM_MS), signal);
if (signal.aborted) break;
@@ -1896,71 +1942,66 @@ async function recordLiveRunInner(
if (cur.o.stalled) say(`The stream has ended: what was recorded lands (no restart).`);
break;
}
- // Only a stall restarts on a state that could not be read.
if (state === "unknown" && !cur.o.stalled) {
- say("The stream's state could not be read: what was recorded lands (no restart).");
+ await refuse(
+ "the stream's state could not be read after its recorder ended",
+ "The stream's state could not be read after its recorder ended: what was recorded lands — the stream may be live and NOT recorded; the row needs a person.",
+ );
break;
}
- if (cur.mode !== "now") {
- // A from-start part that holds the stream up to now (the coverage
- // rule, by the clock): no further from-start pass, whatever is_live
- // says.
- let longest = 0;
- for (const p of parts) if (p.part.fromStart && !p.part.recovery && !p.part.insurance) longest = Math.max(longest, await secondsOf(p.stem));
- const c = streamCoverage({
- capturedSeconds: longest,
- endMeta: null,
- streamStartedAt: record.streamStartedAt ?? null,
- lastEndedAt: now().toISOString(),
- wholeFromStart: true,
- });
- if (c.covers) {
- say(`A part from its start already holds the stream to now (${spanWords(longest)} of ${spanWords(c.streamSeconds ?? 0)}): no further from-start pass.`);
- break;
- }
- if (exitedWithBytes && extraPasses >= 1) {
+ if (cls === "ended" || cls === "private" || cls === "members") {
+ say(`The recorder said the stream is ${cls === "ended" ? "over" : cls === "private" ? "private or removed" : "members-only"}, but it reads live: restarted.`);
+ }
+ let pause = LIVE_RESTART_WAIT_MS;
+ if (cls === "rate-limited") {
+ if (restartLimited) {
await refuse(
- "one extra from-start pass was already made after a recorder ended with the stream reading live",
- "NOT restarted: one extra from-start pass was already made after a recorder ended while the stream read live; what was recorded lands, and the row needs a person.",
+ "rate-limited again after the 15 min wait",
+ "NOT restarted: rate-limited again after the 15 min wait — the stream reads live and is NOT recorded; the row needs a person.",
);
break;
}
+ restartLimited = true;
+ say(`${cur.o.part.stem}: refused by a rate limit or the bot check, and the stream reads live — ONE restart after ${spanWords(LIVE_RATE_LIMIT_WAIT_MS / 1000)}, then no more.`);
+ await waitFor(stretch(LIVE_RATE_LIMIT_WAIT_MS), signal);
+ if (signal.aborted) break;
+ pause = 0;
}
const refusal = restartRefusal(restarts, now().getTime());
if (refusal) {
- await refuse(refusal, `NOT restarted (${refusal}) though the stream is live: what was recorded lands, and the row needs a person.`);
+ await refuse(`${refusal}: the stream reads live and is NOT recorded`, `NOT restarted (${refusal}): the stream reads live and is NOT recorded; the row needs a person.`);
break;
}
if (!(await roomFor(`restart ${restarts.count + 1}`))) {
- await refuse(`the store's disk has less than ${formatBytes(RECORD_LIVE_MIN_FREE_BYTES)} free`, "NOT restarted for want of disk; what was recorded lands.");
+ await refuse("not enough room on the store's disk: the stream reads live and is NOT recorded", "NOT restarted for want of disk: the stream reads live and is NOT recorded; the row needs a person.");
break;
}
if (pause) await waitFor(stretch(pause), signal);
if (signal.aborted) break;
- if (exitedWithBytes && cur.mode !== "now") extraPasses += 1;
restarts.count += 1;
restarts.at.push(now().toISOString());
const k = restarts.count;
- say(`Restart ${k} (${why}, the stream ${state === "live" ? "is live" : "state unknown"}): a new part ${cur.mode === "now" ? "from the live edge" : "from its start"}; the earlier part is kept for the landing.`);
- const o = await ytdlpPart(plan.url, `ytdlp-r${k}`, cur.mode, `restart ${k} (${why}); `, {
+ say(`Restart ${k} (${why}, the stream ${state === "live" ? "is live" : "state unknown"}): a new part from the live edge; the earlier part is kept for the landing.`);
+ const o = await ytdlpPart(plan.url, `ytdlp-r${k}`, "now", `restart ${k} (${why}); `, {
restart: k,
noWait: true,
- onStart: onMainStart(cur.mode, true),
+ onStart: onMainStart("now", true),
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"}`;
- o.part.failureClass = liveFailureClass(o.stderrTail);
+ emptyInRow += 1;
+ const last = recentOutput(o);
+ o.part.error = lastErrorLine(last) ?? `yt-dlp exit ${o.exitCode ?? "null"}`;
+ o.part.failureClass = liveFailureClass(last);
await save();
- if (c === "final" || c === "argv" || c === "unsupported") {
- say(`Restart ${k} recorded nothing (${o.part.error}): no more restarts.`);
+ if (classifyAttempt({ ...o, stderrTail: last, bytes }) === "argv") {
+ await refuse("the live-edge command cannot work (argv)", `Restart ${k} recorded nothing (${o.part.error}): the command cannot work — the stream may be live and NOT recorded; the row needs a person.`);
break;
}
- }
- cur = { o, bytes, mode: cur.mode, partial };
+ } else if (bytes > 0) emptyInRow = 0;
+ cur = { o, bytes, mode: "now", 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);
@@ -2246,10 +2287,10 @@ async function recordLiveRunInner(
let need = 0;
for (const x of placed) need += await sizeOf(x.jp.file);
const free = await (deps.freeBytes ?? getFreeBytes)(storeRoot).catch(() => 0);
- if (free < need + RECORD_LIVE_MIN_FREE_BYTES) {
+ if (free < need + minFree) {
room = false;
(record.spaceHeld ??= []).push({ what: "the join of the parts", at: now().toISOString(), freeBytes: free });
- 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.`);
+ say(`Not joined: the store's disk has ${formatBytes(free)} free, a join of these parts needs ${formatBytes(need + minFree)}. The longest lands; the rest are kept.`);
}
}
if (placed.length >= 2 && room) {
@@ -2322,11 +2363,28 @@ async function recordLiveRunInner(
// 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.
- const bestEnd = best.part?.endedAt ? Date.parse(best.part.endedAt) : null;
+ // A PART THAT MAY HOLD THE STREAM'S END (REVIEW-2 1.1 of live-guard-2): one
+ // not from the start (live edge, insurance, restart), this run's or an
+ // earlier one's (its row), or one no row describes, is removed only when
+ // its span is proven inside the landed file — on the STREAM's clock: its
+ // place (its recorder's start minus the stream's start, which the live
+ // edge's lag can only overstate) plus its length within a minute of the
+ // landed file's end, against the ended stream's own duration. Never on a
+ // coverage by the clock.
+ const placeRows = await loadLiveRecordingRows(paths, req.slug).catch(() => []);
+ const placeOf = new Map(placeRows.filter((r) => r.id === id).flatMap((r) => r.parts).filter((x) => x.stem).map((x) => [x.stem!, x]));
+ const streamStartMs = record.streamStartedAt ? Date.parse(record.streamStartedAt) : NaN;
+ const landedEnd = landedFromStart && best.seconds !== null ? best.seconds : null;
+ const mayHoldEnd = (o: Other): boolean => {
+ const p = o.part ?? placeOf.get(o.group.stem);
+ if (p?.fromStart) return false;
+ if (cov.basis !== "duration" || landedEnd === null || !p?.startedAt || !Number.isFinite(streamStartMs)) return true;
+ const secs = o.seconds ?? p.seconds ?? null;
+ if (secs === null) return true;
+ return (Date.parse(p.startedAt) - streamStartMs) / 1000 + secs > landedEnd + 60;
+ };
for (const o of others) {
- // A live-edge part that ended more than a minute after the landed part
- // may hold the stream's end, however the tolerance reads (REVIEW-1 1.10).
- const laterEnd = o.part && !o.part.fromStart && o.part.endedAt && bestEnd !== null && Date.parse(o.part.endedAt) > bestEnd + 60_000;
+ const laterEnd = mayHoldEnd(o);
if (cov.covers && !laterEnd) {
toRemove.push({
group: o.group,
diff --git a/common/lib/liveCapture.ts b/common/lib/liveCapture.ts
@@ -747,8 +747,10 @@ export type LiveBootRestart = { at: string; by: "boot"; state: LiveBootRestartSt
export const LIVE_WATCH_MS = 60_000;
export const LIVE_RESTART_WAIT_MS = 30_000;
export const LIVE_RESTART_CONFIRM_MS = 60_000;
-export const LIVE_RESTART_MAX_PER_HOUR = 3;
-export const LIVE_RESTART_MAX_PER_RUN = 12;
+// Restarts are live-edge recorders (REVIEW-2 of live-guard-2): cheap, so a
+// flaky connection gets more of them than the whole-stream passes once did.
+export const LIVE_RESTART_MAX_PER_HOUR = 6;
+export const LIVE_RESTART_MAX_PER_RUN = 24;
export type LiveRestarts = {
count: number;