Archilyzer · Source

archilyzer

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

commit 67e550327e55193694d3c71863dbd375fe9630e8
parent c89f420248fc7c563a923ea256a40df4fad7ad75
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 11 Nov 2026 00:09:48 -0500

diarization: fingerprints for what is already diarized -- a fresh diarization.json without voiceprints is PARTIAL while its audio is on disk, and diarizeOneVideo's voiceprint step adds them from its own turns (no re-clustering, generatedAt kept); with the audio gone it is present ("no fingerprint possible"), and audio the engine cannot decode is recorded in audio-integrity.json and reported blocked

- voiceprintOneVideo (controller/diarizeOne.ts): scripts/diarize.mjs
  --voiceprints-only over the existing sidecar; outcomes voiceprinted /
  already-present / no-diarization / no-audio (a fact, never an error) /
  not-configured / unreadable / failed. It trusts the file: complete
  voiceprints, the same generatedAt and turn count, or it failed.
- diarizeOneVideo runs it when an existing sidecar is fresh but without them,
  so the lane, "Diarize speakers", inline capture and the backfill bin all
  fill them in; a failed voiceprint step still reports the diarization as
  existing (find-clips and friends never break on it).
- RECORD, THEN SKIP: a zero-byte audio (no engine run) or an engine decode
  exit (4/5) writes an audio-integrity.json verdict by "speakers", keyed to the
  file's size and mtime; the diarization op reports held audio that is
  `undecodable` as blocked until a different file is there.
- The diarization unit ships an existing diarization.json to a unit executor,
  so a remote worker does the voiceprint step too.

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

Diffstat:
Acommon/controller/diarizeOne.test.ts | 145+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcommon/controller/diarizeOne.ts | 161+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcommon/lib/audioIntegrity.ts | 5+++--
Mcommon/lib/operations.test.ts | 78++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
Mcommon/lib/operations.ts | 40+++++++++++++++++++++++++++++++++++++---
5 files changed, 422 insertions(+), 7 deletions(-)

diff --git a/common/controller/diarizeOne.test.ts b/common/controller/diarizeOne.test.ts @@ -0,0 +1,145 @@ +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { spawnSync } from "node:child_process"; +import path from "node:path"; +import os from "node:os"; +import { chmod, mkdtemp, mkdir, readFile, rm, writeFile } from "node:fs/promises"; +import { diarizeOneVideo, voiceprintOneVideo } from "./diarizeOne"; +import { defaultSiteSettings } from "../lib/settings"; +import type { Paths } from "../lib/paths"; +import { hasVoiceprints, type DiarizationRecord } from "../lib/diarization"; +import { loadDiarization } from "../lib/diarization-server"; +import { loadAudioIntegrity } from "../lib/audioIntegrity-server"; + +// Run with: +// pnpm --filter yt-dlp-transcript-common exec tsx --test common/controller/diarizeOne.test.ts +// +// The engine is a fake DIARIZE_BIN: it logs its argv, and in --voiceprints-only +// mode adds a voiceprint per speaker to the record it is given -- or exits 4 +// (diarize-sherpa.py's "ffmpeg failed") when FAKE_EXIT says so. + +const hasFfmpeg = spawnSync("ffmpeg", ["-version"], { stdio: "ignore" }).status === 0; + +const FAKE = `#!/usr/bin/env node +const fs = require("node:fs"); +const argv = process.argv.slice(2); +fs.appendFileSync(process.env.FAKE_LOG, JSON.stringify(argv) + "\\n"); +if (process.env.FAKE_EXIT) process.exit(Number(process.env.FAKE_EXIT)); +const at = (f) => argv[argv.indexOf(f) + 1]; +const rec = JSON.parse(fs.readFileSync(at("--voiceprints-only"), "utf8")); +const speakers = [...new Set(rec.turns.map((t) => t.speaker))]; +rec.voiceprints = speakers.map((s) => ({ speaker: s, seconds: 1, embedded: 1, centroid: [1, 0], embeddingModel: "emb.onnx" })); +rec.voiceprintsAt = "2026-11-11T00:00:00.000Z"; +fs.writeFileSync(at("--output"), JSON.stringify(rec) + "\\n"); +`; + +const EXISTING: DiarizationRecord = { + videoId: "vid1", + generatedAt: "2026-08-07T00:00:00.000Z", + speakers: 2, + turns: [ + { start: 0, end: 4, speaker: 0 }, + { start: 4, end: 9, speaker: 1 }, + ], + engine: { engine: "sherpa-onnx", segmentationModel: "seg.onnx", embeddingModel: "emb.onnx", threshold: 0.9 }, +}; + +async function setup(opts: { audio?: string | null } = {}) { + const root = await mkdtemp(path.join(os.tmpdir(), "diarize-one-")); + const bin = path.join(root, "fake-diarize.cjs"); + await writeFile(bin, FAKE); + await chmod(bin, 0o755); + const log = path.join(root, "calls.log"); + await writeFile(log, ""); + const videoDir = path.join(root, "vid1"); + await mkdir(videoDir); + await writeFile(path.join(videoDir, "diarization.json"), JSON.stringify(EXISTING) + "\n"); + if (opts.audio !== null) await writeFile(path.join(videoDir, "audio.mp3"), opts.audio ?? "not really mp3"); + const paths = { diarizeBin: bin, ffmpegBin: "ffmpeg", ffprobeBin: "ffprobe" } as unknown as Paths; + const settings = { + ...defaultSiteSettings().diarization, + enabled: true, + segModel: "/m/seg.onnx", + embModel: "/m/emb.onnx", + threshold: 0.9, + }; + process.env.FAKE_LOG = log; + const calls = async () => + (await readFile(log, "utf8")).split("\n").filter(Boolean).map((l) => JSON.parse(l) as string[]); + return { root, videoDir, paths, settings, calls, cleanup: () => rm(root, { recursive: true, force: true }) }; +} + +test("a fresh sidecar without voiceprints gets them from its own turns — no re-diarization, generatedAt kept", async () => { + const t = await setup(); + try { + const out = await diarizeOneVideo({ paths: t.paths, videoDir: t.videoDir, videoId: "vid1", settings: t.settings, onLog: () => {} }); + assert.equal(out, "diarized"); + const calls = await t.calls(); + assert.equal(calls.length, 1); + assert.ok(calls[0].includes("--voiceprints-only"), "the voiceprint step, not a diarization"); + assert.ok(!calls[0].includes("--seg")); + const rec = await loadDiarization(t.videoDir); + assert.equal(hasVoiceprints(rec), true); + assert.equal(rec?.generatedAt, EXISTING.generatedAt); + assert.deepEqual(rec?.turns, EXISTING.turns); + // A second pass has nothing to do. + assert.equal(await diarizeOneVideo({ paths: t.paths, videoDir: t.videoDir, videoId: "vid1", settings: t.settings, onLog: () => {} }), "already-exists"); + assert.equal((await t.calls()).length, 1); + } finally { + await t.cleanup(); + } +}); + +test("with the audio gone: no fingerprint is possible, and that is not a failure", async () => { + const t = await setup({ audio: null }); + try { + assert.equal(await voiceprintOneVideo({ paths: t.paths, videoDir: t.videoDir, videoId: "vid1", settings: t.settings, onLog: () => {} }), "no-audio"); + assert.equal(await diarizeOneVideo({ paths: t.paths, videoDir: t.videoDir, videoId: "vid1", settings: t.settings, onLog: () => {} }), "already-exists"); + assert.equal((await t.calls()).length, 0); + assert.equal(hasVoiceprints(await loadDiarization(t.videoDir)), false); + } finally { + await t.cleanup(); + } +}); + +test("a zero-byte audio is recorded as undecodable and skipped without running the engine", async () => { + const t = await setup({ audio: "" }); + try { + assert.equal(await voiceprintOneVideo({ paths: t.paths, videoDir: t.videoDir, videoId: "vid1", settings: t.settings, onLog: () => {} }), "unreadable"); + assert.equal((await t.calls()).length, 0); + const rec = await loadAudioIntegrity(t.videoDir); + assert.equal(rec?.verdict, "undecodable"); + assert.equal(rec?.by, "speakers"); + assert.equal(rec?.size, 0); + } finally { + await t.cleanup(); + } +}); + +test("an engine that cannot decode the audio (exit 4): recorded as undecodable, the sidecar untouched", { skip: !hasFfmpeg && "needs ffmpeg" }, async () => { + const t = await setup({ audio: "garbage, not audio" }); + process.env.FAKE_EXIT = "4"; + try { + const before = await readFile(path.join(t.videoDir, "diarization.json"), "utf8"); + assert.equal(await voiceprintOneVideo({ paths: t.paths, videoDir: t.videoDir, videoId: "vid1", settings: t.settings, onLog: () => {} }), "unreadable"); + assert.equal(await readFile(path.join(t.videoDir, "diarization.json"), "utf8"), before); + assert.equal((await loadAudioIntegrity(t.videoDir))?.verdict, "undecodable"); + } finally { + delete process.env.FAKE_EXIT; + await t.cleanup(); + } +}); + +test("an engine failure for any other reason is a plain failure, and no verdict is written", async () => { + const t = await setup(); + process.env.FAKE_EXIT = "1"; + try { + assert.equal(await voiceprintOneVideo({ paths: t.paths, videoDir: t.videoDir, videoId: "vid1", settings: t.settings, onLog: () => {} }), "failed"); + // diarizeOne keeps the diarization: the sidecar is fine, only without voiceprints. + assert.equal(await diarizeOneVideo({ paths: t.paths, videoDir: t.videoDir, videoId: "vid1", settings: t.settings, onLog: () => {} }), "already-exists"); + assert.equal(await loadAudioIntegrity(t.videoDir), null); + } finally { + delete process.env.FAKE_EXIT; + await t.cleanup(); + } +}); diff --git a/common/controller/diarizeOne.ts b/common/controller/diarizeOne.ts @@ -20,10 +20,18 @@ import { DIARIZATION_FILENAME, SORTFORMER_DIARIZATION_ENGINE, diarizationTarget, + hasVoiceprints, isDiarizationFresh, } from "../lib/diarization"; import { hasDiarization, loadDiarization } from "../lib/diarization-server"; import { findSourceMedia, isRealAudioFile } from "../lib/videoStatus"; +import { + fileIdentity, + integrityRecord, + measureAndRecordIntegrity, + writeAudioIntegrity, +} from "../lib/audioIntegrity-server"; +import type { AudioIntegrityVerdict } from "../lib/audioIntegrity"; import { pickPreferredAudio } from "../lib/mediaFiles"; import { resolveSavedVideo } from "../lib/savedVideo-server"; @@ -107,12 +115,23 @@ export async function diarizeOneVideo( if (!opts.force) { const existing = await loadDiarization(opts.videoDir); if (existing && isDiarizationFresh(existing, diarizationTarget(cfg))) { + // Fresh turns from before voiceprints existed: add them from those same + // turns while the audio is still here. Never a reason to fail the + // diarization itself — the sidecar is good, it is only without them. + if (!hasVoiceprints(existing)) { + const vp = await voiceprintOneVideo({ ...opts, settings: cfg }); + if (vp === "voiceprinted") return "diarized"; + } return "already-exists"; } } const media = await resolveDiarizableMedia(opts.videoDir); if (!media) return "no-audio"; + if (await isZeroByteAudio(opts.videoDir, media)) { + await recordUnreadableAudio(opts, media, log); + return "failed"; + } const start = Date.now(); log(`Diarize ${opts.videoId} start (${media})`); @@ -176,6 +195,9 @@ export async function diarizeOneVideo( await child; } catch (err) { log(`Diarize ${opts.videoId} failed: ${(err as Error).message}`); + if (!opts.signal?.aborted && isDecodeFailure(err)) { + await recordUnreadableAudio(opts, media, log); + } return "failed"; } @@ -193,3 +215,142 @@ export async function diarizeOneVideo( ); return "diarized"; } + +// --------------------------------------------------------------------------- +// Voiceprints for a sidecar that predates them. + +export type VoiceprintOneOutcome = + // diarization.json now carries a voiceprint per speaker. + | "voiceprinted" + // It already did. + | "already-present" + // No (valid) diarization.json: diarize it first. + | "no-diarization" + // The audio is gone: no fingerprint is possible any more. A fact to list, + // never an error. + | "no-audio" + // No embedding model configured. + | "not-configured" + // The audio is on disk but does not decode (recorded in audio-integrity.json). + | "unreadable" + | "failed"; + +// Add voiceprints to an existing diarization.json from its own turns: the +// embedder only (scripts/diarize.mjs --voiceprints-only), no segmentation and +// no re-clustering, so the turns, the engine and `generatedAt` are kept as they +// are (attribution-diarized's freshness names generatedAt). The same embedding +// model the sherpa engine clusters with, so these are the numbers a fresh +// diarization would have recorded. +export async function voiceprintOneVideo( + opts: DiarizeOneOptions, +): Promise<VoiceprintOneOutcome> { + const log = opts.onLog ?? ((m: string) => console.log(m)); + const cfg = opts.settings ?? getSettings().diarization; + if (!cfg.embModel) return "not-configured"; + const existing = await loadDiarization(opts.videoDir); + if (!existing) return "no-diarization"; + if (hasVoiceprints(existing)) return "already-present"; + const media = await resolveDiarizableMedia(opts.videoDir); + if (!media) return "no-audio"; + if (await isZeroByteAudio(opts.videoDir, media)) { + await recordUnreadableAudio(opts, media, log); + return "unreadable"; + } + const start = Date.now(); + log(`Voiceprints ${opts.videoId} start (${media})`); + try { + const child = execa( + opts.paths.diarizeBin, + [ + "--voiceprints-only", + DIARIZATION_FILENAME, + "--output", + DIARIZATION_FILENAME, + "--python", + cfg.python, + "--emb", + cfg.embModel, + "--threads", + String(cfg.threads), + "--ffmpeg", + opts.paths.ffmpegBin, + "--ffprobe", + opts.paths.ffprobeBin, + media, + ], + { cwd: opts.videoDir, cancelSignal: opts.signal, all: true, buffer: false }, + ); + child.all?.on("data", (c: Buffer) => log(c.toString("utf8").trimEnd())); + await child; + } catch (err) { + log(`Voiceprints ${opts.videoId} failed: ${(err as Error).message}`); + if (!opts.signal?.aborted && isDecodeFailure(err)) { + const verdict = await recordUnreadableAudio(opts, media, log); + if (verdict === "undecodable") return "unreadable"; + } + return "failed"; + } + // Trust the file: the same turns, the same generatedAt, voiceprints complete. + const after = await loadDiarization(opts.videoDir); + if ( + !after || + !hasVoiceprints(after) || + after.generatedAt !== existing.generatedAt || + after.turns.length !== existing.turns.length + ) { + log(`Voiceprints ${opts.videoId} produced no complete voiceprints — treating as failed.`); + return "failed"; + } + log( + `Voiceprints ${opts.videoId} done in ${((Date.now() - start) / 1000).toFixed(1)}s`, + ); + return "voiceprinted"; +} + +// The engine's "could not decode" exits: diarize-sherpa.py returns 4 when +// ffmpeg fails and 5 when it decodes zero samples, and diarize.mjs passes the +// code through. +function isDecodeFailure(err: unknown): boolean { + const code = (err as { exitCode?: number })?.exitCode; + return code === 4 || code === 5; +} + +async function isZeroByteAudio(videoDir: string, media: string): Promise<boolean> { + if (!isRealAudioFile(media)) return false; + const id = await fileIdentity(path.join(videoDir, media)).catch(() => null); + return id !== null && id.size === 0; +} + +// RECORD, THEN SKIP. An audio file the engine cannot decode gets a verdict in +// audio-integrity.json (keyed to the file's size and mtime), and the +// diarization operation reports a video whose held audio is `undecodable` as +// blocked — so the lane does not spend a pass on it every run, and a re-fetched +// file (a new size or mtime) is work again. Only a real audio file: a source +// container or a saved video is not this lane's to judge. +async function recordUnreadableAudio( + opts: DiarizeOneOptions, + media: string, + log: (m: string) => void, +): Promise<AudioIntegrityVerdict | null> { + if (!isRealAudioFile(media)) return null; + try { + const file = path.join(opts.videoDir, media); + const id = await fileIdentity(file); + const record = + id.size === 0 + ? integrityRecord(media, id, { decodedSeconds: 0, totalSeconds: 0, gaps: [] }, { by: "speakers" }) + : await measureAndRecordIntegrity( + opts.videoDir, + media, + { ffmpegBin: opts.paths.ffmpegBin, ffprobeBin: opts.paths.ffprobeBin, signal: opts.signal, lowPriority: true }, + { by: "speakers" }, + ); + if (!record) return null; + if (id.size === 0) await writeAudioIntegrity(opts.videoDir, record); + log(`${opts.videoId}/${media}: ${record.verdict} (${id.size} bytes) — recorded in audio-integrity.json.`); + return record.verdict; + } catch (err) { + log(`${opts.videoId}/${media}: could not record its integrity: ${(err as Error).message}`); + return null; + } +} diff --git a/common/lib/audioIntegrity.ts b/common/lib/audioIntegrity.ts @@ -51,8 +51,9 @@ export type AudioIntegrityRecord = { verdict: AudioIntegrityVerdict; // What measured it: the scan's own version and ffmpeg's `-version` line. tool: { scan: string; ffmpeg?: string }; - // Who wrote it: the audit job, or the refetch that replaced the file. - by: "audit" | "refetch"; + // Who wrote it: the audit job, the refetch that replaced the file, or the + // speakers lane after its engine could not decode the file (diarizeOne). + by: "audit" | "refetch" | "speakers"; jobId?: string; }; diff --git a/common/lib/operations.test.ts b/common/lib/operations.test.ts @@ -2,7 +2,8 @@ import { test } from "node:test"; import assert from "node:assert/strict"; import path from "node:path"; import os from "node:os"; -import { mkdtemp, mkdir, writeFile, rm, utimes } from "node:fs/promises"; +import { mkdtemp, mkdir, writeFile, rm, stat, utimes } from "node:fs/promises"; +import { AUDIO_INTEGRITY_FILENAME } from "./audioIntegrity"; import { getOperation, allOperations, @@ -119,6 +120,8 @@ async function fixture(opts: { // Written into metadata.info.json. Absent means NO metadata file at all, // which is the "duration unknown" case the cap has to get right. durationSec?: number; + // An audio-integrity.json verdict on audio.mp3. + integrity?: "undecodable" | "clean"; }): Promise<{ dir: string; cleanup: () => Promise<void> }> { const root = await mkdtemp(path.join(os.tmpdir(), "backfill-kinds-")); const dir = path.join(root, "vid1"); @@ -150,16 +153,41 @@ async function fixture(opts: { JSON.stringify({ id: "vid1", duration: opts.durationSec }), ); } + if (opts.integrity) { + // A verdict ON audio.mp3 as it is on disk (its size and mtime). + const st = await stat(path.join(dir, "audio.mp3")); + await writeFile( + path.join(dir, AUDIO_INTEGRITY_FILENAME), + JSON.stringify({ + version: 1, checkedAt: "now", file: "audio.mp3", size: st.size, mtime: Math.floor(st.mtimeMs), + durationSeconds: opts.integrity === "undecodable" ? null : 1, + decodedSeconds: opts.integrity === "undecodable" ? 0 : 1, + gaps: [], verdict: opts.integrity, tool: { scan: "x" }, by: "speakers", + }), + ); + } return { dir, cleanup: () => rm(root, { recursive: true, force: true }) }; } -function sidecar(engine: DiarizationRecord["engine"]): string { +// A COMPLETE record by default — turns and the voice fingerprints a sidecar is +// written with today. `voiceprints: false` is one written before they existed. +function sidecar( + engine: DiarizationRecord["engine"], + { voiceprints = true }: { voiceprints?: boolean } = {}, +): string { return JSON.stringify({ videoId: "vid1", generatedAt: "2026-08-07T00:00:00.000Z", speakers: 2, turns: [{ start: 0, end: 4, speaker: 0 }], engine, + ...(voiceprints + ? { + voiceprints: [ + { speaker: 0, seconds: 4, embedded: 1, centroid: [0.6, 0.8], embeddingModel: "emb-1.onnx" }, + ], + } + : {}), } satisfies DiarizationRecord); } @@ -201,6 +229,52 @@ test("present: the sidecar matches the identity we would produce now", async () assert.equal(await classify({ sidecar: sidecar(CURRENT) }), "present"); }); +test("partial: fresh turns without voice fingerprints, while the audio is still here", async () => { + assert.equal( + await classify({ audio: true, sidecar: sidecar(CURRENT, { voiceprints: false }) }), + "partial", + ); + // A persisted container is input enough for the voiceprint step too. + assert.equal( + await classify({ container: true, sidecar: sidecar(CURRENT, { voiceprints: false }) }), + "partial", + ); +}); + +test("present: without fingerprints once the audio is gone — none is possible, and it is not work", async () => { + assert.equal(await classify({ sidecar: sidecar(CURRENT, { voiceprints: false }) }), "present"); +}); + +test("present: without fingerprints when no embedding model is configured (a sortformer setup)", async () => { + assert.equal( + await classify( + { audio: true, sidecar: sidecar({ engine: "sortformer", model: "sf.gguf" }, { voiceprints: false }) }, + settingsWithDiarization({ engine: "sortformer", sortformerModel: "/m/sf.gguf", embModel: "" }), + ), + "present", + ); +}); + +test("blocked: held audio the engine could not decode is recorded and skipped, not offered every pass", async () => { + assert.equal(await classify({ audio: true, integrity: "undecodable" }), "blocked"); + assert.equal( + await classify({ audio: true, integrity: "undecodable", sidecar: sidecar(CURRENT, { voiceprints: false }) }), + "present", + ); + // A clean verdict changes nothing. + assert.equal(await classify({ audio: true, integrity: "clean" }), "missing"); +}); + +test("the diarization unit ships an existing sidecar, so a unit executor can add its voiceprints", async () => { + const { dir, cleanup } = await fixture({ audio: true, sidecar: sidecar(CURRENT, { voiceprints: false }), durationSec: 9 }); + try { + const files = await readVideoFiles(dir, { checkUntranscribable: true }); + assert.deepEqual(diarization.inputs(files), [META_FILENAME, DIARIZATION_FILENAME, "audio.mp3"]); + } finally { + await cleanup(); + } +}); + test("stale: a different threshold or model is work, not coverage", async () => { // The threshold is the single most consequential knob (it decides how many // speakers come out), so a change to it MUST show as work. Before the diff --git a/common/lib/operations.ts b/common/lib/operations.ts @@ -106,6 +106,7 @@ import type { DigestContext } from "./digestContext-server"; import { SORTFORMER_DIARIZATION_ENGINE, diarizationTarget, + hasVoiceprints, isDiarizationFresh, type DiarizationBackend, type DiarizationEngineId, @@ -113,6 +114,8 @@ import { type DiarizationRecord, } from "./diarization"; import { loadDiarization, writeDiarization } from "./diarization-server"; +import { AUDIO_INTEGRITY_FILENAME } from "./audioIntegrity"; +import { heldAudioDamage } from "./audioIntegrity-server"; import { ATTRIBUTION_FILENAME, isAttributionDowngrade, @@ -702,11 +705,26 @@ const diarization: Operation = { // diarization-server.ts treats it: a half-written sidecar must never be // what convinces anything the work is done. if (record) { - return isDiarizationFresh(record, target as DiarizationFreshnessTarget) - ? "present" - : "stale"; + if (!isDiarizationFresh(record, target as DiarizationFreshnessTarget)) { + return "stale"; + } + if (hasVoiceprints(record) || !settings.diarization.embModel) { + return "present"; + } + // Fresh turns WITHOUT voice fingerprints: PARTIAL while the audio is + // still here (diarizeOneVideo's voiceprint step adds them from the same + // turns, seconds of work), present once it is gone — no fingerprint is + // possible then, which the speakers readout lists, and nothing this + // lane can do about it. + return (await hasDiarizableInput(videoDir, files)) && + !(await heldAudioUndecodable(videoDir, files)) + ? "partial" + : "present"; } } + // Audio this lane's engine could not decode, recorded against the file + // (audio-integrity.json): not work until a different file is there. + if (await heldAudioUndecodable(videoDir, files)) return "blocked"; if (!(await hasDiarizableInput(videoDir, files))) { // Read the cap here ONLY when this branch can dispatch a download: with // re-download armed, missing-input is a fetch, and diarizeOneVideo does not @@ -760,6 +778,9 @@ const diarization: Operation = { inputs(files) { const out: string[] = []; if (files.entries.includes(META_FILENAME)) out.push(META_FILENAME); + // The existing sidecar travels too: a fresh one without voiceprints is a + // voiceprint step (its own turns, re-embedded), not a re-diarization. + if (files.hasDiarization) out.push(DIARIZATION_FILENAME); const audio = pickPreferredAudio(files.audioFiles) ?? findSourceMedia(files.entries); if (audio) out.push(audio); @@ -786,6 +807,19 @@ async function hasDiarizableInput( return (await resolveSavedVideo(videoDir)) !== null; } +// Is the audio diarization would read known to be undecodable? Answered from +// the listing first: only a dir holding audio-integrity.json pays a read. +async function heldAudioUndecodable( + videoDir: string, + files: VideoFiles, +): Promise<boolean> { + if (!files.entries.includes(AUDIO_INTEGRITY_FILENAME)) return false; + const preferred = pickPreferredAudio(files.audioFiles); + if (!preferred) return false; + const damage = await heldAudioDamage(videoDir, files.entries); + return damage?.file === preferred && damage.record.verdict === "undecodable"; +} + // Is this video longer than the diarization duration cap? // // THE CAP IS OFF BY DEFAULT NOW — windowed diarization removed the OOM it