Archilyzer · Source

archilyzer

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

commit e3eb8fbefcc8300ddd2f7ec3ba11d6860e944f5d
parent 7dbef189b7838126822a20b2017ab65013004cb2
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 11 Nov 2026 04:55:18 -0500

diarization: a voiceprint-step refusal (exit 6: duration not the record's, a short excerpt, a long-turned speaker with no centroid) is recorded on the sidecar as voiceprintsRefused {file, size, mtime, reason, at}, and the operation reports that video blocked -- "no fingerprint possible from this file: <reason>" -- until a different file is there, instead of retrying once per runner session; the audio stays held

Keyed to the audio file as it was (name, size, floored mtime), as
audio-integrity.json keys exits 4/5; not an integrity verdict -- the file
decodes, it is just not these turns' audio. turns and generatedAt are kept. A
later successful voiceprint step (a different file) drops the refusal.
Tests: the controller records it from the engine's own sentence; the operation
reads blocked for the same file and partial for a changed one; diarize.mjs
drops a stale refusal on success.

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

Diffstat:
Mcommon/controller/diarizeOne.test.ts | 29+++++++++++++++++++++++++++++
Mcommon/controller/diarizeOne.ts | 33+++++++++++++++++++++++++++++++--
Mcommon/lib/diarization.ts | 17+++++++++++++++++
Mcommon/lib/operations.test.ts | 23+++++++++++++++++++++++
Mcommon/lib/operations.ts | 19+++++++++++++++----
Mscripts/diarize-sherpa.test.mjs | 11+++++++++++
Mscripts/diarize.mjs | 4+++-
7 files changed, 129 insertions(+), 7 deletions(-)

diff --git a/common/controller/diarizeOne.test.ts b/common/controller/diarizeOne.test.ts @@ -24,6 +24,7 @@ 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_STDERR) process.stderr.write(process.env.FAKE_STDERR + "\\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")); @@ -155,3 +156,31 @@ test("the voiceprint step never falls back to a source container: with no audio, await t.cleanup(); } }); + +test("an exit-6 refusal is recorded against the file (voiceprintsRefused), turns and generatedAt kept, no voiceprints", async () => { + const t = await setup(); + process.env.FAKE_EXIT = "6"; + process.env.FAKE_STDERR = "diarize-sherpa: refused: the file is 99.000s, the record's audio 10s — not the audio these turns were made from"; + try { + const logs: string[] = []; + assert.equal( + await voiceprintOneVideo({ paths: t.paths, videoDir: t.videoDir, videoId: "vid1", settings: t.settings, onLog: (m) => logs.push(m) }), + "refused", + ); + const rec = await loadDiarization(t.videoDir); + assert.equal(rec?.generatedAt, EXISTING.generatedAt); + assert.deepEqual(rec?.turns, EXISTING.turns); + assert.equal(hasVoiceprints(rec), false); + assert.equal(rec?.voiceprintsRefused?.file, "audio.mp3"); + assert.equal(rec?.voiceprintsRefused?.size, "not really mp3".length); + assert.match(rec?.voiceprintsRefused?.reason ?? "", /^the file is 99\.000s/); + assert.ok(logs.some((l) => l.includes("no fingerprint possible from this file: the file is 99.000s"))); + // Not an integrity verdict: the audio decodes, it is just not these turns'. + assert.equal(await loadAudioIntegrity(t.videoDir), null); + } finally { + delete process.env.FAKE_EXIT; + delete process.env.FAKE_STDERR; + await t.cleanup(); + } +}); + diff --git a/common/controller/diarizeOne.ts b/common/controller/diarizeOne.ts @@ -23,7 +23,7 @@ import { hasVoiceprints, isDiarizationFresh, } from "../lib/diarization"; -import { hasDiarization, loadDiarization } from "../lib/diarization-server"; +import { hasDiarization, loadDiarization, writeDiarization } from "../lib/diarization-server"; import { findSourceMedia, isRealAudioFile } from "../lib/videoStatus"; import { fileIdentity, @@ -233,6 +233,9 @@ export type VoiceprintOneOutcome = | "not-configured" // The audio is on disk but does not decode (recorded in audio-integrity.json). | "unreadable" + // The engine refused this file for these turns (exit 6), recorded on the + // sidecar as voiceprintsRefused: no fingerprint possible from it. + | "refused" | "failed"; // Add voiceprints to an existing diarization.json from its own turns: the @@ -264,6 +267,7 @@ export async function voiceprintOneVideo( } const start = Date.now(); log(`Voiceprints ${opts.videoId} start (${media})`); + const output: string[] = []; try { const child = execa( opts.paths.diarizeBin, @@ -286,10 +290,27 @@ export async function voiceprintOneVideo( ], { cwd: opts.videoDir, cancelSignal: opts.signal, all: true, buffer: false }, ); - child.all?.on("data", (c: Buffer) => log(c.toString("utf8").trimEnd())); + child.all?.on("data", (c: Buffer) => { + const text = c.toString("utf8").trimEnd(); + output.push(text); + log(text); + }); await child; } catch (err) { log(`Voiceprints ${opts.videoId} failed: ${(err as Error).message}`); + if (!opts.signal?.aborted && (err as { exitCode?: number })?.exitCode === 6) { + const reason = refusalReason(output.join("\n")); + const id = await fileIdentity(path.join(opts.videoDir, media)).catch(() => null); + const current = await loadDiarization(opts.videoDir); + if (id && current) { + await writeDiarization(opts.videoDir, { + ...current, + voiceprintsRefused: { file: media, size: id.size, mtime: id.mtime, reason, at: new Date().toISOString() }, + }); + } + log(`${opts.videoId}: no fingerprint possible from this file: ${reason}`); + return "refused"; + } if (!opts.signal?.aborted && isDecodeFailure(err)) { const verdict = await recordUnreadableAudio(opts, media, log); if (verdict === "undecodable") return "unreadable"; @@ -313,6 +334,14 @@ export async function voiceprintOneVideo( return "voiceprinted"; } +// The engine's own sentence for an exit-6 refusal ("diarize-sherpa: refused: +// <why>"), or a generic one. +function refusalReason(output: string): string { + const lines = output.split("\n").filter((l) => l.includes("refused:")); + const last = lines[lines.length - 1]; + return last ? last.slice(last.indexOf("refused:") + "refused:".length).trim() : "the engine refused this file"; +} + // 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. diff --git a/common/lib/diarization.ts b/common/lib/diarization.ts @@ -99,8 +99,25 @@ export type DiarizationRecord = { // voiceprint step only ever uses the video's own extracted audio — never a // source container or a saved video, whose clock can differ (review B3). voiceprintsFrom?: { file: string; bytes?: number; durationSeconds?: number }; + // The voiceprint step REFUSED this audio file (scripts/diarize-sherpa.py + // exit 6: its duration is not the record's, an excerpt came back short, or a + // speaker with long turns got no embedding). Keyed to the file as it was + // (name, size, floored mtime): while that file is the one on disk, no + // fingerprint is possible from it, and the diarization operation reports the + // video blocked rather than retrying it every runner session. A different + // file (a re-download) is work again. The audio stays held either way. + voiceprintsRefused?: { file: string; size: number; mtime: number; reason: string; at: string }; }; +// PURE: does this refusal still speak for the file on disk? +export function voiceprintsRefusedFor( + record: Pick<DiarizationRecord, "voiceprintsRefused"> | null, + file: { name: string; size: number; mtime: number }, +): boolean { + const r = record?.voiceprintsRefused; + return !!r && r.file === file.name && r.size === file.size && r.mtime === Math.floor(file.mtime); +} + // A speaker cluster's voice fingerprint. `centroid` is the L2-normalised mean // TitaNet-small embedding (VOICEPRINT_DIM floats, rounded to 4 decimals) of the // speaker's longest turns, outliers trimmed as voiceMatch's robustCentroid does; diff --git a/common/lib/operations.test.ts b/common/lib/operations.test.ts @@ -277,6 +277,29 @@ test("the diarization unit ships an existing sidecar, so a unit executor can add } }); +test("blocked: the voiceprint step refused THIS audio file (exit 6); a different file is work again", async () => { + const { dir, cleanup } = await fixture({ audio: true }); + try { + const st = await stat(path.join(dir, "audio.mp3")); + const refused = (size: number) => + JSON.stringify({ + ...JSON.parse(sidecar(CURRENT, { voiceprints: false })), + voiceprintsRefused: { file: "audio.mp3", size, mtime: Math.floor(st.mtimeMs), reason: "duration differs", at: "now" }, + }); + const settings = settingsWithDiarization(); + const target = await diarization.resolveTarget(targetCtx(settings)); + const classifyHere = async () => + diarization.state({ videoDir: dir, videoId: "vid1", files: await readVideoFiles(dir, { checkUntranscribable: true }), target, settings }); + await writeFile(path.join(dir, DIARIZATION_FILENAME), refused(st.size)); + assert.equal(await classifyHere(), "blocked"); + // The file on disk is another one now (a re-download): partial again. + await writeFile(path.join(dir, DIARIZATION_FILENAME), refused(st.size + 100)); + assert.equal(await classifyHere(), "partial"); + } 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 @@ -72,6 +72,8 @@ // because it is what keeps them apart if they are ever added: `inline` folds // into an existing pass and `lane` gets the concurrent queue and the share. +import path from "node:path"; +import { stat } from "node:fs/promises"; import type { Paths } from "./paths"; import type { AttributionSettings, @@ -109,6 +111,7 @@ import { hasVoiceprints, isDiarizationFresh, voiceprintsPossible, + voiceprintsRefusedFor, type DiarizationBackend, type DiarizationEngineId, type DiarizationFreshnessTarget, @@ -722,10 +725,18 @@ const diarization: Operation = { // container or a saved video, review B3); present once it is gone — no // fingerprint is possible then, which the speakers readout lists, and // nothing this lane can do about it. - return files.audioFiles.length > 0 && - !(await heldAudioUndecodable(videoDir, files)) - ? "partial" - : "present"; + if (files.audioFiles.length === 0) return "present"; + // The voiceprint step refused this very file (exit 6, recorded on the + // sidecar): "no fingerprint possible from this file: <reason>" — + // blocked until a different file is there, not retried every session. + if (record.voiceprintsRefused) { + const name = pickPreferredAudio(files.audioFiles); + const st = name ? await stat(path.join(videoDir, name)).catch(() => null) : null; + if (name && st && voiceprintsRefusedFor(record, { name, size: st.size, mtime: st.mtimeMs })) { + return "blocked"; + } + } + return (await heldAudioUndecodable(videoDir, files)) ? "present" : "partial"; } } // Audio this lane's engine could not decode, recorded against the file diff --git a/scripts/diarize-sherpa.test.mjs b/scripts/diarize-sherpa.test.mjs @@ -287,3 +287,14 @@ test("voiceprints-only refuses when a speaker with long turns gets no embedding, assert.ok(notReady.voiceprints.every((v) => v.centroid === null)); })); +test("a voiceprint step that succeeds drops a refusal recorded against an earlier file", { skip }, () => + withDir((dir) => { + const wav = path.join(dir, "a.wav"); + writeWav(wav, PLAN); + const r = vpOnly(dir, wav, base({ voiceprintsRefused: { file: "audio.mp3", size: 1, mtime: 1, reason: "old", at: "x" } })); + assert.equal(r.status, 0); + const after = JSON.parse(readFileSync(path.join(dir, "diarization.json"), "utf8")); + assert.equal("voiceprintsRefused" in after, false); + assert.equal(after.voiceprints.length, 2); + })); + diff --git a/scripts/diarize.mjs b/scripts/diarize.mjs @@ -228,8 +228,10 @@ async function runVoiceprintsOnly() { // Everything already on the record stays as it was -- generatedAt above // all: attribution-diarized's freshness names it, so touching it would make // every name already put to these clusters stale for no change in them. + // A refusal recorded against an earlier file is answered by these. + const { voiceprintsRefused: _refused, ...kept } = existing; const record = { - ...existing, + ...kept, voiceprints, voiceprintsAt: new Date().toISOString(), voiceprintsMs: Date.now() - started,