commit be9fbdcc1dbd38e6cabe4612dd50bddcab0771c4
parent 749ca718c037dc502ffc90bc59ee8dc2a8250aca
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Sat, 21 Nov 2026 23:01:16 -0500
record-live: a restart bound reached on a live stream is waited out, not an end (REVIEW-5 note 3); docs for REVIEW-5 B
- restartWaitMs: the hour's 6 free when the oldest is an hour old; past
24 in a run, at most one an hour. The run waits (restarts.waiting on the
row, loud while it waits; restarts.waited counts), reads the state, and
goes on while the stream is live.
- OPERATING.md and the changelog: the waiting part's way into the store,
the boot's landing words, the process group and the stop signal, every
stream pinned, per-stream growth, 119 h, the boot's age, the bound, the
transcript replaced.
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
7 files changed, 122 insertions(+), 35 deletions(-)
diff --git a/OPERATING.md b/OPERATING.md
@@ -1484,20 +1484,29 @@ pnpm ops keep-videos --json '{"slug":"example-rumble","ids":["v1abcde"],"note":
fragment. So a from-start recorder that dies, stalls, or is stopped by an editor shutdown is restarted as the SAME
part: the same stem, the format pinned to the ids on disk, from where it stopped — no new part, no gap, no second
download (`resumes` on the part). A resumed part keeps the proof of start its original run earned
- (`provenStart`); a live-edge or recovery part never has one. The watchdog and a shutdown stop it with SIGTERM, which leaves the state; a
- person's Cancel is SIGINT, which finishes the file. At a shutdown such a part is not landed: it waits in staging
- (`awaitingResume`) and the boot's restart resumes it (the interrupted row then no longer lists it). Such a part is
- never landed, removed or counted inside another by any run that did not resume it: a later Record again lists it
- as waiting too, and its row needs a person. Only when a resume is impossible (no state: the file was
- finished; an unreadable state; a stream past 120 h; a resume that writes nothing) does the live-edge fallback below
- run. A state read refused as private or removed is read again a minute later; confirmed, the row says the stream
+ (`provenStart`); a live-edge or recovery part never has one. The watchdog and a shutdown stop it with SIGTERM, which
+ leaves the state — but only when the part can be resumed at that moment (separate streams, each with its state);
+ every other recorder, a muxed ffmpeg download included, gets SIGINT, which finishes its file. A person's Cancel is
+ SIGINT. The recorder runs in a process group of its own, so a stop reaches yt-dlp's ffmpeg too, and the recorder
+ returns when yt-dlp exits (a process still holding its output 3 s later is killed with the group). A resume pins
+ EVERY stream file of the part, an empty one included; a separate part with fewer than two streams, or two of one
+ kind, is not resumed. A stream that recorded nothing is said on the row when its recorder stops. Each stream file
+ must grow: one that stops for `stallMinutes` while the other grows is a stall. At a shutdown a resumable part is
+ not landed: it waits in staging (`awaitingResume`) and the boot's restart resumes the LONGEST resumable from-start
+ part any row of the stream lists (no row then lists it). A waiting part is never the only copy left in staging for
+ good: any later run of the stream not itself stopped by a shutdown — the boot's run that did not resume it, a
+ person's Record again — takes it into its landing by the rules (merged, landed, or kept and listed). Only when a
+ resume is impossible (no state: the file was finished; an unreadable state; a stream past 119 h, or whose start
+ time is not known; a resume that writes nothing) does the live-edge fallback below run. A state read refused as private or removed is read again a minute later; confirmed, the row says the stream
went private or was removed while recording and what is held (`endedBy`, needing a person).
- **A whole file that replaces a shorter stored one asks for the transcription again when the transcript is the short
one's.** Told by the transcript itself: its last cue ends no later than the replaced container's length plus 60 s
while the new container runs on more than 60 s past it, so it holds nothing of the rest (`transcriptRedo` on the
row, verdict `shorter`: the transcription is asked, the job on the row). When that cannot be told — the transcript
does not read or parse, holds no cues, or the replaced file's length is not known — the verdict is `unknown`, nothing
- is asked, and the row needs a person; so does a `shorter` whose ask was refused. A transcript whose speech runs past
+ is asked, and the row needs a person; so does a `shorter` whose ask was refused. The ask REPLACES the transcript
+ (`replace`: without it the job would find `transcript.json` and do nothing); the old one stays until the new one is
+ written over it. A transcript whose speech runs past
the replaced file's end is left as it is.
- **A stalled or dead recorder is restarted while the stream is live.** Every path-A recorder (and every try beside
the live edge) has a watchdog: its part's files, scratch included, are compared every minute; no growth for
@@ -1513,8 +1522,11 @@ pnpm ops keep-videos --json '{"slug":"example-rumble","ids":["v1abcde"],"note":
most 8 a run every 15 min (none left: the row stays loud) —
until a from-start part reaches where the live-edge part begins; then the row is quiet about it. The stream counts as ended only
on evidence: the state read says so, or three live-edge recorders in a row capture nothing (then, if it still reads
- live, the row is loud). At most 6 restarts in any hour and 24 in a run; past them, or when the state cannot be read
- after an exit, the row says the stream may be live and is NOT recorded (`restarts.refused`) and needs a person.
+ live, the row is loud). At most 6 restarts in any hour, and past 24 in a run at most one an hour: a bound reached on
+ a stream still live is WAITED OUT, not an end — the row says it is not recording until the hour frees a restart
+ (`restarts.waiting`, needing a person while it waits; `restarts.waited` counts them), then it goes on. When the
+ state cannot be read after an exit, the row says the stream may be live and is NOT recorded (`restarts.refused`) and
+ needs a person.
What the recorder said LAST (its output after its last progress line) is classified, also for a part that died
with bytes; the state is read before any conclusion: the disk is not restarted; a 429 or the bot check, with the
stream live, gets ONE restart after 15 min, a second is refused; "ended"/"private" text while the stream reads live
@@ -1561,9 +1573,12 @@ pnpm ops keep-videos --json '{"slug":"example-rumble","ids":["v1abcde"],"note":
live, it records again (the earlier parts stay for the landing's rules) and the interrupted row says `restart:
restarted` — and needs a person until the NEW run's part is growing (a new run that fails, never starts or lands
short leaves it loud, and the listing says which); ended, it records nothing and lands what is in staging
- (`landing`), or with nothing left says `ended` (the end is not recorded: needs a person); unreadable, the state is
- read again after 2 and 8 minutes (not after a rate limit, members-only or the disk), and if it never reads it starts
- and lands NOTHING (`unknown`: the stream may be live and NOT recorded, needs a person: Record again). A person's Cancel never restarts. A restart loop cannot
+ (`landing`, then `landed` or `failed` with what the landing did), or with nothing left says `ended` (the end is not
+ recorded: needs a person); unreadable, the state is read again after 2 and 8 minutes (not after a rate limit,
+ members-only or the disk), and if it never reads it records nothing but STILL lands what is in staging — the only
+ copy — and the row says the state could not be read (or that the stream was made private or removed) and to Record
+ again if it is live; with nothing left it says `unknown`. The age that makes a row too old to restart (12 h) is
+ from its recorder's LAST WRITE (the newest part file), and a row skipped for it is marked `refused` and logged. A person's Cancel never restarts. A restart loop cannot
run: the row is marked before the job is asked (a run restarts once), at most 3 automatic restarts of a stream in
an hour (then `refused`), and a part file written after the boot, or one that changes between three looks 20 s
apart — a recorder of the last process may still be writing — refuses it too.
diff --git a/common/controller/liveRecordings.ts b/common/controller/liveRecordings.ts
@@ -198,6 +198,8 @@ function reasonOf(v: Omit<LiveRecordingView, "reason" | "check">, stallMinutes:
if (v.spaceHeld && v.spaceHeld.length) extra.push(`NOT started for want of disk: ${v.spaceHeld.map((x) => x.what).join(", ")}`);
if (v.restarts && v.restarts.count > 0) extra.push(`its recorder was restarted ${v.restarts.count} time${v.restarts.count === 1 ? "" : "s"} (stalled or died while live)`);
if (v.restarts?.refused) extra.push(`NOT restarted again though the stream was live: ${v.restarts.refused}`);
+ if (v.restarts?.waiting) extra.push(`NOT recording until ${v.restarts.waiting.until}: the restart bound (${v.restarts.waiting.why}) is waited out, then it goes on`);
+ else if (v.restarts?.waited) extra.push(`waited out the restart bound ${v.restarts.waited} time${v.restarts.waited === 1 ? "" : "s"} (nothing recorded while it waited)`);
if (v.lost && !v.fallback && v.startRecovery?.state !== "recovered") {
const hm = (x: number) => `${Math.floor(x / 3600)}:${String(Math.floor((x % 3600) / 60)).padStart(2, "0")}`;
extra.unshift(
diff --git a/common/controller/recordLive.test.ts b/common/controller/recordLive.test.ts
@@ -1399,21 +1399,25 @@ 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 (6 an hour); past it the run lands what it has and the row needs a person", { timeout: 60_000 }, async () => {
+test("slice 3: restarts are bounded (6 an hour); past it the run WAITS the hour out and goes on (REVIEW-5 note 3), and every part is accounted for", { timeout: 60_000 }, async () => {
const id = "exmplbound1";
- // Each recorder writes and then stalls.
- const { run, calls } = await incidentRun(
+ // Each recorder writes and then stalls; the stream ends after the 9th.
+ let n0 = 0;
+ const { run, calls, waits } = await incidentRun(
id,
- async (args, n, signal) => hangAfter(100 * n)(args, n, signal),
- { deps: FAST_WATCH, refresh: { stillLive: () => true }, meta: { ...YT_META(id), release_timestamp: Math.floor(Date.now() / 1000) - 100 }, },
+ async (args, n, signal) => {
+ n0 = n;
+ return hangAfter(100 * n)(args, n, signal);
+ },
+ { deps: FAST_WATCH, refresh: { stillLive: () => n0 < 9 }, meta: { ...YT_META(id), release_timestamp: Math.floor(Date.now() / 1000) - 100 }, },
);
const s = await run;
assert.equal(s.status, "landed");
- assert.equal(calls.length, 7, "the first recorder and 6 restarts, no more");
+ assert.ok(calls.length >= 8, `past the hour's 6 restarts: ${calls.length} recorders`);
+ assert.ok(waits.some((w) => w > 60_000 && w <= 3_600_000), "the hour waited out");
const row = (await rowOf(id))[0]!;
- 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.equal(row.restarts?.refused, undefined);
+ assert.ok((row.restarts?.waited ?? 0) >= 1);
assert.ok((row.keptParts?.length ?? 0) + (row.removedParts?.length ?? 0) >= 3, "every part is accounted for");
});
@@ -2316,21 +2320,24 @@ test("REVIEW2 3.2: a second and a third death while the stream reads live restar
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.
+ // Dying again and again while live: the hour's bound is waited out (said),
+ // and it goes on until the stream ends (REVIEW-5 note 3).
const id2 = "exmplr2a303";
+ let k = 0;
const b = await incidentRun(
id2,
async (args) => {
+ k++;
await writeFile(`${outOf(args)}.mp4`, "format=mov,mp4;seconds=300;");
return deaths;
},
- { deps: { ...FAST_WATCH, join: null, merge: fakeMerge }, refresh: { stillLive: () => true }, meta: { ...YT_META(id2), release_timestamp: Math.floor(Date.now() / 1000) - 300 } },
+ { deps: { ...FAST_WATCH, join: null, merge: fakeMerge }, refresh: { stillLive: () => k < 10 }, meta: { ...YT_META(id2), release_timestamp: Math.floor(Date.now() / 1000) - 300 } },
);
- await b.run;
- assert.equal(b.calls.length, 1 + 6, "the first recorder and 6 restarts (the hour's bound)");
+ await b.run.catch(() => {});
+ assert.ok(b.calls.length > 1 + 6, `past the hour's bound: ${b.calls.length}`);
const row = (await rowOf(id2))[0]!;
- assert.match(row.restarts?.refused ?? "", /reads live and is NOT recorded/);
- assert.equal(row.needsAttention, true);
+ assert.equal(row.restarts?.refused, undefined);
+ assert.ok((row.restarts?.waited ?? 0) >= 1, "the row says it waited");
});
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 () => {
@@ -3866,3 +3873,27 @@ test("REVIEW-5 note 1: one stream that stops growing while the other grows is a
assert.equal(outOf(calls[1]!), outOf(calls[0]!), "resumed in place");
assert.equal(calls[1]![calls[1]!.indexOf("-f") + 1], "136+140");
});
+
+test("REVIEW-5 note 3: the restart bound reached on a stream still live does not end the recording: it waits out the hour, continues, and the row says it waited", { timeout: 60_000 }, async () => {
+ const id = "exmplnote3a";
+ let live = true;
+ const { run, calls, waits, log } = await incidentRun(
+ id,
+ async (args, n) => {
+ // Every recorder exits a moment later with what it wrote (an IRL
+ // stream whose ingest keeps dropping); the stream ends after 9.
+ await writeFile(`${outOf(args)}.mp4`, `format=mov,mp4;seconds=${60 + n};`);
+ if (n >= 9) live = false;
+ return okExit;
+ },
+ { request: { fromStart: false }, deps: { ...FAST_WATCH, join: null, merge: fakeMerge }, refresh: { stillLive: () => live } },
+ );
+ await run.catch(() => {});
+ const row = (await rowOf(id))[0]!;
+ assert.equal(row.restarts?.refused, undefined, "never refused while live");
+ assert.ok((row.restarts?.count ?? 0) >= 7, `restarted past the hour's 6 (${row.restarts?.count})`);
+ assert.ok((row.restarts?.waited ?? 0) >= 1, "it waited");
+ assert.ok(waits.some((w) => w > 60_000 && w <= 3_600_000), `an hour's wait: ${waits.join(", ")}`);
+ assert.ok(log.some((l) => /waits? .*before restart/i.test(l)));
+ assert.ok(calls.length >= 8);
+});
diff --git a/common/controller/recordLive.ts b/common/controller/recordLive.ts
@@ -73,7 +73,7 @@ import {
LIVE_INSURANCE_MAX_STARTS,
catchUpTracker,
insuranceDecision,
- restartRefusal,
+ restartWaitMs,
classifyAttempt,
extractionRefused,
ffmpegLiveArgs,
@@ -2381,10 +2381,20 @@ async function recordLiveRunInner(
if (signal.aborted) break;
pause = 0;
}
- const refusal = restartRefusal(restarts, now().getTime());
- if (refusal) {
- 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;
+ // THE BOUNDS ARE WAITED OUT (REVIEW-5 note 3): on a stream that reads
+ // live the recording does not end at the bound — it waits until the
+ // hour frees a restart, said on the row, and goes on.
+ const bound = restartWaitMs(restarts, now().getTime());
+ if (bound) {
+ restarts.waiting = { until: new Date(now().getTime() + bound.ms).toISOString(), why: bound.why };
+ restarts.waited = (restarts.waited ?? 0) + 1;
+ await save();
+ say(`The restart bound is reached (${bound.why}) while the stream reads live: it waits ${spanWords(bound.ms / 1000)} before restart ${restarts.count + 1} — the stream is NOT recorded meanwhile.`);
+ await waitFor(bound.ms, signal);
+ delete restarts.waiting;
+ await save();
+ if (signal.aborted) break;
+ if ((await liveNow()) === "ended") break;
}
if (!(await roomFor(`restart ${restarts.count + 1}`))) {
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.");
diff --git a/common/lib/liveCapture.ts b/common/lib/liveCapture.ts
@@ -805,8 +805,27 @@ export type LiveRestarts = {
at: string[];
// Why no further restart was made though the stream was live.
refused?: string;
+ // REVIEW-5 note 3: a bound reached on a stream still live is waited out,
+ // not an end: how many times, and the wait in progress (nothing records
+ // meanwhile — the row says so).
+ waited?: number;
+ waiting?: { until: string; why: string };
};
+// How long to wait before one more restart at `nowMs` (REVIEW-5 note 3): the
+// hour's bound frees when its oldest restart is an hour old; past the run's
+// bound, at most one an hour. null: no wait.
+export function restartWaitMs(r: Pick<LiveRestarts, "count" | "at">, nowMs: number): { ms: number; why: string } | null {
+ const recent = r.at.map((a) => Date.parse(a)).filter((t) => nowMs - t < 3_600_000).sort((a, b) => a - b);
+ if (recent.length >= LIVE_RESTART_MAX_PER_HOUR) {
+ return { ms: Math.max(1_000, recent[0]! + 3_600_000 - nowMs), why: `${recent.length} restarts in the last hour (at most ${LIVE_RESTART_MAX_PER_HOUR})` };
+ }
+ if (r.count >= LIVE_RESTART_MAX_PER_RUN && recent.length) {
+ return { ms: Math.max(1_000, recent[recent.length - 1]! + 3_600_000 - nowMs), why: `${r.count} restarts in this run (past ${LIVE_RESTART_MAX_PER_RUN}: at most one an hour)` };
+ }
+ return null;
+}
+
// Whether one more restart is allowed at `nowMs`; else the reason.
export function restartRefusal(r: Pick<LiveRestarts, "count" | "at">, nowMs: number): string | null {
if (r.count >= LIVE_RESTART_MAX_PER_RUN) return `${r.count} restarts in this run (at most ${LIVE_RESTART_MAX_PER_RUN})`;
diff --git a/common/lib/liveRecordings-server.ts b/common/lib/liveRecordings-server.ts
@@ -196,6 +196,8 @@ export function rowNeedsAttention(
// A span of the stream in no part (REVIEW-3 3.1), until a part holds it.
if (r.lost && r.startRecovery?.state !== "recovered") return true;
if (r.restarts?.refused) return true;
+ // Waiting out a restart bound: nothing records meanwhile.
+ if (r.restarts?.waiting) return true;
// A recorder (or a join) not started for want of disk.
if (r.spaceHeld && r.spaceHeld.length) return true;
// The stream went private or was removed while it was recorded.
diff --git a/editor/CHANGELOG.md b/editor/CHANGELOG.md
@@ -19,8 +19,16 @@
the joins on the row and in `live-joins.json`; a gap is stated and needs a person.
- A part resumed in place keeps the proof of start its original run earned; a part waiting to be resumed is never
landed, removed or counted by a run that did not resume it.
- - A whole file that replaces a stored shorter landing asks for the transcription again when the transcript's last
- cue ends inside the shorter file (`transcriptRedo`); when that cannot be told, the row needs a person.
+ - A whole file that replaces a stored shorter landing asks for the transcription again, replacing the transcript,
+ when the transcript's last cue ends inside the shorter file (`transcriptRedo`); when that cannot be told, the row
+ needs a person.
+ - A part left waiting to be resumed always reaches the store: the boot's run lands it when the stream ended, was
+ removed or cannot be read, and any later run takes it into its landing; the row says what was done.
+ - The recorder runs in its own process group (a stop reaches yt-dlp's ffmpeg); SIGTERM only for a part that can
+ be resumed; a resume pins every stream, the empty one too; each stream must grow; 119 h, and an unknown start
+ is not resumable.
+ - The boot pass measures a row's age from its recorder's last write, and marks a row it skips for its age.
+ - A restart bound reached on a stream still live is waited out (said on the row), not the end of the recording.
- **A live recording's landing never deletes around, or replaces, a recording already in the store that it is not
proven to hold.**
- When the landing keeps the container already stored, nothing is removed: the part and every part meant for