commit ca1330dfcb5d08a5084c9711159590a75a29fd34
parent 075a0498434c59d702d4587aa45a7ed20674d27c
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Fri, 6 Nov 2026 21:06:45 -0500
common, editor: fetch-windows makes the recording's clock current before it answers or cuts a whole-recording window
A whole-recording channel's video (Rumble) with a saved container has its
time map made current before any window of it is answered from clips/ or cut:
measured when missing or stale (anchored every 5 min and around every span the
run asks of it), and right after a whole download. Its windows cut on another
clock -- a remote seek, a cut made before the map -- are retired through the
targeted eviction and cut again on the cue clock (`clocked`, `retired` in the
result, said in the log). A map that cannot be measured is said, and the cut
goes on the container's clock for the quote check to catch.
The editor's door answers the same way: fetch-windows' planner and the single
fetch-window treat a held window of such a video as cached only when it was cut
through the current map (heldWindowOnClock); otherwise the span goes on to the
saved container.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
5 files changed, 256 insertions(+), 5 deletions(-)
diff --git a/common/controller/fetchWindows.test.ts b/common/controller/fetchWindows.test.ts
@@ -7,7 +7,7 @@
import { test } from "node:test";
import assert from "node:assert/strict";
-import { chmod, mkdir, mkdtemp, readFile, readdir, writeFile } from "node:fs/promises";
+import { chmod, mkdir, mkdtemp, readFile, readdir, rm, writeFile } from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import {
@@ -751,3 +751,88 @@ test("whole recording: wholeRecording false restores the remote seek; a platform
assert.equal(none.downloads.length, 0);
assert.deepEqual(r4.fetched.map((i) => i.id), ["v1"]);
});
+
+// ONE CLOCK PER RECORDING (lane one-clock): a whole-recording channel's saved
+// video has its time map measured (once per run, anchored around every span the
+// run asks of it) before a window is answered or cut, and the windows cut on
+// another clock are retired.
+const RUMBLE_CONFIG = { url: "https://rumble.com/c/x", platform: "rumble" } as unknown as ChannelConfig;
+const CLOCK = {
+ version: 1, id: "k1", createdAt: "", source: { file: "audio.mp3", bytes: 1 }, target: { file: "source-media.mp4", bytes: 1 },
+ method: "xcorr" as const, params: {}, anchors: [], segments: [{ from: 0, to: 600, offset: 13.1, rate: 0, n: 3, rms: 0 }],
+ gaps: [], residual: { rms: 0, max: 0, n: 3 }, ok: true,
+};
+
+function clockHarness(plan: "measure" | "current") {
+ const w = wholeHarness({ saved: ["v1"] });
+ const ensured: { videoDir: string; extra: number[] }[] = [];
+ const retiredFor: string[] = [];
+ w.h.deps.readChannelConfig = async (_p, slug) => (slug === "c" ? RUMBLE_CONFIG : null);
+ w.h.deps.ensureClock = async ({ videoDir, extra }) => {
+ ensured.push({ videoDir: path.basename(videoDir), extra });
+ return { clock: CLOCK, measured: plan === "measure", plan };
+ };
+ w.h.deps.retireOffClock = async ({ videoDir, clockId }) => {
+ retiredFor.push(`${path.basename(videoDir)}:${clockId}`);
+ const clips = path.join(videoDir, "clips");
+ const names = (await readdir(clips).catch(() => [] as string[])).filter((n) => n.endsWith(".mp4"));
+ for (const n of names) await rm(path.join(clips, n));
+ return names.map((n) => n.replace(/\.mp4$/, ""));
+ };
+ return { ...w, ensured, retiredFor };
+}
+
+test("one clock: the map is measured once per video, around the run's spans, before the cuts", async () => {
+ const c = clockHarness("measure");
+ const logs: string[] = [];
+ const r = await fetchWindows({
+ paths: await corpus(),
+ items: [rumbleItem("v1", 10), rumbleItem("v1", 40)],
+ provenance: { requestedBy: "test" },
+ gapMs: 1000,
+ onLog: (l) => logs.push(l),
+ deps: c.h.deps,
+ });
+ assert.deepEqual(c.ensured, [{ videoDir: "v1", extra: [15, 45] }]);
+ assert.deepEqual(c.retiredFor, ["v1:k1"]);
+ assert.deepEqual(r.clocked, ["c/v1"]);
+ assert.deepEqual(c.cuts.map((x) => x.from), [10, 40]);
+});
+
+test("one clock: a held window cut on another clock is retired and cut again", async () => {
+ const c = clockHarness("current");
+ const paths = await corpus();
+ const clips = path.join(paths.channelsDir, "c", "data", "v1", "clips");
+ await mkdir(clips, { recursive: true });
+ await writeFile(path.join(clips, "0.00-60.00.mp4"), "mp4");
+ await writeFile(path.join(clips, "0.00-60.00.json"), JSON.stringify({ requestedBy: "umtool" }));
+ const logs: string[] = [];
+ const r = await fetchWindows({
+ paths,
+ items: [rumbleItem("v1", 10)],
+ provenance: { requestedBy: "test" },
+ gapMs: 1000,
+ onLog: (l) => logs.push(l),
+ deps: c.h.deps,
+ });
+ assert.equal(r.cached.length, 0);
+ assert.deepEqual(r.retired, ["c/v1/clips/0.00-60.00"]);
+ assert.deepEqual(c.cuts.map((x) => x.from), [10]);
+ assert.match(logs.join(""), /window\(s\) cut on another clock .* retired: 0\.00-60\.00/);
+});
+
+test("one clock: a window held ON the map's clock is answered from the cache", async () => {
+ const c = clockHarness("current");
+ c.h.deps.retireOffClock = async () => [];
+ const paths = await corpus();
+ const clips = path.join(paths.channelsDir, "c", "data", "v1", "clips");
+ await mkdir(clips, { recursive: true });
+ await writeFile(path.join(clips, "0.00-60.00.mp4"), "mp4");
+ await writeFile(
+ path.join(clips, "0.00-60.00.json"),
+ JSON.stringify({ requestedBy: "umtool", source: "saved-video", clock: { id: "k1", from: 13.1, to: 73.1, offset: 13.1, certain: true } }),
+ );
+ const r = await go(paths, [rumbleItem("v1", 10)], c.h);
+ assert.equal(r.cached.length, 1);
+ assert.equal(c.cuts.length, 0);
+});
diff --git a/common/controller/fetchWindows.ts b/common/controller/fetchWindows.ts
@@ -30,6 +30,10 @@ import {
} from "../lib/clipWindowSync";
import { channelConfigPlatform } from "../lib/videoId";
import { resolveVideoDirId } from "../lib/videoDir-server.mjs";
+import { ensureRecordingClock } from "../lib/recordingClock-server";
+import type { RecordingClock } from "../lib/recordingClock.mjs";
+import { listClipWindows } from "../lib/clipWindow-server";
+import { evictClipWindows } from "./evictClipWindows";
import {
cutSavedVideoWindow,
savedWindowSource,
@@ -157,6 +161,20 @@ import { findVideoSourceUrl } from "./undownloadedVideos";
// seek for that run. The editor puts these items on the platform's DOWNLOAD
// queue (fetchWindowsAction.ts), where a persist runs, not its clip queue.
//
+// ONE CLOCK PER RECORDING (lane one-clock, lib/recordingClock.mjs). The cues
+// of a whole-recording channel were transcribed from another file than the
+// saved video (a Rumble channel's audio.mp3): two downloads of one stream, two
+// clocks — 13.6 s apart, and stepping inside one stream, on 6 Nov. So before a
+// window of such a video is answered from clips/ or cut from its saved
+// container, its TIME MAP (`clock.json`) is made current: measured now when
+// missing or stale (anchored every 5 min and around every span this run asks
+// of it), right after a whole download too. The cut then goes through it
+// (savedVideoWindow-server.ts), and the video's windows cut on another clock —
+// a remote seek, a cut made before the map — are RETIRED through the targeted
+// eviction, and their spans cut again. A map that could not be measured is
+// said in the log and the windows are cut on the container's clock: the
+// per-clip quote check (umtool quote-check) is what catches those.
+//
// A JOB OF THIS KIND SPANS CHANNELS, so runManagedFunction's per-channel text
// guard has no channel to ask. It is asked here instead, once per channel: an
// item on a channel whose text is not readable fails as `unreachable` (its
@@ -252,6 +270,11 @@ export type FetchWindowsResult = {
// again, and fresh fetches that failed `desynced` — as
// `<slug>/<dir id>/clips/<name>.desynced.<ext>`.
setAside: string[];
+ // ONE CLOCK PER RECORDING (the header): videos whose time map this run
+ // measured (`<slug>/<dir id>`), and the windows it retired as cut on another
+ // clock (`<slug>/<dir id>/clips/<from>-<to>`).
+ clocked?: string[];
+ retired?: string[];
stopped?: FetchWindowsStop;
};
@@ -304,8 +327,41 @@ export type FetchWindowsDeps = {
assertMediaReachable: (paths: Paths, slug: string) => Promise<unknown>;
// Save a video's whole recording to the saved-video store (the header).
saveWholeRecording: (opts: SaveWholeRecordingOpts) => Promise<SaveWholeRecordingResult>;
+ // The recording's time map (lib/recordingClock-server.ts): the current one,
+ // else measured now and written; null when none applies.
+ ensureClock: (opts: {
+ paths: Paths;
+ videoDir: string;
+ extra: number[];
+ onLog: (line: string) => void;
+ signal?: AbortSignal;
+ }) => Promise<{ clock: RecordingClock | null; measured: boolean; plan: string }>;
+ // Remove the windows of a video NOT cut through `clockId` (a remote seek, a
+ // cut made before the map): their seconds are another clock's. Returns the
+ // retired `<from>-<to>` names.
+ retireOffClock: (opts: { paths: Paths; slug: string; dirId: string; videoDir: string; clockId: string }) => Promise<string[]>;
};
+// The windows of a video cut on another clock than `clockId`, evicted through
+// the targeted eviction (controller/evictClipWindows.ts: windows known bad).
+async function retireOffClockWindows(o: {
+ paths: Paths;
+ slug: string;
+ dirId: string;
+ videoDir: string;
+ clockId: string;
+}): Promise<string[]> {
+ const off = (await listClipWindows(o.videoDir)).filter((w) => w.provenance?.clock?.id !== o.clockId);
+ if (!off.length) return [];
+ await evictClipWindows({
+ paths: o.paths,
+ slug: o.slug,
+ id: o.dirId,
+ windows: off.map((w) => ({ from: w.from, to: w.to })),
+ });
+ return off.map((w) => `${w.from.toFixed(2)}-${w.to.toFixed(2)}`);
+}
+
export type SaveWholeRecordingOpts = {
paths: Paths;
slug: string;
@@ -418,6 +474,16 @@ const DEFAULT_DEPS: FetchWindowsDeps = {
recordFailedCopy,
storedMediaUrl,
probeWindow: (file, paths) => probeWindowStreams(file, paths.ffprobeBin),
+ ensureClock: (o) =>
+ ensureRecordingClock({
+ ffmpegBin: o.paths.ffmpegBin,
+ ffprobeBin: o.paths.ffprobeBin,
+ videoDir: o.videoDir,
+ extra: o.extra,
+ onLog: o.onLog,
+ signal: o.signal,
+ }),
+ retireOffClock: retireOffClockWindows,
assertMediaReachable: (paths, slug) => assertChannelMediaReachable(paths, slug),
saveWholeRecording: saveWholeRecordingManaged,
};
@@ -589,6 +655,50 @@ export async function fetchWindows({
const interrupted = (): FetchWindowsStop | null =>
signal?.aborted ? "cancel" : drainSignal?.aborted ? "drain" : null;
+ // ONE CLOCK PER RECORDING (the header): each video's time map, once per run
+ // (null: none applies). A video with no saved container is not remembered —
+ // a whole download later in the run gives it one.
+ const clocks = new Map<string, RecordingClock | null>();
+ const clockOf = async (
+ item: FetchWindowsItem,
+ label: string,
+ videoDir: string,
+ dirId: string,
+ ): Promise<RecordingClock | null> => {
+ if (clocks.has(videoDir)) return clocks.get(videoDir) ?? null;
+ // Anchors around every span of this video the run asks for.
+ const extra = work.filter((w) => w.slug === item.slug && w.id === item.id).map((w) => (w.from + w.to) / 2);
+ let r: Awaited<ReturnType<FetchWindowsDeps["ensureClock"]>>;
+ try {
+ r = await deps.ensureClock({ paths, videoDir, extra, onLog: fetchLog, signal: fetchSignal });
+ } catch (e) {
+ log(
+ ` ⏱ ${label}: the recording's clock could not be measured (${(e as Error).message}); ` +
+ "its windows are cut on the saved video's own clock — check their quotes (umtool quote-check).",
+ );
+ clocks.set(videoDir, null);
+ return null;
+ }
+ if (r.plan === "no-container") return null;
+ clocks.set(videoDir, r.clock);
+ if (!r.clock) return null;
+ if (r.measured) (result.clocked ??= []).push(`${item.slug}/${dirId}`);
+ const retired = await deps
+ .retireOffClock({ paths, slug: item.slug, dirId, videoDir, clockId: r.clock.id })
+ .catch((e: unknown) => {
+ log(` ⏱ ${label}: retiring the windows cut on another clock failed: ${(e as Error).message}`);
+ return [] as string[];
+ });
+ if (retired.length) {
+ for (const n of retired) (result.retired ??= []).push(`${item.slug}/${dirId}/clips/${n}`);
+ log(
+ ` ⏱ ${item.slug}/${dirId}: ${retired.length} window(s) cut on another clock (a remote seek, or before the map) ` +
+ `retired: ${retired.join(", ")} — cut again from the saved video on the cue clock.`,
+ );
+ }
+ return r.clock;
+ };
+
// A whole download that failed this run, by video dir: the video's other
// windows fail with its message, without a second attempt.
const wholeFailed = new Map<string, { message: string; failureClass: FetchWindowsFailureClass }>();
@@ -661,6 +771,11 @@ export async function fetchWindows({
});
const videoDir = path.join(paths.channelsDir, item.slug, "data", dirId);
+ // ONE CLOCK PER RECORDING: a whole-recording channel's saved video has its
+ // time map before anything is answered from its windows or cut from it.
+ const clockWanted = wholeRecordingFor(settings, channelConfigPlatform(config) ?? "", item, wholeRecording);
+ const clock = clockWanted ? await clockOf(item, label, videoDir, dirId) : null;
+
// THE CACHE FIRST, here rather than only inside fetchWindowManaged, so a
// cached window owes no pause and is not counted as a network attempt —
// and IN SYNC (the header): a desynced held window is set aside here, and
@@ -676,7 +791,18 @@ export async function fetchWindows({
progress();
continue;
}
- const { hit, desynced } = held;
+ const { desynced } = held;
+ let hit = held.hit;
+ // A held window cut on another clock than the recording's map is not this
+ // span's seconds: retired, and the span cut again below.
+ if (hit && clock && hit.provenance?.clock?.id !== clock.id) {
+ const retired = await deps
+ .retireOffClock({ paths, slug: item.slug, dirId, videoDir, clockId: clock.id })
+ .catch(() => [] as string[]);
+ for (const n of retired) (result.retired ??= []).push(`${item.slug}/${dirId}/clips/${n}`);
+ log(` ⏱ ${label}: clips/${hit.file} was cut on another clock — retired; cut again on the cue clock.`);
+ hit = null;
+ }
for (const d of desynced) {
result.setAside.push(`${item.slug}/${dirId}/clips/${d.setAsideAs}`);
log(
@@ -895,6 +1021,8 @@ export async function fetchWindows({
result.saved.push(`${item.slug}/${item.id}`);
const clean = await deps.recordClean(platform, paths).catch(() => null);
if (clean) log(clean);
+ // The map from the cues' clock onto the container just saved.
+ await clockOf(item, label, videoDir, dirId);
const after = await deps.savedWindowSource({
paths,
slug: item.slug,
diff --git a/common/lib/recordingClock-server.ts b/common/lib/recordingClock-server.ts
@@ -368,3 +368,26 @@ export async function ensureRecordingClock(opts: {
const clock = await measureRecordingClock({ ...opts, ...plan });
return { clock, measured: true, plan: plan.kind };
}
+
+/**
+ * May a held window of this video answer for a cue span? Not when the
+ * recording's map is due (measured on the next fetch-windows run: every window
+ * there is on another clock) and not when it was cut through another map than
+ * the current one. A video no map applies to: yes, as ever.
+ */
+export async function heldWindowOnClock(
+ videoDir: string,
+ provenance: { clock?: { id: string } } | null | undefined,
+): Promise<boolean> {
+ let plan: ClockPlan;
+ try {
+ plan = await planRecordingClock(videoDir);
+ } catch {
+ // A file the plan could not stat (a drive not answering): the cut path's
+ // own guards say so; the cache answers as before.
+ return true;
+ }
+ if (plan.kind === "measure") return false;
+ if (plan.kind === "current") return provenance?.clock?.id === plan.clock.id;
+ return true;
+}
diff --git a/editor/app/channels/[slug]/videos/[id]/videoActions.ts b/editor/app/channels/[slug]/videos/[id]/videoActions.ts
@@ -115,7 +115,7 @@ import {
type StoredUrlWhy,
} from "yt-dlp-transcript-common/lib/storedMediaUrl";
import { storedMediaUrl } from "yt-dlp-transcript-common/lib/storedMediaUrl-server";
-import { CLIP_WINDOW_MIN_GAP_SECONDS } from "yt-dlp-transcript-common/controller/fetchWindows";
+import { CLIP_WINDOW_MIN_GAP_SECONDS, wholeRecordingFor } from "yt-dlp-transcript-common/controller/fetchWindows";
import { probeVideoHeight } from "yt-dlp-transcript-common/ytdlp/ffprobeDuration";
import { detectPlatform } from "yt-dlp-transcript-common/lib/platform";
import { channelConfigPlatform } from "yt-dlp-transcript-common/lib/videoId";
@@ -127,6 +127,7 @@ import {
recordDownloadBackoff,
} from "yt-dlp-transcript-common/jobs/downloadBackoff";
import { getSettings } from "yt-dlp-transcript-common/lib/settings";
+import { heldWindowOnClock } from "yt-dlp-transcript-common/lib/recordingClock-server";
import { resolveCookiePolicy } from "yt-dlp-transcript-common/lib/cookiePolicy";
import {
downloadOneManaged,
@@ -1600,7 +1601,15 @@ export async function fetchWindowAction(req: {
const { hit } = await findInSyncContainingClipWindow(videoDir, from, to, {
probe: ffprobeWindowProbe(paths.ffprobeBin),
});
- if (hit) {
+ // ONE CLOCK PER RECORDING (controller/fetchWindows.ts): a whole-recording
+ // channel's held window answers only when cut through the video's current
+ // time map; an off-clock one is passed over (the next fetch-windows run
+ // retires it) and the span is cut from the saved container below.
+ const clocked =
+ hit &&
+ wholeRecordingFor(getSettings(), channelConfigPlatform(r.config) ?? "", {}, undefined) &&
+ !(await heldWindowOnClock(videoDir, hit.provenance));
+ if (hit && !clocked) {
// The window's own height, read off its header: a window holds seconds,
// so the probe is quick, and it is the only record of how tall a window
// fetched under an earlier cap is.
diff --git a/editor/app/channels/[slug]/videos/fetchWindowsAction.ts b/editor/app/channels/[slug]/videos/fetchWindowsAction.ts
@@ -24,6 +24,7 @@ import {
} from "yt-dlp-transcript-common/lib/clipWindowSync-server";
import { sourceGoneState } from "yt-dlp-transcript-common/lib/sourceGone-server";
import { savedWindowSource } from "yt-dlp-transcript-common/lib/savedVideoWindow-server";
+import { heldWindowOnClock } from "yt-dlp-transcript-common/lib/recordingClock-server";
import type { ChannelConfig } from "yt-dlp-transcript-common/lib/channelConfig";
import {
isValidChannelSlug,
@@ -229,7 +230,12 @@ async function planFetchWindows(
probe: ffprobeWindowProbe(paths.ffprobeBin),
setAside: false,
});
- if (held.hit) {
+ // ONE CLOCK PER RECORDING (controller/fetchWindows.ts): a whole-recording
+ // channel's held window answers only when it was cut through the video's
+ // current time map; otherwise the span goes on (to the saved container,
+ // whose job measures the map and retires the off-clock window).
+ const clockedChannel = wholeRecordingFor(settings, channelConfigPlatform(config) ?? "", item, wholeRecording);
+ if (held.hit && (!clockedChannel || (await heldWindowOnClock(videoDir, held.hit.provenance)))) {
cached.push(item);
continue;
}