commit 000f00623ac2b091372b068270c3190f54f0d295
parent a2354f80691db583b825af6fc9032db7c88143b0
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 11 Nov 2026 02:53:16 -0500
cleanup (review B2): clean after capture holds a channel with no source URL -- "no source to check: clean by hand" -- unless its config sets cleanAfterCaptureUnverified: true (schema + CHANNEL.md); the manual Clean audio sweep keeps today's fail-open behaviour
verifyBeforeClean fails OPEN for a URL-less channel, which is right for a
sweep the operator pressed and wrong for an automatic delete: an imported or
hand-built channel's audio may be its only copy anywhere. The opt-in skips
the availability step for that channel only (there is nothing to list).
Tests: held without the opt-in, cleaned with it, and the channel sweep on the
same channel still cleans.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat:
6 files changed, 47 insertions(+), 3 deletions(-)
diff --git a/CHANNEL.md b/CHANNEL.md
@@ -40,6 +40,7 @@ Regenerate this file with `pnpm --filter yt-dlp-transcript-common exec tsx bin/f
| `lastFullSweepAt` | sync state | SYNC STATE. When this channel last paid for a sync FULL SWEEP — the deep pass that re-enumerates the whole listing to refresh `playlist` and flag videos that have left it. Stamped by the sweep; read by the cadence gate to decide whether the next sync sweeps or stays on the cheap newest-first paged walk. |
| `excludeFromBuild` | config | Leave this channel out of every site build. |
| `excludeFromCleanup` | config | Leave this channel's reclaimable bytes out of the aggregate "cleanable data" total on /cleanup and its badge. The per-channel cleanup sweeps stay available; only the running total changes. |
+| `cleanAfterCaptureUnverified` | config | Let clean-after-capture (settings `diarization.cleanAfterCapture`) delete this channel's audio with NO availability check. Only for a channel with no `url`: with no source there is nothing to list, so the automatic per-video clean holds every such channel ("no source to check: clean by hand") unless this is true. The manual Clean audio sweep is unaffected. Absent/false = held. |
| `syncIntervalMinutes` | config | Auto-sync cadence: the scheduler syncs this channel when `now - lastSyncedAt >= syncIntervalMinutes`. Absent = inherit the global default; 0 = auto-sync off (still manually syncable); positives clamp to [1, 44640] (~31 days). A missing `url`, or a `sync` tier of paused in the channel-priority document, also disables auto-sync. |
| `fullSweepIntervalMinutes` | config | Full-sweep cadence: a sync upgrades itself to a full sweep when `now - lastFullSweepAt >= fullSweepIntervalMinutes`. Absent = inherit `syncScheduler.fullSweepIntervalMinutes`; 0 = never sweep (every sync is a paged walk); positives clamp to [1, 44640]. |
| `skipLiveDownloads` | config | Per-channel override for the global `skipLiveDownloads`. Absent = inherit; false = allow downloading currently-live / upcoming videos. |
diff --git a/common/controller/cleanAfterCapture.test.ts b/common/controller/cleanAfterCapture.test.ts
@@ -304,6 +304,30 @@ test("a held platform: the video is held, nothing deleted, nothing requested", a
assert.ok(logs.some((l) => l.includes("youtube is held after a 429")), logs.join("\n"));
});
+// ---- B2: a channel with no source URL ---------------------------------------
+
+test("no source URL: the automatic clean holds; the channel's opt-in lets it through; the manual sweep is unchanged", async () => {
+ await settings({}, { verifyAvailabilityBeforeClean: true });
+ const { paths, video } = await corpus();
+ const cfg = path.join(paths.channelsDir, "ch", "config.json");
+ await writeFile(cfg, JSON.stringify({ handling: "transcribe", name: "ch" }));
+ const a = await video("a1", { diarization: "voiceprints" });
+ const out = await cleanAudioForVideo({ channelSlug: "ch", paths, videoId: "a1", onLog: () => {}, checkDeps: NO_NETWORK });
+ assert.deepEqual(out, { outcome: "held", gate: "no-source-url", removedFiles: 0, bytesFreed: 0 });
+ assert.equal(await exists(path.join(a, "audio.mp3")), true);
+
+ await writeFile(cfg, JSON.stringify({ handling: "transcribe", name: "ch", cleanAfterCaptureUnverified: true }));
+ assert.equal((await cleanAudioForVideo({ channelSlug: "ch", paths, videoId: "a1", onLog: () => {}, checkDeps: NO_NETWORK })).outcome, "cleaned");
+
+ // The manual sweep: as today — a channel with no URL cannot be verified and
+ // is cleaned (verifyBeforeClean fails open), opt-in or not.
+ await writeFile(cfg, JSON.stringify({ handling: "transcribe", name: "ch" }));
+ const b = await video("b1", { diarization: "voiceprints" });
+ const r = await cleanAudioFromTranscribed({ channelSlug: "ch", paths, onLog: () => {} });
+ assert.equal(r.cleanedDirs, 1);
+ assert.equal(await exists(path.join(b, "audio.mp3")), false);
+});
+
test.after(() => rm(ROOT, { recursive: true, force: true }));
test("concurrency stays 1: one diarization at a time, one backfill unit at a time", () => {
diff --git a/common/controller/cleanAudioFromTranscribed.ts b/common/controller/cleanAudioFromTranscribed.ts
@@ -92,7 +92,11 @@ export type AudioCleanGate =
// diarization.cleanVerdictMaxAgeHours (a check is requested), or a fresh
// listing that does not name the video (maybe deleted, maybe unlisted).
| "awaiting-availability"
- | "maybe-missing";
+ | "maybe-missing"
+ // cleanAudioForVideo only (review B2): the channel has no source URL, so no
+ // check can vouch for anything — held unless its config sets
+ // cleanAfterCaptureUnverified. The manual sweep cleans these as before.
+ | "no-source-url";
export async function audioCleanGate(
videoDir: string,
@@ -349,6 +353,15 @@ export async function cleanAudioForVideo({
return held(gate);
}
if (signal?.aborted) return held(gate);
+ // NO SOURCE, NO CHECK (review B2). verifyBeforeClean fails OPEN for a channel
+ // with no URL — right for a sweep the operator pressed, wrong for an
+ // automatic delete: an imported or hand-built channel's audio may be its only
+ // copy anywhere. Held unless the channel opts in.
+ const unverifiedOptIn = !config?.url && config?.cleanAfterCaptureUnverified === true;
+ if (!config?.url && !unverifiedOptIn) {
+ log(`Kept ${videoId}'s audio: no source to check — clean by hand (or set cleanAfterCaptureUnverified on the channel).`);
+ return held("no-source-url");
+ }
// AN UNMOUNTED DRIVE IS NOT AN EMPTY ONE. The audio here may be a tier link
// into a media/ that points at another disk; removing the link while that
// disk is away strands its bytes there. Asked fresh, per video: this runs
@@ -359,7 +372,8 @@ export async function cleanAudioForVideo({
log(`Kept ${videoId}'s audio: ${(err as Error).message}`);
return held("media-unreachable");
}
- const verify = verifyAvailability ?? getSettings().verifyAvailabilityBeforeClean;
+ const verify =
+ !unverifiedOptIn && (verifyAvailability ?? getSettings().verifyAvailabilityBeforeClean);
if (verify) {
const cached = await resolveEffectiveAvailability(videoDir);
if (isPermanentlyGone(cached)) {
diff --git a/common/lib/channelConfig.ts b/common/lib/channelConfig.ts
@@ -245,6 +245,7 @@ export type ChannelConfig = {
lastFullSweepAt?: string;
excludeFromBuild?: boolean;
excludeFromCleanup?: boolean;
+ cleanAfterCaptureUnverified?: boolean;
syncIntervalMinutes?: number;
fullSweepIntervalMinutes?: number;
skipLiveDownloads?: boolean;
@@ -317,6 +318,8 @@ export const CHANNEL_CONFIG_FIELD_DOCS: FieldDocs<ChannelConfig> = {
excludeFromBuild: "Leave this channel out of every site build.",
excludeFromCleanup:
"Leave this channel's reclaimable bytes out of the aggregate \"cleanable data\" total on /cleanup and its badge. The per-channel cleanup sweeps stay available; only the running total changes.",
+ cleanAfterCaptureUnverified:
+ "Let clean-after-capture (settings `diarization.cleanAfterCapture`) delete this channel's audio with NO availability check. Only for a channel with no `url`: with no source there is nothing to list, so the automatic per-video clean holds every such channel (\"no source to check: clean by hand\") unless this is true. The manual Clean audio sweep is unaffected. Absent/false = held.",
syncIntervalMinutes:
"Auto-sync cadence: the scheduler syncs this channel when `now - lastSyncedAt >= syncIntervalMinutes`. Absent = inherit the global default; 0 = auto-sync off (still manually syncable); positives clamp to [1, 44640] (~31 days). A missing `url`, or a `sync` tier of paused in the channel-priority document, also disables auto-sync.",
fullSweepIntervalMinutes:
@@ -539,6 +542,7 @@ export const CHANNEL_CONFIG_COERCIONS: {
lastFullSweepAt: str,
excludeFromBuild: bool,
excludeFromCleanup: bool,
+ cleanAfterCaptureUnverified: bool,
syncIntervalMinutes: zeroOrClamped(SYNC_INTERVAL_MIN_MINUTES, SYNC_INTERVAL_MAX_MINUTES),
fullSweepIntervalMinutes: zeroOrClamped(
SYNC_INTERVAL_MIN_MINUTES,
diff --git a/common/lib/channelConfigSchema.test.ts b/common/lib/channelConfigSchema.test.ts
@@ -39,7 +39,7 @@ test("one key list: docs = coercions = schema shape, sync-state keys inside it",
assert.deepEqual(Object.keys(CHANNEL_CONFIG_COERCIONS), [...CHANNEL_CONFIG_KEYS]);
assert.deepEqual(Object.keys(channelConfigObjectSchema.shape), [...CHANNEL_CONFIG_KEYS]);
assert.deepEqual(Object.keys(CHANNEL_CONFIG_FIELD_DOCS), [...CHANNEL_CONFIG_KEYS]);
- assert.equal(CHANNEL_CONFIG_KEYS.length, 42); // 2026-10-30: `skipShorts`
+ assert.equal(CHANNEL_CONFIG_KEYS.length, 43); // 2026-11-11: `cleanAfterCaptureUnverified`
assert.equal(sameKeys, true);
assert.equal(fits, true);
for (const k of CHANNEL_SYNC_STATE_KEYS) assert.ok(CHANNEL_CONFIG_KEYS.includes(k), k);
diff --git a/common/lib/channelConfigSchema.ts b/common/lib/channelConfigSchema.ts
@@ -69,6 +69,7 @@ export const channelConfigObjectSchema = z.object({
lastFullSweepAt: field("lastFullSweepAt"),
excludeFromBuild: field("excludeFromBuild"),
excludeFromCleanup: field("excludeFromCleanup"),
+ cleanAfterCaptureUnverified: field("cleanAfterCaptureUnverified"),
syncIntervalMinutes: field("syncIntervalMinutes"),
fullSweepIntervalMinutes: field("fullSweepIntervalMinutes"),
skipLiveDownloads: field("skipLiveDownloads"),