commit 410c865cf367310d12cf30a78d4f7fcc532abf76
parent ae411a07bccd4505c87082729df83b694d490f76
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Fri, 20 Nov 2026 12:59:17 -0500
common: a "from now" recording with no readable start gives no chat zero
liveChatClockZero fell through to release_timestamp when the landed part
was recorded "from now" but its startedAt was missing or unparsable, and
called that zero certain: the one case where the broadcast's start is
known to be the wrong zero. It now answers no zero (basis capture-start,
not certain), so the live lines stay on the capture's clock and the log
says so.
readLiveChatZero reads live-recording.json as written (coerceLiveRecording
only validates it): coercion drops a part with no startedAt, and with the
part gone the record's own fromStart decides.
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
4 files changed, 54 insertions(+), 12 deletions(-)
diff --git a/common/controller/normalizeLiveChat.test.ts b/common/controller/normalizeLiveChat.test.ts
@@ -184,6 +184,23 @@ test("no zero to be had (no release_timestamp, no recording): the capture's cloc
assert.equal(doc.clock?.certain, false);
});
+test("a recording NOT from the start with no readable start: no zero, the capture's clock, and the log says so", async () => {
+ const rec = recording({ fromStart: false });
+ const parts = rec.parts.map(({ startedAt, ...p }) => (void startedAt, p));
+ const dir = await videoDir({
+ raw: [liveLine(100_000, { id: "m1", author: "viewer1", text: "hello" })],
+ rec: { ...rec, parts },
+ });
+ const logs: string[] = [];
+ const out = await normalizeLiveChat({ videoDir: dir, channelSlug: "demo-channel", force: true, tier: false, log: (m) => logs.push(m) });
+ assert.equal(out.status, "wrote");
+ const doc = JSON.parse(await readFile(path.join(dir, "live_chat.cues.json"), "utf8")) as Doc;
+ assert.equal(doc.cues[0].start, 100);
+ assert.equal(doc.clock?.basis, "capture-start");
+ assert.equal(doc.clock?.certain, false);
+ assert.ok(logs.some((l) => /left on the capture's clock/.test(l)), logs.join("\n"));
+});
+
test("a pure replay: the same starts as ever, basis replay", async () => {
const dir = await videoDir({
raw: [replayLine(12_000, { id: "a", author: "viewer1", text: "lol" }), replayLine(14_000, { id: "b", author: "viewer2", text: "W" })],
diff --git a/common/controller/normalizeLiveChat.ts b/common/controller/normalizeLiveChat.ts
@@ -21,6 +21,7 @@ import {
parseLiveChatDetailed,
type LiveChatClock,
type LiveChatZero,
+ type LiveRecordingLike,
} from "../lib/liveChat";
import { LIVE_RECORDING_FILENAME, coerceLiveRecording } from "../lib/liveCapture";
import type { Cue } from "../lib/vtt";
@@ -97,8 +98,14 @@ export async function readLiveChatZero(
(raw) => JSON.parse(raw) as { release_timestamp?: unknown },
() => null,
);
+ // The record as written, not coerceLiveRecording's: that drops a part with
+ // no `startedAt`, and a "from now" part with no start must still say "no
+ // zero" rather than fall back to the broadcast's start.
const record = await readFile(path.join(videoDir, LIVE_RECORDING_FILENAME), "utf8").then(
- (raw) => coerceLiveRecording(JSON.parse(raw)),
+ (raw) => {
+ const parsed: unknown = JSON.parse(raw);
+ return coerceLiveRecording(parsed) ? (parsed as LiveRecordingLike) : null;
+ },
() => null,
);
return liveChatClockZero(parsedMeta, record);
@@ -202,7 +209,7 @@ function clockNote(clock: LiveChatClock): string {
if (clock.basis === "replay") return "";
const dup = clock.duplicatesDropped > 0 ? `, ${clock.duplicatesDropped} duplicate(s) of the replay dropped` : "";
if (clock.basis === "capture-start") {
- return ` — ${clock.liveLines} line(s) captured live, left on the capture's clock (no broadcast start known)${dup}`;
+ return ` — ${clock.liveLines} line(s) captured live, left on the capture's clock (no zero known for the recording)${dup}`;
}
const shift = clock.shiftSeconds !== undefined ? ` ${clock.shiftSeconds} s` : "";
return (
diff --git a/common/lib/liveChat.test.ts b/common/lib/liveChat.test.ts
@@ -76,6 +76,18 @@ test("the recording's zero", () => {
assert.deepEqual(liveChatClockZero(meta, { status: "landed", landedPart: 0, parts: [part(false)] }), {
zeroMs: T0 + 50_000, basis: "recording-start", certain: false,
});
+ // From now with no readable start: no zero (never the broadcast's start).
+ for (const startedAt of [undefined, "not a date"]) {
+ assert.deepEqual(
+ liveChatClockZero(meta, { status: "landed", landedPart: 0, parts: [{ fromStart: false, ...(startedAt ? { startedAt } : {}) }] }),
+ { zeroMs: null, basis: "capture-start", certain: false },
+ );
+ }
+ // The landed part missing from the record: the record's own mode decides.
+ assert.deepEqual(liveChatClockZero(meta, { status: "landed", landedPart: 0, fromStart: false, parts: [] }), {
+ zeroMs: null, basis: "capture-start", certain: false,
+ });
+ assert.equal(liveChatClockZero(meta, { status: "landed", landedPart: 0, fromStart: true, parts: [] }).zeroMs, T0);
// A recording that landed nothing did not make the media.
assert.equal(liveChatClockZero(meta, { status: "failed", parts: [part(false)] }).basis, "broadcast-start");
// Nothing known.
diff --git a/common/lib/liveChat.ts b/common/lib/liveChat.ts
@@ -248,6 +248,8 @@ export type LiveChatZero = {
// LiveRecordingRecord), structurally, so this file stays import-free.
export type LiveRecordingLike = {
status?: string;
+ // The record's own mode, for a part the record cannot show.
+ fromStart?: boolean;
landedPart?: number;
parts?: { fromStart?: boolean; startedAt?: string }[];
reach?: { fromStart?: boolean; missingSeconds?: number | null } | null;
@@ -265,7 +267,8 @@ export type LiveRecordingLike = {
* the second (measured 20 Nov: four lines a streamer read aloud sat 6–14 s
* after it — the stream's latency and the reading, which stay).
* - A part recorded "from now": that part's start — yt-dlp's start-up and the
- * live edge's lag are not known, so it is NOT certain.
+ * live edge's lag are not known, so it is NOT certain. With no readable
+ * start, no zero: the broadcast's start is known to be wrong for it.
* - A failed or cancelled recording that landed nothing did not make the
* media: as if there were none.
* - Neither known: null (the capture's clock stays).
@@ -275,19 +278,22 @@ export function liveChatClockZero(
record: LiveRecordingLike | null | undefined,
): LiveChatZero {
const parts = Array.isArray(record?.parts) ? record.parts : [];
- const part =
- typeof record?.landedPart === "number"
- ? parts[record.landedPart]
- : record?.status === "recording"
- ? parts.at(-1)
- : undefined;
- if (part && part.fromStart === false) {
- const startedMs = part.startedAt ? Date.parse(part.startedAt) : NaN;
+ // The recording made the media when it landed a part or is still recording.
+ const madeMedia = typeof record?.landedPart === "number" || record?.status === "recording";
+ const picked = typeof record?.landedPart === "number" ? parts[record.landedPart] : madeMedia ? parts.at(-1) : undefined;
+ const part = picked && typeof picked === "object" ? picked : undefined;
+ // The part's own mode, else the record's (a part missing from the record).
+ const fromStart = part && typeof part.fromStart === "boolean" ? part.fromStart : madeMedia ? record?.fromStart : undefined;
+ if (fromStart === false) {
+ const startedMs = typeof part?.startedAt === "string" ? Date.parse(part.startedAt) : NaN;
if (Number.isFinite(startedMs)) return { zeroMs: startedMs, basis: "recording-start", certain: false };
+ // A "from now" recording with no readable start: the broadcast's start is
+ // known to be the WRONG zero here, so there is none.
+ return { zeroMs: null, basis: "capture-start", certain: false };
}
const release = meta?.release_timestamp;
if (typeof release === "number" && Number.isFinite(release) && release > 0) {
- const reach = part ? record?.reach : null;
+ const reach = madeMedia ? record?.reach : null;
const missing =
reach && reach.fromStart === false && typeof reach.missingSeconds === "number" ? reach.missingSeconds : 0;
return { zeroMs: (release + missing) * 1000, basis: "broadcast-start", certain: true };