commit 686c8b290fa48a217b6ddd5db3031467c36c0016
parent 0d5d753ef58de675350a110a761e658a05ae112c
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Mon, 26 Oct 2026 08:00:42 -0400
transcribe-bucket: regenerate the report only when it is older than the channel's data; a stray id is still named after it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
3 files changed, 76 insertions(+), 7 deletions(-)
diff --git a/editor/app/api/ops/transcribe-bucket/route.test.ts b/editor/app/api/ops/transcribe-bucket/route.test.ts
@@ -1,6 +1,6 @@
import test from "node:test";
import assert from "node:assert/strict";
-import { mkdir, writeFile } from "node:fs/promises";
+import { mkdir, utimes, writeFile } from "node:fs/promises";
import path from "node:path";
import { setupOpsCorpus, callPost } from "../_testCorpus";
@@ -23,6 +23,8 @@ await writeFile(
path.join(CHANNEL, "snapshot.json"),
JSON.stringify({ generatedAt: "2026-10-26T01:10:00.000Z", totals: { videos: 0 }, buckets: { downloadedNoTranscript: [] } }),
);
+const past = new Date(Date.now() - 60 * 60 * 1000);
+await utimes(path.join(CHANNEL, "snapshot.json"), past, past);
// What the import landed since.
const dir = path.join(CHANNEL, "data", "imported0001");
await mkdir(dir, { recursive: true });
diff --git a/editor/app/api/ops/transcribe-bucket/route.ts b/editor/app/api/ops/transcribe-bucket/route.ts
@@ -1,3 +1,5 @@
+import path from "node:path";
+import { stat } from "node:fs/promises";
import { getPaths } from "yt-dlp-transcript-common/lib/paths";
import { channelExists, readChannelSnapshot } from "yt-dlp-transcript-common/controller/channels";
import {
@@ -37,9 +39,10 @@ export const dynamic = "force-dynamic";
// is the report's, and a report written before an import landed says "No
// video ids supplied" (an empty bucket) or "64 of ids not in the bucket" for
// audio that is right there. When the bucket is empty, or `ids` names videos
-// outside it, the route asks for the channel's report on the refresh-report
-// queue, waits for it (REGEN_WAIT_MS), and reads the bucket again; a report
-// still regenerating when the wait runs out is said, with its job id.
+// outside it, and the report is older than the channel's data (reportBehindDisk),
+// the route asks for the channel's report on the refresh-report queue, waits
+// for it (REGEN_WAIT_MS), and reads the bucket again; a report still
+// regenerating when the wait runs out is said, with its job id.
const REGEN_WAIT_MS = 90_000;
function bucketMisses(bucketIds: readonly string[], ids: unknown): boolean {
@@ -49,6 +52,27 @@ function bucketMisses(bucketIds: readonly string[], ids: unknown): boolean {
return ids.some((id) => typeof id === "string" && !known.has(id));
}
+const mtimeOf = (p: string) => stat(p).then((s) => s.mtimeMs, () => null);
+
+// Is the report OLDER than what it reports on? A new video dir moves `data/`'s
+// mtime; audio landing in a named video's dir moves that dir's. A report
+// written after both is current, and its answer stands.
+async function reportBehindDisk(channelDir: string, ids: unknown): Promise<boolean> {
+ const report = await mtimeOf(path.join(channelDir, "snapshot.json"));
+ if (report === null) return true;
+ const dirs = [path.join(channelDir, "data")];
+ if (Array.isArray(ids)) {
+ for (const id of ids) {
+ if (typeof id === "string" && /^[A-Za-z0-9_-]+$/.test(id)) dirs.push(path.join(channelDir, "data", id));
+ }
+ }
+ for (const d of dirs) {
+ const m = await mtimeOf(d);
+ if (m !== null && m > report) return true;
+ }
+ return false;
+}
+
export async function POST(request: Request) {
return ops(
request,
@@ -57,7 +81,11 @@ export async function POST(request: Request) {
const slug = reqSlug(body, "slug");
const paths = getPaths();
let snapshot = await readChannelSnapshot(paths, slug);
- if (bucketMisses(snapshot?.buckets.downloadedNoTranscript ?? [], body.ids) && (await channelExists(paths, slug))) {
+ if (
+ bucketMisses(snapshot?.buckets.downloadedNoTranscript ?? [], body.ids) &&
+ (await channelExists(paths, slug)) &&
+ (await reportBehindDisk(path.join(paths.channelsDir, slug), body.ids))
+ ) {
const asked = await requestRefreshReport(paths, slug);
if (asked.ok) {
const wait = await waitForRefreshReport(paths, asked.jobId, { timeoutMs: REGEN_WAIT_MS });
@@ -77,9 +105,9 @@ export async function POST(request: Request) {
);
}
const bucketIds = snapshot.buckets.downloadedNoTranscript ?? [];
- if (bucketIds.length === 0) {
+ if (bucketIds.length === 0 && body.ids === undefined) {
return opsFail(
- `Nothing to transcribe on ${slug}: its report, read again from disk, holds no downloaded, untranscribed audio.`,
+ `Nothing to transcribe on ${slug}: its report holds no downloaded, untranscribed audio.`,
400,
{ info: true },
);
diff --git a/editor/e2e/chat-only.spec.ts b/editor/e2e/chat-only.spec.ts
@@ -378,3 +378,42 @@ test("the form round-trips the chat-only tier and the ops API sets it", async ({
).downloadFilter?.rejectedLivestreams,
).toBe("chat-only");
});
+
+// CHAT LATER (2026-10-26). A stream's chat replay made each YouTube download of
+// a streaming channel 2–4× slower; `chat: "later"` (Configure → Live chat
+// replay) leaves it out of the downloads, and the backlog job — the lane's by
+// itself, or the Download stage's button — fetches it afterwards, selected by
+// the stream's metadata (a download without live_chat records no chat track).
+test("chat later: set on the Configure form, then the Download stage's backlog fetches the stream's chat", async ({
+ page,
+}) => {
+ test.setTimeout(180_000);
+ await resetData("title-filter-channel");
+ await writeFilterConfig(null);
+ await generateReport(page, CHANNEL);
+
+ await page.goto(channelStage(CHANNEL, "configure"));
+ await page.getByLabel("live chat replay").selectOption("later");
+ await page.getByLabel("caption languages").fill("en.*");
+ await page.getByRole("button", { name: /save changes/i }).click();
+ await expect
+ .poll(async () => {
+ const c = await readJson<{ chat?: string; subLangs?: string }>(`${ROOT}/config.json`);
+ return `${c.chat}|${c.subLangs}`;
+ })
+ .toBe("later|en.*");
+ await page.reload();
+ await expect(page.getByLabel("live chat replay")).toHaveValue("later");
+
+ await download(page);
+ expect(await pathExists(`${ROOT}/data/${LIVE}/transcript.live_chat.json`)).toBe(false);
+
+ await page.goto(channelStage(CHANNEL, "download"));
+ await page.getByRole("button", { name: "Fetch chat backlog" }).click();
+ const out = page.getByLabel("Fetch chat backlog output");
+ await expect(out).toContainText(/Chat backlog of test-filter: 1 fetched/, { timeout: 60_000 });
+ expect(await pathExists(`${ROOT}/data/${LIVE}/live_chat.cues.json`)).toBe(true);
+ const state = await readJson<{ lastRun?: { complete: boolean; fetched: number } }>(`${ROOT}/chat-backlog.json`);
+ expect(state.lastRun?.complete).toBe(true);
+ expect(state.lastRun?.fetched).toBe(1);
+});