commit c544c0dd61f17d1929f05f7f7d9b5899bc40018a
parent a5a1ccf63f49b7f16800fbe09485e2ed4ea19624
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Thu, 15 Oct 2026 17:06:17 -0400
common: a salvage that finds nothing missing is a clean transcript (release 30 lane Q2) — a corrupt-full-source video whose kept file was replaced by a clean one outside the managed download is still salvaged automatically (its sidecar says so), and the decode then finds no gap; transcribe-outcome.json records `salvaged` only when something did not decode or a window could not be transcribed, so such a transcript stays out of salvagedTranscript; the gaps are reckoned once, after the engine, from the decode's and the failed windows'
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
2 files changed, 72 insertions(+), 32 deletions(-)
diff --git a/common/controller/transcribeOne.ts b/common/controller/transcribeOne.ts
@@ -30,6 +30,7 @@ import {
mergeGaps,
salvageDecode,
type SalvageGap,
+ type SalvageResult,
} from "../lib/salvageAudio-server";
import { writeFileAtomic } from "../lib/jsonFile-server";
import { probeMedia } from "../lib/evidenceClip-server";
@@ -263,14 +264,13 @@ async function transcribeResolved(
const transcriptPath = path.join(opts.videoDir, "transcript.json");
// What the engine reads: the resolved audio, or its salvage WAV.
let engineAudio = resolvedAudio;
- let salvaged: TranscriptSalvage | null = null;
+ let scan: SalvageResult | null = null;
if (salvage) {
log(
`Salvage: decoding ${resolvedAudio} with error tolerance — undecodable spans become silence on the recording's clock.`,
);
- let r;
try {
- r = await salvageDecode(
+ scan = await salvageDecode(
path.join(opts.videoDir, resolvedAudio),
path.join(opts.videoDir, SALVAGE_WAV_FILENAME),
{
@@ -287,14 +287,8 @@ async function transcribeResolved(
"transcription",
);
}
- log(`Salvage: ${describeSalvage(r)}.`);
+ log(`Salvage: ${describeSalvage(scan)}.`);
engineAudio = SALVAGE_WAV_FILENAME;
- salvaged = {
- source: resolvedAudio,
- decodedSeconds: r.decodedSeconds,
- totalSeconds: r.totalSeconds,
- gaps: r.gaps,
- };
}
const worker = opts.worker;
@@ -425,20 +419,27 @@ async function transcribeResolved(
// sidecar write must not fail an otherwise-successful transcription (the build
// falls back to the transcript file mtime when the sidecar is absent).
// A salvage's gaps: what did not decode, and any window the engine could
- // not transcribe (parakeet --salvage). Decoded seconds never claim a gap.
- if (salvaged) {
+ // not transcribe (parakeet --salvage). A file that decoded whole with every
+ // window transcribed (a corrupt full source whose kept file was replaced by
+ // a clean one outside the managed download) made a clean transcript, and is
+ // not recorded as a salvage. Decoded seconds never claim a gap.
+ let salvaged: TranscriptSalvage | null = null;
+ if (scan) {
const failed = await failedWindowsOf(transcriptPath);
if (failed.length > 0) {
log(`Salvage: ${failed.length} window(s) could not be transcribed; recorded as gaps.`);
- const gaps = mergeGaps([...salvaged.gaps, ...failed]);
+ }
+ const gaps = mergeGaps([...scan.gaps, ...failed]);
+ if (gaps.length > 0 || scan.decodedSeconds < scan.totalSeconds - 1) {
+ const covered = Math.max(0, Math.round((scan.totalSeconds - gapSeconds(gaps)) * 1000) / 1000);
salvaged = {
- ...salvaged,
+ source: resolvedAudio,
+ decodedSeconds: Math.min(scan.decodedSeconds, covered),
+ totalSeconds: scan.totalSeconds,
gaps,
- decodedSeconds: Math.min(
- salvaged.decodedSeconds,
- Math.max(0, Math.round((salvaged.totalSeconds - gapSeconds(gaps)) * 1000) / 1000),
- ),
};
+ } else {
+ log(`Salvage: ${resolvedAudio} decodes whole; the transcript is a clean one.`);
}
}
try {
diff --git a/common/controller/transcribeSalvage.test.ts b/common/controller/transcribeSalvage.test.ts
@@ -29,6 +29,7 @@ const tools = hasFfmpeg();
let ROOT = "";
let VIDEO_DIR = "";
let DAMAGED = "";
+let CLEAN = "";
const SLUG = "tones";
const ID = "vid1";
@@ -54,8 +55,8 @@ process.stdout.write(JSON.stringify({ words }));
if (!tools) return;
VIDEO_DIR = path.join(process.env.TRANSCRIPTS_DIR, "channels", SLUG, "data", ID);
await mkdir(VIDEO_DIR, { recursive: true });
- const clean = makeToneFile(path.join(ROOT, "clean.mp4"));
- DAMAGED = corruptBytes(clean, path.join(VIDEO_DIR, "audio.mp4"));
+ CLEAN = makeToneFile(path.join(ROOT, "clean.mp4"));
+ DAMAGED = corruptBytes(CLEAN, path.join(VIDEO_DIR, "audio.mp4"));
await writeFile(
path.join(VIDEO_DIR, "metadata.info.json"),
JSON.stringify({ id: ID, title: "Tones", duration: 30, upload_date: "20260105", webpage_url: "https://example.invalid/v/vid1" }),
@@ -75,6 +76,19 @@ after(() => rm(ROOT, { recursive: true, force: true }));
const near = (a: number, b: number, tol = 0.06) => Math.abs(a - b) <= tol;
+// A model file must exist; the fake CLI never reads it. 20 s windows with the
+// default 6 s overlap: the 30 s recording is two windows, so the stitch's
+// offsets are exercised too.
+const worker = () => ({
+ id: "w1",
+ name: "fake parakeet",
+ kind: "local" as const,
+ enabled: true,
+ priority: 0,
+ appId: "parakeet",
+ config: { model: CLEAN, chunkSize: 20 },
+});
+
test(
"a corrupt full source is salvaged: cues on the recording's clock, the gap recorded, the WAV gone",
{ skip: !tools && "ffmpeg/ffprobe not installed" },
@@ -88,18 +102,7 @@ test(
videoDir: VIDEO_DIR,
videoId: ID,
audioFilename: "audio.mp4",
- worker: {
- id: "w1",
- name: "fake parakeet",
- kind: "local",
- enabled: true,
- priority: 0,
- appId: "parakeet",
- // A model file must exist; the fake CLI never reads it. 20 s windows
- // with the default 6 s overlap: the 30 s recording is two windows, so
- // the stitch's offsets are exercised too.
- config: { model: DAMAGED, chunkSize: 20 },
- },
+ worker: worker(),
onLog: (l) => lines.push(l),
skipInlineDiarization: true,
});
@@ -135,3 +138,39 @@ test(
assert.ok(existsSync(path.join(VIDEO_DIR, "audio.mp4")));
},
);
+
+test(
+ "a file that decodes whole makes a clean transcript: nothing recorded as salvaged",
+ { skip: !tools && "ffmpeg/ffprobe not installed" },
+ async () => {
+ // The kept file was replaced by a clean one outside the managed download;
+ // the sidecar still says corrupt-full-source, so salvage runs — and finds
+ // nothing missing.
+ const { transcribeOneVideo } = await import("./transcribeOne");
+ const { getPaths } = await import("../lib/paths");
+ const dir = path.join(path.dirname(VIDEO_DIR), "vid2");
+ await mkdir(dir, { recursive: true });
+ await writeFile(path.join(dir, "audio.mp4"), await readFile(CLEAN));
+ await writeFile(path.join(dir, "metadata.info.json"), JSON.stringify({ id: "vid2", title: "Tones", duration: 30 }));
+ await writeFile(
+ path.join(dir, "download-outcome.json"),
+ JSON.stringify({ videoId: "vid2", status: "corrupt-full-source", startedAt: "x", finishedAt: "x", attempts: [] }),
+ );
+ const lines: string[] = [];
+ const outcome = await transcribeOneVideo({
+ paths: getPaths(),
+ videoDir: dir,
+ videoId: "vid2",
+ audioFilename: "audio.mp4",
+ worker: worker(),
+ onLog: (l) => lines.push(l),
+ skipInlineDiarization: true,
+ });
+ assert.equal(outcome, "transcribed", lines.join("\n"));
+ assert.match(lines.join("\n"), /decodes whole; the transcript is a clean one/);
+ const record = JSON.parse(await readFile(path.join(dir, "transcribe-outcome.json"), "utf8"));
+ assert.equal(record.salvaged, undefined);
+ const transcript = JSON.parse(await readFile(path.join(dir, "transcript.json"), "utf8"));
+ assert.equal(transcript.chunk_data.length, burstTimes().length);
+ },
+);