Archilyzer · Source

archilyzer

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

commit 2ea0d40e544345f33cfc9e19768890482b4f876e
parent d712996aca66ec014bf9f3d95154c1fba7c8f08d
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Fri, 13 Nov 2026 19:20:05 -0500

Taller clip windows, re-review fixes: a tall refetch fetches, ultrawide converges, the ladder in umtool

- umtool fetch --refetch marks its items `refetch: true` (route, spec and
  replay carry it): on a tall ask a lower held window does not answer
  them — they are cut again at their tier from the saved copy, or, with
  none, fetched at their tier on the platform's queue. The planner plans
  them the same way.
- tallerFromSaved compares against the saved copy's picture fitted in the
  cap's box (fittedHeight), not min(cap, height): an ultrawide copy is cut
  tall once, and the next ask is a plain hit ("best"), never a re-cut or a
  `lower` line. The pointer's height stays an early "lower" exit only.
- umtool's tall resolve snaps its cap to the editor's rungs (1080, 1440,
  2160): a project asking 900 or 1200 reads the .h1080 / .h1440 window.
- A plain window is cut from a tiered one only when that window passes
  the sync check (a desynced one is set aside and the plain ask goes on
  without it); a failed cut fails the item as cut-failed, never a fetch.
- fetch-via-editor refuses --max-height above 720 on a project without
  render.tallWindows, naming `umtool look <p> tallWindows=true`.
- Docs: a take with no saved base renders tall once the knob is on; a 720
  window derived from a tiered one may serve a site's evidence.

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

Diffstat:
MOPERATING.md | 15++++++++++-----
Mcommon/controller/fetchWindows.ts | 36+++++++++++++++++++++++++++++++++---
Mcommon/controller/fetchWindowsTier.test.ts | 60+++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
Mcommon/lib/clipWindowSync-server.ts | 25+++++++++++++++++++++++++
Mcommon/lib/clipWindowTier-server.ts | 16+++++++++++++---
Mcommon/lib/evidenceClip.mjs | 11++++++++++-
Mcommon/lib/savedVideoWindow-server.test.ts | 23+++++++++++++++++++++++
Meditor/app/api/ops/fetch-windows/route.ts | 9++++++++-
Meditor/app/channels/[slug]/videos/[id]/videoActions.ts | 20+++++++++++++++-----
Meditor/app/channels/[slug]/videos/fetchWindowsAction.ts | 21+++++++++++++++++----
Meditor/app/channels/[slug]/videos/fetchWindowsTier.test.ts | 21++++++++++++++-------
Meditor/app/jobs/jobReplayRegistry.ts | 2++
Mumtool/docs/knobs.md | 4+++-
Mumtool/docs/report-video.md | 11++++++++---
Mumtool/lib/report/fetchCli.mjs | 4++++
Mumtool/lib/report/fetchWindows.mjs | 19+++++++++++++++++--
Mumtool/lib/report/tallWindows.test.mjs | 17++++++++++++++++-
Mumtool/report-to-video/fetch-via-editor.mjs | 9+++++++++
Mumtool/report-to-video/fetch-via-editor.test.mjs | 16++++++++++++++++
Mumtool/report-to-video/sources.test.mjs | 25+++++++++++++++++++++++++
20 files changed, 325 insertions(+), 39 deletions(-)

diff --git a/OPERATING.md b/OPERATING.md @@ -808,14 +808,19 @@ pnpm ops reports-export --json '{"siteId":"example-site","formats":["html","md" while render mode holds the machine, and says so in the job log. A single fetch-window answers with what there is now instead, and says why. - With no taller saved copy, the lower window is used as it is. The answer lists it under `"lower"` (fetch-window - and `fetch_clip`: `belowAsked`) with its height and why. Nothing fetches a taller one from the network over it; - persist the video (`persist-videos`) to give it a copy to cut from. - - `umtool fetch --refetch` on a tall project evicts only the taller windows of the span, then cuts them again; the - 720 window stays. Without `render.tallWindows` a refetch evicts the 720 windows only, as before. + and `fetch_clip`: `belowAsked`) with its height and why. Only a refetch fetches a taller one from the network over + it; persisting the video (`persist-videos`) gives it a copy to cut from. + - `umtool fetch --refetch` on a tall project evicts only the taller windows of the span, then cuts them again from + the saved copy, or fetches them at their tier; the 720 window stays. Without `render.tallWindows` a refetch evicts + the 720 windows only, as before. - Heights are recorded only for taller windows, and for a 720 window the first time a tall ask needs it (one probe, written to its sidecar). A saved copy with no recorded height gets the height that probe found (`probed.height`). - A 720 ask that misses, over a span a taller window holds, is cut from that window (the 1280×720 box; its sidecar - says `source: "clip-window"`, `derivedFrom`), never fetched. + says `source: "clip-window"`, `derivedFrom`), never fetched. Only a taller window that passes the sync check is + used; a failed cut fails the item. That 720 window may later serve as a site's evidence: a further encode of the + same seconds. + - A refetch marks its items (`"refetch": true`): a lower held window does not answer them. They are cut again at + their tier from the saved copy, or, with none, fetched at their tier on the platform's own queue. - `evict-clips` takes `"tiers": "plain" | "tiered"` (default both). The age-out, named and covering evictions and the clock retirement treat a taller window as a window of its span. `check-windows` checks the taller windows too. - A cited recording deleted or made private on its platform cannot be fetched from its page. `find-copy` (a site's diff --git a/common/controller/fetchWindows.ts b/common/controller/fetchWindows.ts @@ -23,6 +23,7 @@ import { assertChannelMediaReachable, assertChannelTextReadable } from "../lib/c import { detectPlatform } from "../lib/platform"; import { findInSyncContainingClipWindow, + findInSyncTieredWindowHolding, judgeClipWindow, probeWindowStreams, setAsideDesyncedWindow, @@ -36,7 +37,7 @@ 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, tieredWindowHolding } from "../lib/clipWindow-server"; +import { listClipWindows } from "../lib/clipWindow-server"; import { evictClipWindows } from "./evictClipWindows"; import { cutPlainFromTieredWindow, @@ -241,6 +242,11 @@ export type FetchWindowsItem = { // is gone (a stale reading: made public again, a geo block read as removed). // The editor's door refuses a gone recording's window without it. force?: boolean; + // A REFETCH (umtool fetch --refetch, after it evicted the span's taller + // windows): on a tall ask a LOWER held window does not answer it — it is + // cut again at its tier from the saved copy, or, with none, fetched at its + // tier on the platform's own queue. No effect on a plain ask. + refetch?: boolean; }; export type FetchWindowsFailureClass = @@ -904,6 +910,11 @@ export async function fetchWindows({ `${d.setAsideAs}, and the span is fetched again.`, ); } + // A refetch is not answered by a lower window (the evicted tier is wanted). + if (hit && tier !== undefined && item.refetch && (hit.height ?? 0) < tier) { + log(` ${label}: a refetch — clips/${hit.file} (${hit.height ?? "?"}p) does not answer it; cut or fetched again at ${tier}p.`); + hit = null; + } if (hit && tier !== undefined && (hit.height ?? 0) < tier) { // A TALL ASK OVER A LOWER WINDOW: a taller cut beside it from the saved // copy when that is taller; else the window as it is, and why. Never a @@ -924,6 +935,14 @@ export async function fetchWindows({ progress(); continue; } + if (t.kind === "best") { + // As tall as the saved copy gives in the tier's box: an ordinary hit. + result.cached.push(item); + log(` = ${label}: cached in clips/${hit.file} (${t.height}p, all the saved copy gives at ${tier}p)`); + done += 1; + progress(); + continue; + } (result.lower ??= []).push({ item, file: hit.file, height: hit.height ?? null, asked: tier, why: t.why }); result.cached.push(item); log( @@ -969,7 +988,14 @@ export async function fetchWindows({ // nothing on disk changed but the new window. A cut that fails goes on to // the network as before. if (tier === undefined) { - const tiered = await tieredWindowHolding(videoDir, item.from, item.to); + // Only a tiered window that is in sync (judged as any window in use; a + // desynced one is set aside and the plain ask goes on without it). + const t = await findInSyncTieredWindowHolding(videoDir, item.from, item.to, { probe }).catch(() => ({ hit: null, desynced: [] })); + for (const d of t.desynced) { + result.setAside.push(`${item.slug}/${dirId}/clips/${d.setAsideAs}`); + log(` ! ${label}: clips/${d.window.file} — ${windowSyncLagText(d.sync)}; set aside as ${d.setAsideAs}.`); + } + const tiered = t.hit; if (tiered) { try { const cut = await deps.cutPlainFromTiered({ @@ -994,7 +1020,11 @@ export async function fetchWindows({ progress(); continue; } catch (e) { - log(` ${label}: cutting it from clips/${tiered.file} failed (${(e as Error).message}) — fetching it instead.`); + // As a failed cut from a saved copy: the item fails, nothing is fetched. + fail(item, "cut-failed", `cutting it from clips/${tiered.file} failed: ${(e as Error).message}`); + done += 1; + progress(); + continue; } } } diff --git a/common/controller/fetchWindowsTier.test.ts b/common/controller/fetchWindowsTier.test.ts @@ -289,13 +289,16 @@ test("a plain ask that misses, over a span a tiered window holds, is cut from th assert.equal(h.fetches.length, 0); assert.equal(r.cut.length, 1); assert.match(lines.join(""), /cut from clips\/0\.00-30\.00\.h1080\.mp4 into clips\/10\.00-20\.00\.mp4/); - // A cut that fails goes to the network, as before. + // A cut that fails fails the item, as a saved-copy cut does: nothing is fetched. + await rm(path.join(clips, "10.00-20.00.mp4"), { force: true }); const bad = harness(); bad.deps.cutPlainFromTiered = async () => { throw new Error("ffmpeg refused"); }; - await run(paths, bad.deps); - assert.equal(bad.fetches.length, 1); + const failed = await run(paths, bad.deps); + assert.equal(bad.fetches.length, 0); + assert.equal(failed.failed[0]?.class, "cut-failed"); + assert.match(failed.failed[0]?.message ?? "", /cutting it from clips\/0\.00-30\.00\.h1080\.mp4 failed: ffmpeg refused/); }); }); @@ -320,3 +323,54 @@ test("a tall cut from the saved copy waits out render mode, and says so", async assert.equal(plain.cuts.length, 1); }); }); + +// 4: a tiered window that is not in sync is no source: set aside, and the plain +// ask goes on as if it were not there (here: the network). +test("a desynced tiered window is set aside, not cut from; the plain ask is fetched", async () => { + await withCorpus(async ({ paths, clips }) => { + await writeFile(path.join(clips, "0.00-30.00.h1080.mp4"), "taller"); + await writeFile(path.join(clips, "0.00-30.00.h1080.json"), JSON.stringify({ requestedBy: "umtool", height: 1080 })); + const h = harness(); + h.deps.probeWindow = async () => [ + { codec_type: "video", start_time: "3.200000", duration: "93.733000" }, + { codec_type: "audio", start_time: "3.140000", duration: "90.580000" }, + ]; + const r = await run(paths, h.deps); + assert.deepEqual(h.derived, []); + assert.equal(h.fetches.length, 1); + assert.equal(h.fetches[0].tier, undefined); + assert.deepEqual(r.setAside, ["c/v1/clips/0.00-30.00.h1080.desynced.mp4"]); + assert.ok((await readdir(clips)).includes("0.00-30.00.h1080.desynced.mp4")); + }); +}); + +// 1: a REFETCH on a tall ask is not answered by the lower 720 window. +test("a tall refetch over a 720 window: cut at its tier from the saved copy; with none, fetched at its tier", async () => { + await withCorpus(async ({ paths, videoDir, clips }) => { + await plainWindow(clips, 720); + const refetch: FetchWindowsItem = { ...item, refetch: true }; + // No saved copy: the network, at the tier. + const h = harness(); + const lines: string[] = []; + const r = await fetchWindows({ paths, items: [refetch], provenance: { requestedBy: "umtool" }, maxHeight: 1080, gapMs: 0, onLog: (l) => lines.push(l), deps: h.deps }); + assert.equal(r.cached.length, 0); + assert.equal(r.lower, undefined); + assert.equal(h.fetches.length, 1); + assert.equal(h.fetches[0].tier, 1080); + assert.match(lines.join(""), /a refetch — clips\/10\.00-20\.00\.mp4 \(720p\) does not answer it/); + // A saved copy (even one no taller): cut again at the tier from it. + await writeFile( + path.join(videoDir, "saved-video.json"), + JSON.stringify({ storedAt: "", dir: "/s", file: "source-media.mp4", bytes: 1, format: { preset: "original", height: 720 } }), + ); + const s = harness({ saved: covers(720) }); + await fetchWindows({ paths, items: [refetch], provenance: { requestedBy: "umtool" }, maxHeight: 1080, gapMs: 0, deps: s.deps }); + assert.deepEqual(s.cuts, [{ maxHeight: 1080, from: 10, to: 20 }]); + assert.equal(s.fetches.length, 0); + // Without the flag the same ask is the 720 window, listed lower. + const plain = harness({ saved: covers(720) }); + const p = await run(paths, plain.deps, 1080); + assert.equal(p.cached.length, 1); + assert.equal(plain.cuts.length, 0); + }); +}); diff --git a/common/lib/clipWindowSync-server.ts b/common/lib/clipWindowSync-server.ts @@ -199,3 +199,28 @@ export async function findInSyncContainingClipWindow( } return { hit: null, desynced }; } + +// THE TIERED WINDOW A PLAIN MISS MAY BE CUT FROM (the height tier, D) — only +// one that is in sync, judged exactly as a window is when it is used: the +// tiered windows holding [from, to], tightest first (lowest tier of equals); +// a desynced one is set aside as usual (unless `setAside: false`, a planner) +// and the next asked; none left is null — the plain ask goes on as if there +// were no tiered window at all. +export async function findInSyncTieredWindowHolding( + videoDir: string, + from: number, + to: number, + opts: { probe: WindowStreamProbe; setAside?: boolean; record?: boolean }, +): Promise<{ hit: ClipWindow | null; desynced: DesyncedClipWindow[] }> { + const candidates = (await listClipWindows(videoDir, { tiers: true })) + .filter((w) => w.tier !== undefined && clipWindowContains(w, from, to)) + .sort((a, b) => a.to - a.from - (b.to - b.from) || (a.tier ?? 0) - (b.tier ?? 0)); + const desynced: DesyncedClipWindow[] = []; + for (const w of candidates) { + const { sync } = await judgeClipWindow(w, { probe: opts.probe, record: opts.record }); + if (!sync || sync.ok) return { hit: w, desynced }; + const aside = opts.setAside === false ? null : await setAsideDesyncedWindow(w, sync); + desynced.push({ window: w, sync, setAsideAs: aside?.file ?? null }); + } + return { hit: null, desynced }; +} diff --git a/common/lib/clipWindowTier-server.ts b/common/lib/clipWindowTier-server.ts @@ -18,14 +18,19 @@ import type { Paths } from "./paths"; import { loadSavedVideo, recordSavedVideoProbedHeight } from "./savedVideo-server"; import { savedWindowSource, type SavedWindowSource } from "./savedVideoWindow-server"; +import { fittedHeight } from "./evidenceClip-server"; export type TallerFromSaved = | { kind: "cut"; source: Extract<SavedWindowSource, { kind: "covers" }>; height: number } + // The window is already as tall as the saved copy gives inside the cap's + // box (an ultrawide source fits a 1080 box at 810): nothing to cut, and not + // "lower" in any way a cut could fix. + | { kind: "best"; height: number } | { kind: "lower"; why: string }; export const NO_SAVED_COPY_WHY = "no saved copy of the recording to cut a taller one from — the lower window is used as it is; " + - "persist the video (persist-videos) to give it one"; + "persist the video (persist-videos) to give it one, or refetch it (umtool fetch --refetch) to fetch it taller"; export async function tallerFromSaved(opts: { paths: Pick<Paths, "transcriptsDir" | "savedVideosDir" | "ffprobeBin">; @@ -68,9 +73,14 @@ export async function tallerFromSaved(opts: { if (recorded === undefined && source.probe.height) { await recordSavedVideoProbedHeight(opts.videoDir, pointer.file, source.probe.height).catch(() => false); } - const best = Math.min(opts.cap, savedHeight); + // WHAT A CUT WOULD BE: the copy's picture fitted inside the cap's 16:9 box + // (the cut's own arithmetic) — not min(cap, height), which an ultrawide copy + // never reaches, so it would be cut again on every ask. + const best = fittedHeight(source.probe.width, source.probe.height, opts.cap) ?? Math.min(opts.cap, savedHeight); if (best <= have) { - return { kind: "lower", why: `the saved copy is ${savedHeight}p, no taller than the window` }; + return have >= best && opts.hitHeight !== null + ? { kind: "best", height: best } + : { kind: "lower", why: `the saved copy gives ${best}p in the ${opts.cap}p box, no taller than the window` }; } return { kind: "cut", source, height: best }; } diff --git a/common/lib/evidenceClip.mjs b/common/lib/evidenceClip.mjs @@ -69,6 +69,15 @@ const TIERED_RE = /^(\d+(?:\.\d+)?)-(\d+(?:\.\d+)?)\.h(\d{3,4})$/; /** Is `maxHeight` a tall ask (above the plain 720)? */ export const isTallAsk = (maxHeight) => Number.isFinite(maxHeight) && maxHeight > PLAIN_WINDOW_MAX_HEIGHT; +// THE LADDER the editor snaps a tall ask to (lib/clipWindow.ts +// WINDOW_TIER_RUNGS): an ask of 900 or 1000 is the 1080 file, 1200 the 1440. +// A tall resolve takes the rung as its cap, so the editor's `.h1080` window is +// what a project asking 900 gets, not "too tall". +export const WINDOW_TIER_RUNGS = Object.freeze([1080, 1440, 2160]); + +/** The rung a tall ask snaps to (the editor's tier before its setting holds it). */ +export const tierRungOf = (maxHeight) => WINDOW_TIER_RUNGS.find((r) => r >= maxHeight) ?? 2160; + /** * A directory listing, or [] for a directory that is not there. * @param {string} dir @@ -522,7 +531,7 @@ async function heightOfWindow(ctx, kind, w) { * @returns {Promise<LocalSource | null>} */ async function tallResolve(tiers, ctx, from, to, { allow, preferName }) { - const cap = Number(ctx.maxHeight); + const cap = tierRungOf(Number(ctx.maxHeight)); /** @type {{ tier: SourceTier, w: SourceWindow, h: number }[]} */ const best = []; for (const tier of tiers) { diff --git a/common/lib/savedVideoWindow-server.test.ts b/common/lib/savedVideoWindow-server.test.ts @@ -363,3 +363,26 @@ test("recordSavedVideoProbedHeight writes probed.height once, only for the file const raw = JSON.parse(await readFile(path.join(c.videoDir, "saved-video.json"), "utf8")); assert.equal(raw.origin.kind, "local-archive", "every other key kept"); }); + +// 2: an ULTRAWIDE saved copy fits the 1080 box at 810 — the tall cut is made +// once; the next ask finds it as tall as the copy gives and cuts nothing. +test("an ultrawide saved copy is cut tall once; the second tall ask cuts nothing", async () => { + const { tallerFromSaved } = await import("./clipWindowTier-server"); + const { listClipWindows } = await import("./clipWindow-server"); + const uw = path.join(ROOT, "fixtures", "ultrawide.mp4"); + ff(["-f", "lavfi", "-i", "testsrc=size=2560x1080:rate=5:duration=8", "-c:v", "libx264", "-preset", "ultrafast", "-pix_fmt", "yuv420p", uw]); + const c = await corpus(uw); + const ask = (hitHeight: number | null) => + tallerFromSaved({ paths: c.paths, slug: SLUG, videoDir: c.videoDir, from: 2, to: 5, hitHeight, cap: 1080 }); + // The 720 window of it is 540 tall. + const first = await ask(540); + assert.equal(first.kind, "cut"); + if (first.kind !== "cut") return; + assert.equal(first.height, 810); + const tall = await cutSavedVideoWindow({ paths: c.paths, videoDir: c.videoDir, source: first.source, from: 2, to: 5, provenance: { requestedBy: "umtool" }, tier: 1080 }); + assert.equal(tall.height, 810); + assert.equal((await probeMedia(tall.path, "ffprobe"))?.height, 810); + const second = await ask(tall.height ?? null); + assert.deepEqual(second, { kind: "best", height: 810 }); + assert.equal((await listClipWindows(c.videoDir, { tiers: true })).length, 1); +}); diff --git a/editor/app/api/ops/fetch-windows/route.ts b/editor/app/api/ops/fetch-windows/route.ts @@ -95,7 +95,7 @@ export const dynamic = "force-dynamic"; // // A big list goes in a file: `pnpm ops fetch-windows --file list.json`. -const ITEM_KEYS = ["slug", "id", "from", "to", "clipId", "reason", "pad", "webpageUrl", "force"]; +const ITEM_KEYS = ["slug", "id", "from", "to", "clipId", "reason", "pad", "webpageUrl", "force", "refetch"]; function optItemString(e: OpsBody, key: string, where: string): string | undefined { const v = e[key]; @@ -104,6 +104,11 @@ function optItemString(e: OpsBody, key: string, where: string): string | undefin return v.trim() || undefined; } +function reqItemBool(v: unknown, where: string, key: string): boolean { + if (typeof v !== "boolean") throw new OpsInputError(`"${where}.${key}" must be a boolean`); + return v; +} + function reqItemForce(v: unknown, where: string): boolean { if (typeof v !== "boolean") throw new OpsInputError(`"${where}.force" must be a boolean`); return v; @@ -161,6 +166,8 @@ function reqWindowItems(body: OpsBody): FetchWindowsItem[] { ...(typeof pad === "number" ? { pad } : {}), webpageUrl: optItemString(e, "webpageUrl", where), ...(e.force !== undefined ? { force: reqItemForce(e.force, where) } : {}), + // A refetch (umtool fetch --refetch): a lower held window does not answer it. + ...(e.refetch !== undefined ? { refetch: reqItemBool(e.refetch, where, "refetch") } : {}), }; }); } diff --git a/editor/app/channels/[slug]/videos/[id]/videoActions.ts b/editor/app/channels/[slug]/videos/[id]/videoActions.ts @@ -99,13 +99,14 @@ import { windowTierOf, type ClipProvenance, } from "yt-dlp-transcript-common/lib/clipWindow"; -import { clipWindowPath, tieredWindowHolding, windowHeightOf } from "yt-dlp-transcript-common/lib/clipWindow-server"; +import { clipWindowPath, windowHeightOf } from "yt-dlp-transcript-common/lib/clipWindow-server"; import { windowMaxHeightOf } from "yt-dlp-transcript-common/lib/clipSettings"; import { tallerFromSaved } from "yt-dlp-transcript-common/lib/clipWindowTier-server"; import { renderModeHeldNow } from "yt-dlp-transcript-common/lib/renderHold"; import { ffprobeWindowProbe, findInSyncContainingClipWindow, + findInSyncTieredWindowHolding, judgeClipWindow, setAsideDesyncedWindow, } from "yt-dlp-transcript-common/lib/clipWindowSync-server"; @@ -1685,7 +1686,8 @@ export async function fetchWindowAction(req: { if (hit && !clocked && tier !== undefined && (hit.height ?? 0) < tier) { const t = await tallerFromSaved({ paths, slug, videoDir, from, to, hitHeight: hit.height ?? null, cap: tier }); if (t.kind === "cut" && !renderWhy) taller = t; - else belowAsked = { asked: tier, why: t.kind === "cut" ? renderWhy! : t.why }; + else if (t.kind === "cut") belowAsked = { asked: tier, why: renderWhy! }; + else if (t.kind === "lower") belowAsked = { asked: tier, why: t.why }; } if (hit && !clocked && !taller) { // The window's own height. A tall ask reads its sidecar's record, else @@ -1789,10 +1791,17 @@ export async function fetchWindowAction(req: { // the tiered file — nothing fetched, nothing on disk changed but the new // window. A cut that fails goes on to the network as before. if (tier === undefined) { - const tiered = await tieredWindowHolding(videoDir, from, to); + // Only an in-sync tiered window (a desynced one is set aside, as any). + const { hit: tiered } = await findInSyncTieredWindowHolding(videoDir, from, to, { + probe: ffprobeWindowProbe(paths.ffprobeBin), + }); if (tiered) { try { await assertChannelTextReadable(paths, slug); + } catch (e) { + return { ok: false, status: 503, error: (e as Error).message }; + } + try { const cut = await cutPlainFromTieredWindow({ paths, videoDir, tiered, from, to, provenance: req.provenance }); safeRevalidate([`/channels/${slug}/videos/${videoId}`]); return { @@ -1805,8 +1814,9 @@ export async function fetchWindowAction(req: { provenance: cut.provenance, ...clamped, }; - } catch { - // The network, as before the tier. + } catch (e) { + // As a failed cut from a saved copy: refused, never a fetch instead. + return { ok: false, status: 500, error: (e as Error).message }; } } } diff --git a/editor/app/channels/[slug]/videos/fetchWindowsAction.ts b/editor/app/channels/[slug]/videos/fetchWindowsAction.ts @@ -25,11 +25,11 @@ import { } from "yt-dlp-transcript-common/lib/clipWindow"; import { windowMaxHeightOf } from "yt-dlp-transcript-common/lib/clipSettings"; import { tallerFromSaved } from "yt-dlp-transcript-common/lib/clipWindowTier-server"; -import { tieredWindowHolding } from "yt-dlp-transcript-common/lib/clipWindow-server"; import { probeVideoHeight } from "yt-dlp-transcript-common/ytdlp/ffprobeDuration"; import { ffprobeWindowProbe, findInSyncContainingClipWindow, + findInSyncTieredWindowHolding, } 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"; @@ -320,7 +320,10 @@ async function planFetchWindows( // 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)))) { + // A REFETCH on a tall ask is not answered by a lower window: planned on to + // the saved copy (a cut at its tier) or, with none, its platform's queue. + const refetchPast = tier !== undefined && item.refetch === true && (held.hit?.height ?? 0) < tier; + if (held.hit && !refetchPast && (!clockedChannel || (await heldWindowOnClock(videoDir, held.hit.provenance)))) { const hitHeight = held.hit.height ?? null; if (tier !== undefined && (hitHeight ?? 0) < tier) { // Lower than asked: a taller cut from the saved copy when it is @@ -333,7 +336,7 @@ async function planFetchWindows( groups.set(queueKey, group); continue; } - lower.push({ item, file: held.hit.file, height: hitHeight, asked: tier, why: t.why }); + if (t.kind === "lower") lower.push({ item, file: held.hit.file, height: hitHeight, asked: tier, why: t.why }); } cached.push(item); continue; @@ -365,7 +368,17 @@ async function planFetchWindows( // ...or, on a plain ask, a taller (tiered) window of the span: the job // cuts the 720 window from it locally (the height tier, D), on the same // queue no platform shares. - if (saved.kind === "covers" || (tier === undefined && (await tieredWindowHolding(videoDir, item.from, item.to)))) { + if ( + saved.kind === "covers" || + (tier === undefined && + ( + await findInSyncTieredWindowHolding(videoDir, item.from, item.to, { + probe: ffprobeWindowProbe(paths.ffprobeBin), + setAside: false, + record: false, + }) + ).hit) + ) { const queueKey = resolveQueueKey(SAVED_VIDEO_CLIP_QUEUE, queueOverride); const group = groups.get(queueKey) ?? { platform: SAVED_VIDEO_CLIP_PLATFORM, diff --git a/editor/app/channels/[slug]/videos/fetchWindowsTier.test.ts b/editor/app/channels/[slug]/videos/fetchWindowsTier.test.ts @@ -61,7 +61,7 @@ const items = [ { slug: SLUG, id: "equal1", from: 1, to: 3, clipId: "c#2" }, ]; -test("a tall ask plans a taller cut beside a window lower than the saved copy, and lists the one that cannot be taller", async () => { +test("a tall ask plans a taller cut beside a window lower than the saved copy; one as tall as the copy gives is a hit", async () => { const r = await fetchWindowsAction({ items, requestedBy: "umtool", maxHeight: 1080, dryRun: true }); assert.ok(r.ok); if (!r.ok) return; @@ -69,12 +69,9 @@ test("a tall ask plans a taller cut beside a window lower than the saved copy, a r.groups.map((g) => [g.platform, g.items.map((i) => i.clipId)]), [["saved-video", ["c#1"]]], ); + // 90p is all a 160×90 copy gives in the 1080 box: an ordinary hit, not "lower". assert.deepEqual(r.cached.map((i) => i.clipId), ["c#2"]); - assert.equal(r.lower?.length, 1); - assert.equal(r.lower![0].item.clipId, "c#2"); - assert.equal(r.lower![0].height, 90); - assert.equal(r.lower![0].asked, 1080); - assert.match(r.lower![0].why, /saved copy is 90p/); + assert.equal(r.lower, undefined); }); test("no ask plans as before: both held windows are cached, nothing listed lower", async () => { @@ -92,5 +89,15 @@ test("an ask above clips.windowMaxHeight is planned at the ceiling, and says so" assert.ok(r.ok); if (!r.ok) return; assert.equal(r.clampedFrom, 2160); - assert.equal(r.lower?.[0]?.asked, 1080); + assert.deepEqual(r.cached.map((i) => i.clipId), ["c#2"]); +}); + +test("a tall refetch is not answered by a held window: planned onto the saved copy's cut", async () => { + await writeFile(process.env.SETTINGS_FILE!, JSON.stringify({ minFreeDiskGB: 0 })); + const r = await fetchWindowsAction({ items: [{ ...items[1], refetch: true }], requestedBy: "umtool", maxHeight: 1080, dryRun: true }); + assert.ok(r.ok); + if (!r.ok) return; + assert.deepEqual(r.cached, []); + assert.deepEqual(r.groups.map((g) => [g.platform, g.items.map((i) => i.clipId)]), [["saved-video", ["c#2"]]]); + assert.equal(r.lower, undefined); }); diff --git a/editor/app/jobs/jobReplayRegistry.ts b/editor/app/jobs/jobReplayRegistry.ts @@ -126,6 +126,8 @@ function windowItems(v: unknown): FetchWindowsItem[] { webpageUrl: str(r.webpageUrl), // find-copy's copy (release 29 E2): a replay records it again. copy: coerceClipCopy(r.copy), + // A refetch stays one (the height tier). + ...(r.refetch === true ? { refetch: true } : {}), }); } return out; diff --git a/umtool/docs/knobs.md b/umtool/docs/knobs.md @@ -371,7 +371,9 @@ With it on, `umtool fetch` asks the editor for that height. The editor keeps the lower, with why. The build and every tool that checks its sources (quote-check, `--align`, scenes, cut points, the availability check, quick clip, the chain) read the cap from the manifest, so they all resolve the same file. `--refetch` evicts and re-cuts only the taller windows; the 720 window, which a site's evidence is cut from, stays. A -take records the knob with the rest of the look. +take records the knob with the rest of the look. A take with no saved base follows the project's current manifest, so +like any look key it renders tall once the knob is turned on. `fetch-via-editor --max-height` above 720 is refused on a +project without the knob. | | In umtool | From a terminal | Route | |---|---|---|---| diff --git a/umtool/docs/report-video.md b/umtool/docs/report-video.md @@ -3118,7 +3118,10 @@ one (`<from>-<to>.h<tier>.mp4`), cut from the saved copy when that copy is talle why — usually "no saved copy". The build, quote-check, `--align`, scenes, cut points, the availability check, quick clip and the chain all take the cap from the manifest's render, so they resolve the same file: a raw `out/clips-raw` file or a 720 corpus window gives way to a taller corpus window or to the saved copy. Neither is deleted. A raw -file's height is probed once and kept in `out/clips-raw.heights.json`. +file's height is probed once and kept in `out/clips-raw.heights.json`. A height between the editor's rungs +(1080, 1440, 2160) resolves as its rung, as the editor fetches it: a 900 project reads the `.h1080` window. A 720 +window the editor later cuts from a taller one (a site's plain ask) may serve as that site's evidence: a further +encode of the same seconds. A window on disk that is BAD (cut from a saved video that turned out corrupt) is a cache hit all the same, so a plain fetch keeps it. `umtool fetch <project> @@ -3126,8 +3129,10 @@ is a cache hit all the same, so a plain fetch keeps it. `umtool fetch <project> `from`–`to` the body asks for, pad included — goes to the editor's `evict-clips` as `{slug, id, covering: [{from, to}], tiers}`, which removes every cached window of that video OVERLAPPING the span — on a tall project only the taller (`.h<tier>`) -windows, which are then cut again from the saved copy, the 720 one left for the -sites; on any other only the 720 windows, as before (a wider window the dedup would have served it +windows, which are then cut again from the saved copy (or, with none, fetched +again at their height: the items carry `refetch: true`, so the 720 window does +not answer them), the 720 one left for the sites; on any other only the 720 +windows, as before (a wider window the dedup would have served it from included, and its `.desynced.*` twin), and only once that job has ended is the fetch asked. `--refetch-video <slug>/<id>` does the same for every window the project asks of one video. A window another project shares is evicted too: diff --git a/umtool/lib/report/fetchCli.mjs b/umtool/lib/report/fetchCli.mjs @@ -28,6 +28,7 @@ import { projectFetchBody, readFetchRuns, recordFetchRun, + markRefetched, refetchEvictions, refetchTiers, summarizeAnswer, @@ -178,6 +179,9 @@ export async function fetchCommand(args, { root = REPORTS_ROOT, out = (s) => con } const plan = refetchEvictions(body, skipped, { clipIds: refetchClips, videos }); if (!plan.ok) throw new CliError(plan.error); + // The refetched items say so (`refetch: true`): on a tall project a lower + // held window then does not answer them — cut again at their tier, or fetched. + markRefetched(body, plan.requests); refetch = []; for (const req of plan.requests) { const { jobId } = await postEvictClips(cfg, { ...req, tiers: refetchTiers(body) }, { dryRun }); diff --git a/umtool/lib/report/fetchWindows.mjs b/umtool/lib/report/fetchWindows.mjs @@ -130,8 +130,6 @@ export function fetchWindowsBody(manifest, { manifestPath, project, rulings = nu }; } - - // Twitch's record ids wear a `v` the directory does not: "v123" and "123" are one video. const sameVideo = (a, b) => String(a).replace(/^v(?=\d+$)/, "") === String(b).replace(/^v(?=\d+$)/, ""); @@ -308,6 +306,23 @@ export function postEvictClips(cfg, { slug, id, covering, tiers }, { dryRun = fa */ export const refetchTiers = (body) => (body?.maxHeight !== undefined ? "tiered" : "plain"); +/** + * Mark the body's items a refetch evicts for (`refetch: true`, in place): the + * items of each request's video whose span overlaps one it evicts. The editor + * then does not answer them with a lower held window on a tall project. + * @param {{ items: Record<string, any>[] }} body + * @param {{ slug: string, id: string, covering: { from: number, to: number }[] }[]} requests + */ +export function markRefetched(body, requests) { + for (const it of body.items) { + const hit = requests.some( + (r) => r.slug === it.slug && sameVideo(r.id, it.id) && r.covering.some((c) => c.from < it.to && it.from < c.to), + ); + if (hit) it.refetch = true; + } + return body; +} + // `evicting <slug>/<id>/<name> (…)` / `would evict …` — the line // common/controller/evictClipWindows.ts logs for each window. const EVICT_LINE = /^\s*(?:would evict|evicting) [^/\s]+\/[^/\s]+\/(\S+) /; diff --git a/umtool/lib/report/tallWindows.test.mjs b/umtool/lib/report/tallWindows.test.mjs @@ -13,7 +13,7 @@ import { fileURLToPath } from "node:url"; import { planQuoteCheck } from "./quoteCheck.mjs"; import { localSources } from "umtool-report-to-video/build-video"; import { rawWindowName, resolveLocalSource, tallWindowCap } from "umtool-report-to-video/sources"; -import { fetchWindowsBody, refetchTiers } from "./fetchWindows.mjs"; +import { fetchWindowsBody, markRefetched, refetchEvictions, refetchTiers } from "./fetchWindows.mjs"; const SLUG = "demo"; const VIDEO = "vid1"; @@ -141,3 +141,18 @@ test("every resolveLocalSource / localSources / corpusWindowsOf call site states } assert.deepEqual(missing, []); }); + +test("a refetch marks the items it evicts for (refetch: true), and only those", () => { + const manifest = { + ...manifestOf({ tallWindows: true, maxHeightSource: 1080 }), + timeline: [ + { type: "clip", id: "c1", video: VIDEO, start: 10, end: 20 }, + { type: "clip", id: "c2", video: VIDEO, start: 300, end: 310 }, + ], + }; + const { body, skipped } = fetchWindowsBody(manifest, { manifestPath: "/x/m.json", project: "p" }); + const plan = refetchEvictions(body, skipped, { clipIds: ["c1"] }); + assert.ok(plan.ok); + markRefetched(body, plan.requests); + assert.deepEqual(body.items.map((i) => [i.clipId, i.refetch === true]), [["c1", true], ["c2", false]]); +}); diff --git a/umtool/report-to-video/fetch-via-editor.mjs b/umtool/report-to-video/fetch-via-editor.mjs @@ -140,6 +140,15 @@ const whole = JSON.parse(await readFile(manifestPath, "utf8")); // clips.windowMaxHeight, and says when a clip stays lower. Without the knob no // height is sent, as before. A whole recording (--full) keeps --max-height alone. const windowMaxHeight = maxHeight ?? tallWindowCap(whole?.render); +// A window asked taller than 720 by hand, on a project that does not read +// taller windows: refused, rather than cut into a file its own build and checks +// would never resolve. +if (!wantFull && maxHeight !== undefined && maxHeight > 720 && tallWindowCap(whole?.render) === undefined) { + die( + `--max-height ${maxHeight} asks for a window taller than 720, but this project does not read taller windows: ` + + `turn them on with \`umtool look <p> tallWindows=true\` (render.tallWindows), or ask 720 or less`, + ); +} const provenance = whole.provenance ?? {}; const pad = Number(flag("--pad") ?? 3); diff --git a/umtool/report-to-video/fetch-via-editor.test.mjs b/umtool/report-to-video/fetch-via-editor.test.mjs @@ -408,3 +408,19 @@ test("a Rumble clip whose whole-recording fetch fails: exit 1, and still no seek await rm(c.root, { recursive: true, force: true }); } }); + +// A window asked above 720 on a project that does not read taller windows is +// refused, naming the knob, before any request. +test("--max-height above 720 without render.tallWindows is refused, naming the knob", async () => { + const ed = await stubEditor(CACHED(720)); + try { + const { code, events } = await run(ed.url, ["--max-height", "1080"]); + assert.notEqual(code, 0); + assert.equal(ed.posts.length, 0); + assert.ok(events.some((e) => e.ev === "note" && /umtool look <p> tallWindows=true/.test(e.message)), JSON.stringify(events)); + // 720 and under, and --full, are as before. + assert.equal((await run(ed.url, ["--max-height", "720"])).code, 0); + } finally { + await ed.close(); + } +}); diff --git a/umtool/report-to-video/sources.test.mjs b/umtool/report-to-video/sources.test.mjs @@ -664,3 +664,28 @@ test("a tall ask with only lower windows reaches for the saved copy when it is t await rm(t.root, { recursive: true, force: true }); } }); + +// The editor's LADDER (1080, 1440, 2160): a project asking 900 or 1200 reads +// the editor's `.h1080` / `.h1440` window as its rung, not as too tall. +test("a tall ask between rungs resolves the rung's window: 900 and 1000 read .h1080, 1200 reads .h1440", async () => { + const t = await tree(); + try { + await touch(path.join(t.clipsDir, "0.00-60.00.mp4")); + await writeFile(path.join(t.clipsDir, "0.00-60.00.json"), JSON.stringify({ height: 720 })); + await touch(path.join(t.clipsDir, "0.00-60.00.h1080.mp4")); + await writeFile(path.join(t.clipsDir, "0.00-60.00.h1080.json"), JSON.stringify({ height: 1080 })); + const want = { video: VIDEO, slug: SLUG, from: 10, to: 20 }; + for (const h of [900, 1000]) { + const hit = await resolveLocalSource(want, { channelsDir: t.channelsDir, probe: fakeProbe(600).probe, render: { tallWindows: true, maxHeightSource: h } }); + assert.equal(hit.name, "0.00-60.00.h1080.mp4", String(h)); + } + await touch(path.join(t.clipsDir, "0.00-60.00.h1440.mp4")); + await writeFile(path.join(t.clipsDir, "0.00-60.00.h1440.json"), JSON.stringify({ height: 1440 })); + const at1200 = await resolveLocalSource(want, { channelsDir: t.channelsDir, probe: fakeProbe(600).probe, render: { tallWindows: true, maxHeightSource: 1200 } }); + assert.equal(at1200.name, "0.00-60.00.h1440.mp4"); + const at1080 = await resolveLocalSource(want, { channelsDir: t.channelsDir, probe: fakeProbe(600).probe, render: TALL }); + assert.equal(at1080.name, "0.00-60.00.h1080.mp4"); + } finally { + await rm(t.root, { recursive: true, force: true }); + } +});