commit 8e4fb917cfc40cc4d5e234339159b53c2849a782
parent e9cda413a4f7795e5f7b8fe3f7aad4fa193af537
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Mon, 9 Nov 2026 23:34:53 -0500
jobs: a held transcription is a skip for every caller; a persist run stops before fetching for a store that cannot take it
Review of lane drive-stall, item 2:
- isMediaDriveHeld (transcribeError.ts) is the one predicate (by instance,
or by the class's flag from another module copy). transcribeOneFromQueue
skips on it; downloadOneManaged's inline whisper no longer marks a download
failed when its audio's drive is not answering — the status stays the
attempt's, as with inline whisper off. The one-video jobs (transcribe-one,
fix-incomplete) fail with the drive's sentence, as before for a refusal.
- savedVideosStoreRefusal (lib/savedVideoStore.ts): the store guard's error
as a value. persist-videos stops before each fetch on it
(stopped: "store-unavailable", reported like low-disk), persist-kept stops
and counts skippedStoreUnavailable — neither downloads a container only to
leave it in the data dir. dropSavedAlternateAction answers the
not-answering refusal like the in-transition one.
- transcribeOneVideo's config read for the stall check is memoised per
channel for 10 s (review nit 3b).
Tests: persist-videos and persist-kept stop with no download; the predicate.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
12 files changed, 213 insertions(+), 16 deletions(-)
diff --git a/common/controller/persistKept.test.ts b/common/controller/persistKept.test.ts
@@ -59,6 +59,7 @@ test("persistKept is a no-op when keep-latest is off", async () => {
persisted: 0,
failed: 0,
skippedNoUrl: 0,
+ skippedStoreUnavailable: 0,
skippedLowDisk: 0,
});
});
@@ -83,3 +84,35 @@ test("persistKept counts in-window videos already saved without re-downloading",
assert.equal(res.skippedNoUrl, 0);
});
});
+
+// A STORE THAT CANNOT TAKE A CONTAINER STOPS THE PASS BEFORE ANY FETCH (review
+// of lane drive-stall): the store's drive is not answering, so nothing is
+// downloaded to land nowhere; every unsaved kept video is counted skipped.
+test("persistKept stops before fetching when the saved-video store's drive is not answering", async () => {
+ const { recordLocationHealth, resetStorageHealth } = await import("../lib/storageHealth");
+ await withPaths(async (paths) => {
+ for (const id of ["20240101_a", "20240202_b", "20240303_c"]) {
+ await mkdir(path.join(paths.channelsDir, "alpha", "data", id), { recursive: true });
+ }
+ recordLocationHealth(
+ { id: "store", label: "Store drive", root: path.dirname(paths.savedVideosDir) },
+ "stalled",
+ );
+ const lines: string[] = [];
+ try {
+ const res = await persistKept({
+ paths,
+ channelSlug: "alpha",
+ channelConfig: { handling: "transcribe", keepLatest: 2 },
+ onLog: (l: string) => lines.push(l),
+ });
+ assert.equal(res.kept, 2);
+ assert.equal(res.persisted, 0);
+ assert.equal(res.failed, 0);
+ assert.equal(res.skippedStoreUnavailable, 2);
+ assert.match(lines.join("\n"), /The saved-video store's drive "Store drive" is not answering .* — stopping/);
+ } finally {
+ resetStorageHealth();
+ }
+ });
+});
diff --git a/common/controller/persistKept.ts b/common/controller/persistKept.ts
@@ -5,6 +5,8 @@ import { getSettings } from "../lib/settings";
import { diskGate } from "../lib/diskSpace";
import { resolveCookiePolicy } from "../lib/cookiePolicy";
import { isSavedVideo } from "../lib/savedVideo-server";
+import { savedVideoDir } from "../lib/savedVideo";
+import { savedVideosStoreRefusal } from "../lib/savedVideoStore";
import { computeKeptVideoIds } from "./keptVideos";
import { findVideoSourceUrl } from "./undownloadedVideos";
import {
@@ -40,6 +42,9 @@ export type PersistKeptResult = {
failed: number;
// No resolvable source URL (no metadata + not in the playlist).
skippedNoUrl: number;
+ // Not attempted because the saved-video store could not take a container
+ // (its drive not answering, or mid-move) — asked before each fetch.
+ skippedStoreUnavailable: number;
// Not attempted because free disk fell under the floor part-way through. A
// refusal to start, not a failure — these videos are still kept, still
// unpersisted, and the next pass picks them up.
@@ -81,6 +86,7 @@ export async function persistKept({
failed: 0,
skippedNoUrl: 0,
skippedLowDisk: 0,
+ skippedStoreUnavailable: 0,
};
if (keptIds.size === 0) {
log(
@@ -105,17 +111,35 @@ export async function persistKept({
// Set once the disk gate closes mid-pass. Everything after it is counted as
// skipped rather than attempted, so the log says how much was left.
let lowDisk = false;
+ let storeUnavailable = false;
for (const videoId of ordered) {
if (signal?.aborted) break;
if (lowDisk) {
result.skippedLowDisk += 1;
continue;
}
+ if (storeUnavailable) {
+ result.skippedStoreUnavailable += 1;
+ continue;
+ }
const videoDir = path.join(dataDir, videoId);
if (await isSavedVideo(videoDir)) {
result.alreadySaved += 1;
continue;
}
+ // THE STORE MUST BE ABLE TO TAKE IT (review of lane drive-stall): asked
+ // before the fetch, so a stalled store drive or a store mid-move stops the
+ // pass instead of downloading containers that land nowhere.
+ const refusal = await savedVideosStoreRefusal(
+ paths,
+ savedVideoDir(paths, channelConfig, channelSlug, videoId),
+ );
+ if (refusal) {
+ storeUnavailable = true;
+ result.skippedStoreUnavailable += 1;
+ log(` ${videoId}: ${refusal.message} — stopping; remaining videos skipped.`);
+ continue;
+ }
// PER ITEM, not once at the start. This pass writes full source containers —
// the largest files the app produces — so the twentieth video must not
// inherit the first one's headroom. Same shape as backfillReacquire's
@@ -175,6 +199,9 @@ export async function persistKept({
(result.skippedLowDisk > 0
? `, ${result.skippedLowDisk} skipped (low disk)`
: "") +
+ (result.skippedStoreUnavailable > 0
+ ? `, ${result.skippedStoreUnavailable} skipped (saved-video store unavailable)`
+ : "") +
` of ${result.kept} kept.`,
);
return result;
diff --git a/common/controller/persistVideos.test.ts b/common/controller/persistVideos.test.ts
@@ -538,3 +538,30 @@ test("a dry run buckets every item and fetches nothing", async () => {
assert.equal(res.plan.willFetch, 2);
});
});
+
+// A STORE THAT CANNOT TAKE A CONTAINER STOPS THE RUN BEFORE THE FETCH (review
+// of lane drive-stall): its drive is not answering, so no container is
+// downloaded only to be left in the data dir.
+test("a saved-video store whose drive is not answering stops the run before any fetch", async () => {
+ const { recordLocationHealth, resetStorageHealth } = await import("../lib/storageHealth");
+ await withPaths(async (paths) => {
+ for (const id of ["aaa111", "bbb222"]) await seedVideo(paths, "demo-channel", id);
+ recordLocationHealth(
+ { id: "store", label: "Store drive", root: path.dirname(paths.savedVideosDir) },
+ "stalled",
+ );
+ try {
+ const h = harness(paths);
+ const res = await persistVideos({
+ paths,
+ items: ["aaa111", "bbb222"].map((id) => ({ slug: "demo-channel", id })),
+ deps: h.deps,
+ });
+ assert.deepEqual(h.downloads, []);
+ assert.equal(res.stopped, "store-unavailable");
+ assert.deepEqual(res.notAttempted.map((i) => i.id), ["aaa111", "bbb222"]);
+ } finally {
+ resetStorageHealth();
+ }
+ });
+});
diff --git a/common/controller/persistVideos.ts b/common/controller/persistVideos.ts
@@ -5,9 +5,10 @@ import type { ChannelConfig } from "../lib/channelConfig";
import type { SiteSettings } from "../lib/settings";
import { getSettings } from "../lib/settings";
import { diskGate, type DiskGateStatus } from "../lib/diskSpace";
+import { savedVideosStoreRefusal } from "../lib/savedVideoStore";
import { resolveCookiePolicy } from "../lib/cookiePolicy";
import type { DownloadOutcomeRecord } from "../lib/downloadOutcome";
-import type { SavedVideoPointer } from "../lib/savedVideo";
+import { savedVideoDir, type SavedVideoPointer } from "../lib/savedVideo";
import {
loadSavedVideo,
restoreSavedVideoProvenance,
@@ -94,7 +95,15 @@ export type PersistVideosPlan = {
willFetch: number;
};
-export type PersistVideosStop = "low-disk" | "rate-limit" | "cancelled" | "drained";
+// `store-unavailable`: the saved-video store cannot take a container (its
+// drive is not answering, or it is being moved) — the run stops before
+// downloading one only to leave it in the data dir.
+export type PersistVideosStop =
+ | "low-disk"
+ | "rate-limit"
+ | "store-unavailable"
+ | "cancelled"
+ | "drained";
export type PersistVideosResult = {
plan: PersistVideosPlan;
@@ -459,6 +468,18 @@ export async function persistVideos({
stop("low-disk", i);
break;
}
+ // THE STORE MUST BE ABLE TO TAKE IT, asked before the fetch: a stalled
+ // drive or a store mid-move would refuse the container after a whole
+ // download. Memory and the corpus disk only.
+ const refusal = await savedVideosStoreRefusal(
+ paths,
+ savedVideoDir(paths, config, p.slug, p.id),
+ );
+ if (refusal) {
+ log(` ${label(p)}: ${refusal.message} — stopping; the rest are left for a later run.`);
+ stop("store-unavailable", i);
+ break;
+ }
const replacing = p.bucket === "wrongHeight";
log(
` ${label(p)}: ${replacing ? "replacing the saved container" : "fetching the source container"} (${quality})…`,
diff --git a/common/controller/transcribeError.ts b/common/controller/transcribeError.ts
@@ -23,7 +23,19 @@ export class TranscribeError extends Error {
// in failed-transcriptions, transcribed on a later pass once the drive answers.
// Its own class so a batch's log says the drive, not "no audio file".
export class MediaDriveHeldError extends TranscribeError {
+ // Read by `isMediaDriveHeld`, which also answers for a copy of this class
+ // from another module instance (instanceof does not).
+ readonly mediaDriveHeld = true;
constructor(message: string) {
super(message, "no-audio");
}
}
+
+// A transcription refused because its channel's media drive is not answering:
+// a skip for every caller, never a failed transcription or a failed download.
+export function isMediaDriveHeld(err: unknown): err is MediaDriveHeldError {
+ return (
+ err instanceof MediaDriveHeldError ||
+ (err instanceof Error && (err as { mediaDriveHeld?: unknown }).mediaDriveHeld === true)
+ );
+}
diff --git a/common/controller/transcribeOne.test.ts b/common/controller/transcribeOne.test.ts
@@ -124,3 +124,15 @@ test("a channel whose media drive is not answering is refused before its audio i
await rm(dir, { recursive: true, force: true });
}
});
+
+// Every caller reads a held transcription as a skip through ONE predicate,
+// which also answers for a copy of the class from another module instance.
+test("isMediaDriveHeld: the held class, by instance or by its flag; nothing else", async () => {
+ const { isMediaDriveHeld, MediaDriveHeldError } = await import("./transcribeError");
+ assert.equal(isMediaDriveHeld(new MediaDriveHeldError("the media drive \"x\" is not answering")), true);
+ const foreign = Object.assign(new Error("copy"), { mediaDriveHeld: true });
+ assert.equal(isMediaDriveHeld(foreign), true);
+ assert.equal(isMediaDriveHeld(new TranscribeError("no audio file", "no-audio")), false);
+ assert.equal(isMediaDriveHeld(new Error("boom")), false);
+ assert.equal(isMediaDriveHeld(null), false);
+});
diff --git a/common/controller/transcribeOne.ts b/common/controller/transcribeOne.ts
@@ -2,6 +2,7 @@ import path from "node:path";
import fs from "fs-extra";
import { execa } from "execa";
import type { Paths } from "../lib/paths";
+import type { ChannelConfig } from "../lib/channelConfig";
import type { Worker } from "../lib/workers";
import { getTranscriptionApp } from "../lib/transcriptionApps";
import { detectTranscriptFormat } from "../lib/whisper";
@@ -69,6 +70,23 @@ async function resolveAudioFile(
return null;
}
+// THE CHANNEL'S CONFIG FOR THE STALL CHECK, read at most once per 10 s per
+// channel (review of lane drive-stall): a batch transcribes a channel's videos
+// one after another, and each asked config.json again. Its media targets are
+// all the check reads, and a move rewrites them seldom; ten seconds late is
+// within the health pass's own cadence.
+const STALL_CONFIG_TTL_MS = 10_000;
+const stallConfigMemo = new Map<string, { at: number; config: ChannelConfig | null }>();
+
+async function channelConfigForStall(file: string): Promise<ChannelConfig | null> {
+ const now = Date.now();
+ const hit = stallConfigMemo.get(file);
+ if (hit && now - hit.at < STALL_CONFIG_TTL_MS) return hit.config;
+ const config = await readChannelConfigFile(file).catch(() => null);
+ stallConfigMemo.set(file, { at: now, config });
+ return config;
+}
+
// A CONTAINER TO TRANSCRIBE FROM, before any audio download (release 23 F2).
//
// The page's Transcribe (and `pnpm ops transcribe-one`) used to download the
@@ -206,10 +224,11 @@ export async function transcribeOneVideo(
// is a tierable file, a link onto the channel's media drive; asking for it
// there in-process holds one of Node's file threads until the kernel gives
// up (~30 s). The health record is memory, the config the corpus disk's.
- const mediaConfig = await readChannelConfigFile(
- path.join(path.dirname(path.dirname(opts.videoDir)), "config.json"),
- ).catch(() => null);
- const stall = channelMediaStall(mediaConfig);
+ const stall = channelMediaStall(
+ await channelConfigForStall(
+ path.join(path.dirname(path.dirname(opts.videoDir)), "config.json"),
+ ),
+ );
if (stall) {
throw new MediaDriveHeldError(
`${mediaDriveHeldText(stall)} — ${opts.videoId} is left for when it answers`,
diff --git a/common/controller/transcribeOneFromQueue.ts b/common/controller/transcribeOneFromQueue.ts
@@ -7,7 +7,7 @@ import {
readVideoFiles,
} from "../lib/videoStatus";
import { transcribeWithWorker } from "./transcribeOne";
-import { MediaDriveHeldError, TranscribeError } from "./transcribeError";
+import { isMediaDriveHeld, TranscribeError } from "./transcribeError";
import type { TaskTracker } from "../jobs/taskHooks";
const { pathExists, appendFile } = fs;
@@ -157,7 +157,7 @@ export async function transcribeOneFromQueue({
// A missing audio file is a download/source problem, not a transcription
// failure — skip it (it transcribes once a good audio file exists) rather
// than permanently recording it in failed-transcriptions.
- if (err instanceof MediaDriveHeldError) {
+ if (isMediaDriveHeld(err)) {
log(`Skipping ${videoId}: ${err.message}`);
return { attempted: true, outcome: "skipped" };
}
diff --git a/common/lib/savedVideoStore.ts b/common/lib/savedVideoStore.ts
@@ -141,3 +141,27 @@ export class SavedVideosStoreNotAnsweringError extends Error {
this.health = health;
}
}
+
+// THE STORE'S REFUSAL, AS A VALUE (review of lane drive-stall): the error the
+// guard above would throw for a write into `storeDir` — the store's drive not
+// answering, or the store mid-move — or null. A batch that FETCHES before it
+// persists (persist-videos, persist-kept: a whole source container per video)
+// asks this before each download, so a store that cannot take the container
+// stops the run instead of downloading one only to leave it in the data dir.
+export async function savedVideosStoreRefusal(
+ paths: Pick<Paths, "transcriptsDir" | "savedVideosDir">,
+ storeDir: string,
+): Promise<SavedVideosStoreNotAnsweringError | SavedVideosStoreInTransitionError | null> {
+ try {
+ await assertSavedVideosStoreWritable(paths, storeDir);
+ return null;
+ } catch (err) {
+ if (
+ err instanceof SavedVideosStoreNotAnsweringError ||
+ err instanceof SavedVideosStoreInTransitionError
+ ) {
+ return err;
+ }
+ throw err;
+ }
+}
diff --git a/common/ytdlp/downloadOneManaged.ts b/common/ytdlp/downloadOneManaged.ts
@@ -87,6 +87,7 @@ import {
} from "../lib/transcriptCoverage";
import type { Paths } from "../lib/paths";
import { transcribeWithWorker } from "../controller/transcribeOne";
+import { isMediaDriveHeld } from "../controller/transcribeError";
import { extractVideoId, outputArgsForUrl } from "./runYtdlp";
import { channelExtraArgs, channelPaceSeconds } from "./channelArgs";
import {
@@ -1855,11 +1856,21 @@ async function runManagedDownload(
});
status = "ok-auto-transcribed";
} catch (err) {
- opts.onLog(
- `Whisper failed after no-subs fallback: ${(err as Error).message}\n`,
- );
- status = "failed";
- lastSucceeded = false;
+ if (isMediaDriveHeld(err)) {
+ // THE AUDIO IS HERE; ITS DRIVE IS NOT ANSWERING (lane
+ // drive-stall). The download succeeded — the status stays the
+ // attempt's, as when inline whisper is off, and the transcription
+ // lane picks the video up once the drive answers.
+ opts.onLog(
+ `Audio downloaded for ${videoId}; not transcribed inline: ${(err as Error).message}.\n`,
+ );
+ } else {
+ opts.onLog(
+ `Whisper failed after no-subs fallback: ${(err as Error).message}\n`,
+ );
+ status = "failed";
+ lastSucceeded = false;
+ }
}
} else {
opts.onLog(
diff --git a/editor/app/channels/[slug]/persistActions.ts b/editor/app/channels/[slug]/persistActions.ts
@@ -122,7 +122,11 @@ export async function persistChannelVideosAction(
safeRevalidate([`/channels/${slug}`, "/saved-videos"]);
// A run that stopped short or lost a video did not do what it was asked:
// the job says so, and the re-run picks up the rest.
- if (result.stopped === "low-disk" || result.stopped === "rate-limit") {
+ if (
+ result.stopped === "low-disk" ||
+ result.stopped === "rate-limit" ||
+ result.stopped === "store-unavailable"
+ ) {
throw new Error(
`Stopped (${result.stopped}) with ${result.notAttempted.length} video(s) not attempted — run it again later.`,
);
diff --git a/editor/app/channels/[slug]/videos/[id]/videoActions.ts b/editor/app/channels/[slug]/videos/[id]/videoActions.ts
@@ -82,7 +82,10 @@ import {
unpersistSavedVideo,
type DropSavedAlternateResult,
} from "yt-dlp-transcript-common/lib/savedVideo-server";
-import { SavedVideosStoreInTransitionError } from "yt-dlp-transcript-common/lib/savedVideoStore";
+import {
+ SavedVideosStoreInTransitionError,
+ SavedVideosStoreNotAnsweringError,
+} from "yt-dlp-transcript-common/lib/savedVideoStore";
import {
savedVideoPath,
type SavedVideoOrigin,
@@ -1457,7 +1460,11 @@ export async function dropSavedAlternateAction(
paths,
});
} catch (e) {
- if (e instanceof SavedAlternateRefusal || e instanceof SavedVideosStoreInTransitionError) {
+ if (
+ e instanceof SavedAlternateRefusal ||
+ e instanceof SavedVideosStoreInTransitionError ||
+ e instanceof SavedVideosStoreNotAnsweringError
+ ) {
return { ok: false, error: e.message };
}
throw e;