Archilyzer · Source

archilyzer

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

commit 718ec5322becd2d807a48d9de38c2080e1a4d710
parent 73217bef8d6a32bbdb6566931f34977053b05b3e
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Fri, 16 Oct 2026 08:07:06 -0400

plans: release 31 lane A, as shipped — the audio-integrity audit (plans/release-31/audio-audit.md), FACTS

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Mplans/FACTS.md | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aplans/release-31/audio-audit.md | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 121 insertions(+), 0 deletions(-)

diff --git a/plans/FACTS.md b/plans/FACTS.md @@ -9824,3 +9824,57 @@ parsed to 0 cues, indexing the video textless) is CLOSED by `200a3105` (transcri `get_video_metadata` adds a `- copies:` line (`copiesIndex`: a mirror video's status and the creator's strong matches; a creator video held by a mirror, and whether it is gone); `enumerate_matches` `copies: "only-here"` restricts the scan to the only-copy mirror videos by id (to the mirror channels unless the call scopes itself). + +## Release 31 lane A: the audio-integrity audit (verified 2026-10-16, branch `r31/audio-audit`) + +- **`channels/<slug>/data/<id>/audio-integrity.json`** (declared with `sidecar()` in `lib/audioIntegrity-server.ts`; + types and the rule in `lib/audioIntegrity.ts`) — TEXT, never published: `{version: 1, checkedAt, file, size, mtime + (epoch ms, floored), durationSeconds (container, or null), decodedSeconds, gaps: [[from, to], …], verdict: clean | + damaged | undecodable, tool: {scan: "scanDecodable/1", ffmpeg?}, by: audit | refetch, jobId?}`. It speaks for ONE + file: the record is stale when the named file is gone or its size (or, where the reader has it, mtime) differs. + Written only by `measureAndRecordIntegrity` (the audit and the refetch's re-audit); nothing is written when ffmpeg + could not run or the file changed during the decode. +- **The rule** (`integrityVerdict`, `AUDIO_INTEGRITY_MIN_DECODED_RATIO` = 0.98): nothing decodes → undecodable; any + listed gap (holes ≥ 0.5 s after merging, the tail to the container's duration included) or under 98 % of the + container's duration decoded → damaged; else clean. Readers recompute it from the numbers (`isDamagedIntegrity`), + not from `verdict`. +- **The job**: kind `audio-audit` (`needsMedia`, not replayable), ONE PER CHANNEL, every one on queue `audio-audit` + (`AUDIO_AUDIT_QUEUE`) — one file decoded at a time machine-wide; `pnpm ops audio-audit {slug | platform, scope?: + untranscribed (default: no transcript, `isVideoTranscribed`) | all, max? (files across the whole request — a shared + counter, exact because the jobs run in turn), force?}` → `{jobIds, channels, refused}` (409 when none started). + `platform` = `channelPlatform(config)`. The file audited is `pickPreferredAudio` of the real audio files; a video + whose outcome is corrupt-full-source is left out (counted `corruptFullSource`). The decode is `scanDecodable` with + `lowPriority` (`ionice -c3` when on PATH + `os.setPriority(pid, 19)`; only this caller asks). Resume: a file whose + record matches name+size+mtime is `fresh` (skipped) unless `force`. Before each file the storage watch's verdict + (`channelMediaStall`, no I/O) and the file's stat through `onDrive` (when the channel has a `mediaDir`); a stall + ends the channel's job FAILED with "The media drive of "<slug>" (location "<label>") is not answering since …". + Each decode has a deadline of 60 s + 0.1 s per audio second (metadata duration, else size at 8 kB/s); two in a row + missed end the job failed too. The job asks `ffmpeg -version` first and fails without it (a missing ffmpeg under + ionice would otherwise read as "nothing decodes"). Progress metric `files`. Log ends `@@audio-audit {slug, scope, + held, fresh, planned, checked, clean, damaged, undecodable, unmeasured, timedOut, corruptFullSource, stopped?}`. +- **Snapshot bucket `corruptHeldAudio`** (`controller/channelSnapshot.ts`, after the corrupt-full-source + short-circuit): a dir with the sidecar whose record names one of its real audio files, matches that file's lstat'd + size (`audioSizes`; an unknown size counts the name) and is damaged — and the video has NO transcript, or a SALVAGE + one. Untranscribed members are short-circuited out of downloadedNoTranscript and wrongFormatAudio (the lane does not + transcribe them; a retry first). A damaged file under any other transcript is in no bucket (/review lists it). + `ReplayBucket`; channel flow siding "damaged held audio" (download); Download stage card **Damaged held audio** + (`retry damaged held audio bucket`, items `damaged held audio <id>`); attention chip; the video list's download dot + (row `corruptHeldAudio`, status `downloaded_no_transcript`). +- **The refetch's second trigger** (`ytdlp/corruptRefetch.ts`): `prepareCorruptRefetch` → `trigger: + "damaged-held-audio"` when the outcome is not corrupt-full-source and `heldAudioDamage(videoDir)` (record matches + name+size+mtime, damaged) — same aside/settle. `previous` may be null. Failed → the previous record (status kept, + e.g. `ok`) with the attempts and the retry appended, or with none the download's own record + `corruptRefetches`; + the file renamed back keeps size+mtime, so the record matches again. Clean / still-malformed → the kept file is + re-audited (`by: "refetch"`; also for a corrupt full source that carries a record). `CorruptRefetch.trigger: + "damaged-held-audio"`. `downloadOneManaged` turns `audioCheck` on for that refetch on a transcribe-handling channel + without it. Retry prefilter: `destinationExists(…, {refetchDamagedAudio: true})` (retry-bucket passes it for every + bucket, beside `refetchCorruptFullSource`). Log prefix "Damaged held audio:". +- **Leftovers rule changed for both triggers**: an `.corrupt-kept` is removed as "the download since was clean" only + when the record is ok* AND its `finishedAt` is at or after the aside's ctime (the rename's); an older ok record + restores it. The unsettled-failure rewrite to corrupt-full-source is skipped when the audit record names the aside. +- **Salvage**: `transcribeOne`'s automatic salvage also fires when `heldAudioDamage` names the very file being read. +- **/review's media scan** (`scanCorruptMedia`) reads the sidecar per dir: a matching record rides on the finding as + `audit: {verdict, decodedSeconds, durationSeconds, gaps (count), checkedAt}`; a file tier 1 reads as fine (and the + right length) whose record is damaged is a finding of verdict `damaged` (totals `damaged?`). No decode for it. +- **e2e fixtures**: `fake-ffmpeg.mjs` answers `-version`, and `-f framecrc pipe:1` with 100 frames over fake-ffprobe's + duration (`__DUR=<s>__`, else 100000) — half of it for a file carrying `__CORRUPT__`. diff --git a/plans/release-31/audio-audit.md b/plans/release-31/audio-audit.md @@ -0,0 +1,67 @@ +# Release 31, lane A — the audio-integrity audit (as shipped) + +Branch `r31/audio-audit` from `main` `3ef1b558` (`main` `c9ec3bc8` and then `1ed16ffc` — lanes C, P3, D — merged in +before the final gates). Brief: `r31a-brief.md` (the plan of record for this lane). FACTS: "Release 31 lane A: the +audio-integrity audit". + +## What and why + +Only a download that went through the audio check is ever classified (release 30 Q's `corrupt-full-source`). Audio +held from before the check, or from a channel without it, was never checked; the media scan on /review read +containers, fed no bucket and no refetch. This lane measures what is on disk and routes the damage into Q's refetch. + +- **`audio-integrity.json`** (`lib/audioIntegrity.ts`, `lib/audioIntegrity-server.ts`, declared with `sidecar()`): + one record per video dir, for one file (name, size, mtime); verdict clean | damaged | undecodable by + `integrityVerdict` (`AUDIO_INTEGRITY_MIN_DECODED_RATIO` 0.98, or any listed gap). +- **The job** (`controller/audioAudit.ts`): `pnpm ops audio-audit {slug | platform, scope?, max?, force?}` → one + `audio-audit` job per channel (`needsMedia`) on the `audio-audit` queue, so one file is decoded at a time + machine-wide; the decode is `scanDecodable` with the new `lowPriority` (`ionice -c3` when on PATH, nice 19 by + `os.setPriority`; only this caller asks). Resumable by name+size+mtime; `max` a counter shared by the run's jobs; + corrupt full sources left to Q. Stall-aware: `channelMediaStall` before each file, the stat through `onDrive`, a + deadline per decode (60 s + 0.1 s per audio second), two missed in a row stop the job; a stop by the drive fails + the job with the sentence. `ffmpeg -version` first (refused without it). Log ends `@@audio-audit {…}`. +- **Bucket `corruptHeldAudio`** in the one classifier (`channelSnapshot.ts`, after the corrupt-full-source + short-circuit): damaged held audio with no transcript (short-circuited out of downloadedNoTranscript and the + wrong-format sweep) or a salvage transcript. Normalized in `stageStatus`, a download siding in `channelFlow`, the + Download stage's **Damaged held audio** card with the bucket's Retry, an attention chip, the video list's dot. +- **The retry** (`ytdlp/corruptRefetch.ts`): a second trigger, `damaged-held-audio`; the audio check is forced on + for it (`downloadOneManaged`); a failed refetch restores the previous record (or keeps the download's own); the + kept file is re-audited after clean / still-malformed. `destinationExists` `refetchDamagedAudio` (retry-bucket). + Salvage transcription is automatic for such a file (`transcribeOne`). +- **/review**: `scanCorruptMedia` attaches the audit's verdict (`audit`) to a finding and lists a readable file the + audit found damaged as `damaged`; the finding row shows the audit line. + +| Commit | What | +| --- | --- | +| `68e87ea5` | the audit, the sidecar, the bucket and its surfaces, the refetch trigger, salvage, /review, ops route/help, COMMANDS.md, the e2e fake ffmpeg, the e2e scenario, CHANGELOG | +| (this commit) | this record, FACTS | + +## Gates (from the worktree root, every one behind the shared heavy lock) + +- tsc: `pnpm -r --no-bail --workspace-concurrency=1 exec tsc --noEmit` clean on the merged tree. +- common: 4362 at the branch's start → 4427 after merging main (lanes C, P3, D) and this lane, all pass. This lane's + own: `controller/audioAudit.test.ts` 11 (real ffmpeg over the synthetic damaged recording), `lib/audioIntegrity + .test.ts` 3, `ytdlp/corruptRefetch.test.ts` +7, `lib/sidecar-server.test.ts` (fifteen declared). +- editor unit: 319 → 322 (with the merged lanes), all pass. +- test:scripts: 1030 (+3 skipped) → 1041 (+3 skipped), all pass. +- `docs cli --check`, `docs files --check`, `docs env --check`, `settings example --check`: clean (COMMANDS.md + regenerated). +- e2e `audio-check-scenarios.spec.ts` (with the new scenario: audit → corruptHeldAudio → Retry → clean, re-audited): + run 1 — **17/17 passed** (1.2 min, foreground, behind the lock; the build through the heavy slot first). +- Decode speed measured on a synthetic 30-minute AAC file: 1168× realtime at normal priority, 1039× at the audit's + low priority (≈ 3.5 s per hour of audio on an idle machine; a slow drive dominates). + +## Rulings and calls + +- Corrupt full sources are not audited (Q's path covers them); counted in the log. +- The bucket holds untranscribed damaged files and salvage-transcribed ones; a damaged file under any other transcript + stands, in no bucket (/review lists it). Untranscribed members are held out of the transcription lane until a + retry, as a corrupt full source is. +- The snapshot matches the record by name and size only (no extra stat); the audit and the refetch by name, size and + mtime. +- Q's leftover rule tightened: an aside is removed as "since clean" only with a clean record newer than the aside. + +## Not done + +No live run (the orchestrator's). CHANNEL.md needs nothing (per-video sidecars are not in it). The video page does +not show the audit record (the bucket, the row dot and /review do).