Archilyzer · Source

archilyzer

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

commit 8a8a2812751b926b33d2da8b5f0cd3acee208db7
parent c8c3476800034651b68926b37d7ac72931a0b25b
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 11 Nov 2026 01:07:44 -0500

cleanup: clean after capture never deletes through an unmounted drive -- cleanAudioForVideo asserts the channel's media is reachable, fresh, before removing anything (a tier link removed while its disk is away strands the bytes there); the channel sweep keeps its job kind's needsMedia guard

Safety tests beside it: an unmounted media drive holds the audio link as it
is ("media-unreachable"); a clean removes the audio and nothing else (source
media, transcripts, sidecars, the saved-video pointer, clips/ untouched); the
concurrency defaults that are load-bearing stay 1. The rest of the lane's
safety is already in place and tested in the earlier commits: unreadable
audio is recorded (audio-integrity.json) and reported blocked, not retried
every run; the runner skips a channel whose media is not answering
(buildChannelWork's media hold) and the per-channel run asserts reachability
(operationBatch); every Clean audio gate applies to clean-after-capture.

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

Diffstat:
Mcommon/controller/cleanAfterCapture.test.ts | 42+++++++++++++++++++++++++++++++++++++++++-
Mcommon/controller/cleanAudioFromTranscribed.ts | 16+++++++++++++++-
2 files changed, 56 insertions(+), 2 deletions(-)

diff --git a/common/controller/cleanAfterCapture.test.ts b/common/controller/cleanAfterCapture.test.ts @@ -1,6 +1,6 @@ import { test } from "node:test"; import assert from "node:assert/strict"; -import { access, mkdir, mkdtemp, rm, writeFile } from "node:fs/promises"; +import { access, lstat, mkdir, mkdtemp, readFile, rm, symlink, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import path from "node:path"; import type { Paths } from "../lib/paths"; @@ -200,4 +200,44 @@ test("clean after capture: off by default, and a protected video stays protected assert.equal(report.audioCleaned, 0); }); +test("cleanAudioForVideo: an unmounted media drive keeps the audio link where it is", async () => { + await settings({}); + const { paths, video } = await corpus(); + const v = await video("v1", { diarization: "voiceprints" }); + // Tier the audio by hand onto a "drive" that is not mounted: a dangling + // media link and a relative link into it, as mediaTier writes them. + await rm(path.join(v, "audio.mp3")); + const channelDir = path.join(paths.channelsDir, "ch"); + const target = path.join(ROOT, "platter-not-mounted", "ch", "media"); + await writeFile(path.join(channelDir, "config.json"), JSON.stringify({ name: "ch", mediaDir: target })); + await symlink(target, path.join(channelDir, "media")); + await symlink("../../media/v1/audio.mp3", path.join(v, "audio.mp3")); + const out = await cleanAudioForVideo({ channelSlug: "ch", paths, videoId: "v1", onLog: () => {} }); + assert.deepEqual(out, { outcome: "held", gate: "media-unreachable", removedFiles: 0, bytesFreed: 0 }); + assert.ok((await lstat(path.join(v, "audio.mp3"))).isSymbolicLink(), "the link is untouched"); +}); + +test("cleanAudioForVideo removes the audio and nothing else: no source media, clip, transcript, sidecar or saved-video pointer", async () => { + await settings({}); + const { paths, video } = await corpus(); + const v = await video("v1", { diarization: "voiceprints" }); + const keep = ["source-media.mp4", "transcript.json", "transcript.cues.json", "diarization.json", "saved-video.json"]; + for (const f of keep.filter((f) => !["transcript.json", "diarization.json"].includes(f))) await writeFile(path.join(v, f), "keep"); + await mkdir(path.join(v, "clips")); + await writeFile(path.join(v, "clips", "10.00-20.00.m4a"), "clip"); + const out = await cleanAudioForVideo({ channelSlug: "ch", paths, videoId: "v1", onLog: () => {} }); + assert.equal(out.outcome, "cleaned"); + assert.equal(await exists(path.join(v, "audio.mp3")), false); + for (const f of keep) assert.equal(await exists(path.join(v, f)), true, f); + assert.equal(await readFile(path.join(v, "clips", "10.00-20.00.m4a"), "utf8"), "clip"); +}); + test.after(() => rm(ROOT, { recursive: true, force: true })); + +test("concurrency stays 1: one diarization at a time, one backfill unit at a time", () => { + // Load-bearing (plans/FACTS.md): two sherpa runs at once doubled the 11 GB + // transients that OOM-killed the box; the Speakers lane runs beside GPU + // transcription on four of eight threads. + assert.equal(defaultSiteSettings().diarization.concurrency, 1); + assert.equal(defaultSiteSettings().backfill.concurrency, 1); +}); diff --git a/common/controller/cleanAudioFromTranscribed.ts b/common/controller/cleanAudioFromTranscribed.ts @@ -1,4 +1,5 @@ import { removeMediaFile } from "../lib/mediaTier-server"; +import { assertChannelMediaReachable } from "../lib/channelMedia"; import path from "node:path"; import fs from "fs-extra"; import type { Paths } from "../lib/paths"; @@ -73,7 +74,10 @@ export type AudioCleanGate = | "keep-latest" | "do-not-clean" | "awaiting-diarization" - | "awaiting-voiceprint"; + | "awaiting-voiceprint" + // cleanAudioForVideo only: the channel's media drive is not answering. The + // channel sweep is covered by its job kind's needsMedia guard instead. + | "media-unreachable"; export async function audioCleanGate( videoDir: string, @@ -320,6 +324,16 @@ export async function cleanAudioForVideo({ return held(gate); } if (signal?.aborted) return held(gate); + // 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 + // from a unit hook, not from a job whose kind declares needsMedia. + try { + await assertChannelMediaReachable(paths, channelSlug); + } catch (err) { + log(`Kept ${videoId}'s audio: ${(err as Error).message}`); + return held("media-unreachable"); + } const verify = verifyAvailability ?? getSettings().verifyAvailabilityBeforeClean; if (verify) { const verdicts = await verifyBeforeClean({