Archilyzer · Source

archilyzer

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

commit e4038dc47f42e68067d60620bb65e0c465b96661
parent 4bfeea81e208cb9bdcc61726a69face82ea81e57
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Thu, 15 Oct 2026 17:16:18 -0400

plans: release 30 lane Q — corrupt-source recovery, as shipped (record, FACTS)

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

Diffstat:
Mplans/FACTS.md | 46++++++++++++++++++++++++++++++++++++++++++++++
Aplans/release-30/q.md | 98+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 144 insertions(+), 0 deletions(-)

diff --git a/plans/FACTS.md b/plans/FACTS.md @@ -9604,3 +9604,49 @@ parsed to 0 cues, indexing the video textless) is CLOSED by `200a3105` (transcri `planArticleDelete` refuses while it is live. `settings.generation.verdicts.window {mode, seconds}` (default seconds, 60) is the window proposals read; umtool's bar form writes the run's. `benchItemsHash` covers the claim's text and its quotes' spans. + +## Release 30 lane Q: corrupt-source recovery (verified 2026-10-15, branch `r30/corrupt-recovery`) + +- **A managed download of a corrupt-full-source video is a refetch** (`common/ytdlp/corruptRefetch.ts`, called by + `downloadOneManaged` around `runManagedDownload` for every URL with a canonical id). `prepareCorruptRefetch` moves + every real audio file aside as `<name>.corrupt-kept` (`CORRUPT_KEPT_SUFFIX`) with `renameMediaFile` + (`lib/mediaTier-server.ts`: a tier link's bytes are renamed beside themselves in `media/<id>/` and the link + re-pointed; a real file renamed in place); `settleCorruptRefetch` decides by the download's own status: `ok*` with + a fresh audio file → the aside is removed; `corrupt-full-source` → whichever copy decodes longer stays + (`scanDecodable`; a tie keeps the new copy, both unmeasurable keeps the old); anything else → a fresh file is + removed, the aside renamed back, and the sidecar rewritten as the PREVIOUS record (status corrupt-full-source) with + the new attempts appended. The record RETURNED to the caller is the download's own (status `failed`, its + `failureClass`), so a batch backs the platform off on a 429; only the sidecar keeps the bucket's status. + `prepare` first settles any `.corrupt-kept` an interrupted run left (restore, or keep the longer of two copies, or + remove after a clean record; a non-ok record it finds is rewritten corrupt-full-source). +- **`download-outcome.json` `corruptRefetches[]`**: one `CorruptRefetch` per retry, oldest first — + `{startedAt, finishedAt, result: "clean" | "still-malformed" | "failed", status, failureClass?, error?, kept?: + "new" | "previous", decodedSeconds?: {previous, new}}`; carried from record to record by the refetch. +- **The retry prefilter**: `retry-bucket` passes `refetchCorruptFullSource` to `destinationExists`, which then answers + false for a video whose outcome is corrupt-full-source whatever is on disk (the kept file, a salvage transcript). + Only the retry: download-missing and sync still count the kept file as there. `corruptFullSource` is a + `ReplayBucket`; the channel's download stage has a Retry card for it (`retry corrupt full sources bucket`). +- **Media-tier scratch**: `*.corrupt-kept` and `audio.salvage.wav` (`lib/mediaTier.ts` SCRATCH_PATTERNS) — never + tiered, never counted as text; neither is a real audio file. +- **Salvage decode** (`common/lib/salvageAudio-server.ts`): `ffmpeg -err_detect ignore_err -fflags +discardcorrupt`, + 16 kHz mono. `scanDecodable` = the framecrc of the unpadded decode (decoded seconds = summed frame durations; a pts + jump is a hole; the tail to ffprobe's container duration is one); `salvageDecode` adds a second output, + `aresample=16000:async=1:first_pts=0,apad=whole_dur=<container>` into a WAV — silence of each hole's length, so + the WAV is on the source's clock (a plain decode closes the holes up and every later cue lands early by the gap; + both pinned by `salvageAudio-server.test.ts` over `common/testing/audio/corruptAudio.mjs`). Listed gaps: holes merged + when less than 1 s of audio lies between them, then those under 0.5 s dropped (still counted in decoded seconds). +- **Salvage transcription** (`controller/transcribeOne.ts`): `salvage` on `transcribeOneVideo`/`transcribeWithWorker` + (true forces, false forbids, undefined = automatic when `download-outcome.json` says corrupt-full-source). The engine + reads `audio.salvage.wav` in the video dir (removed in a `finally`; parakeet's `.audio.salvage.wav.parakeet` cache + survives a pause — the decode is deterministic). Parakeet gets `--salvage` (`TranscribeBuildInput.salvage`): a window + whose slice or parakeet-cli run fails is a gap; its neighbours own their whole reach on that side; the output gains + `salvage.failedWindows` (what no transcribed window reached); every window failing is exit 1. Whisper.cpp and + chough ignore the flag. +- **`transcribe-outcome.json` `salvaged`** = `{source, decodedSeconds, totalSeconds, gaps: [[from, to], …]}` (decode + holes ∪ failed windows, merged), written only when something is missing — a salvage of a file that decodes whole + is a clean transcript with no `salvaged`. +- **Snapshot bucket `salvagedTranscript`**: whisper transcripts whose transcribe-outcome has `salvaged` (one small read + per whisper transcript carrying the sidecar). Classified BEFORE the corrupt-full-source short-circuit, so a + salvaged corrupt full source is in both buckets. Still counted in `totals.transcribed`. Channel flow: a transcribe + siding; the video page: `SalvagedTranscriptNotice` (`salvaged transcript` status). +- **Ops**: `transcribe-one {…, "salvage": bool}`; `retry-bucket {"bucket": "corruptFullSource"}` refetches. diff --git a/plans/release-30/q.md b/plans/release-30/q.md @@ -0,0 +1,98 @@ +# Release 30, lane Q — corrupt-source recovery (as shipped) + +Branch `r30/corrupt-recovery` from `main` `59fdc486`. Brief: `r30q-brief.md` (the plan of record for this lane). +FACTS: "Release 30 lane Q: corrupt-source recovery". + +## Q1, as shipped (2026-10-15): a retry of a corrupt full source refetches it + +The kept container made the corruptFullSource bucket's only control a no-op (the retry-bucket prefilter read it as +"already complete"). Built: +- **The retry asks again.** `retry-bucket` passes `refetchCorruptFullSource` to `destinationExists` + (`common/ytdlp/runYtdlp.ts`): a video whose `download-outcome.json` is corrupt-full-source is never "complete" to + the retry, whatever is on disk (the kept file, a salvage transcript). Only the retry: download-missing and sync still + count the kept file, so no sweep re-fetches these. +- **Every managed download of a corrupt-full-source video is a refetch** (`common/ytdlp/corruptRefetch.ts`, around + `runManagedDownload` in `downloadOneManaged` — so retry-bucket, the video page's re-download and any batch that + reaches the video all take it). `prepareCorruptRefetch` moves each real audio file aside as + `<name>.corrupt-kept`, tier-aware (`renameMediaFile`, new in `lib/mediaTier-server.ts`: a tier link's bytes are + renamed beside themselves in `media/<id>/` and the link re-pointed). `settleCorruptRefetch` decides by what the + download ended as: + - `ok*` with a fresh audio file: the aside file is removed (`removeMediaFile`); + - `corrupt-full-source` again: whichever copy decodes longer stays (`scanDecodable`, one tolerant ffmpeg decode), + the other removed; a tie keeps the new copy, both unmeasurable keeps the old; + - anything else (a 429 at the prefetch — the live case — the network, a filter, a cancel, a short file): a fresh + file is removed, the aside file renamed back, and the sidecar rewritten as the previous record (status + corrupt-full-source) with the new attempts appended. **The caller still gets the download's own record** (status + `failed`, its `failureClass`), so a batch backs the platform off as for any 429. + - Each retry is a `CorruptRefetch` in the sidecar's new `corruptRefetches[]` (result, status, failureClass, error, + kept, decoded seconds of each copy). + - A run cut short leaves `.corrupt-kept`; the next `prepare` settles it first (restore; or the longer of two copies; + or remove after a clean record; a non-ok record it finds is rewritten corrupt-full-source). + - A kept file that cannot be moved aside fails that video's download (it is never downloaded over). +- `*.corrupt-kept` and `audio.salvage.wav` are media-tier scratch (`lib/mediaTier.ts`): never tiered, never text. +- **Surfaces.** `corruptFullSource` is a `ReplayBucket`; the channel's Download stage has a **Corrupt full sources** + card with the bucket's Retry (`retry corrupt full sources bucket`); the channel flow's siding, the video list's dot + title, the video page's outcome badge and the snapshot's comments say a retry downloads again (the "futile" sentence + is gone). Ops help for `retry-bucket`; COMMANDS.md. +- Test kit: `common/testing/audio/corruptAudio.mjs` — a synthetic AAC tone-burst recording, the same with a seeded run + of bytes overwritten, a WAV reader and a burst-onset finder (README not touched — a later kit pass can list it). + +## Q2, as shipped (2026-10-15): salvage transcription + +A plain transcription of a corrupt file failed at the first bad window. Built: +- **The decode** (`common/lib/salvageAudio-server.ts`): `-err_detect ignore_err -fflags +discardcorrupt`, 16 kHz mono; + one ffmpeg run with two outputs — the framecrc of the unpadded decode (decoded seconds; a pts jump is a hole; the + tail to the container's duration is one) and a WAV through `aresample=async=1:first_pts=0,apad=whole_dur=<duration>` + (each hole silence of its own length). **The timestamp claim is verified**: over the synthetic damaged recording the + bursts after the damage are at their source times in the salvage WAV (±50 ms) and absent inside the gap, while a + plain decode (the control) puts every later burst early by the gap's length. +- **The transcription** (`controller/transcribeOne.ts`): `salvage` on `transcribeOneVideo` / `transcribeWithWorker` — + true forces, false forbids, absent = **automatic when the download outcome is corrupt-full-source** (my call: the + file is known to be malformed and a plain run fails at the first bad window; nothing else transcribes such a video + automatically, so this only changes an explicit Transcribe). The engine reads `audio.salvage.wav` in the video dir + (removed in a `finally`; parakeet's window cache survives a pause). Recorded in `transcribe-outcome.json` as + `salvaged: {source, decodedSeconds, totalSeconds, gaps}` — only when something is missing; a salvage of a file that + decodes whole is a clean transcript. +- **parakeet-stitch `--salvage`** (passed by the parakeet app on a salvage run; whisper.cpp and chough ignore it): a + window whose slice or parakeet-cli run fails is a gap, not the end of the file; its neighbours own their whole reach + on that side; the output gains `salvage.failedWindows`, which transcribeOne merges into the gaps; every window failing + is still exit 1. +- **Not a clean full transcript**: the snapshot's new `salvagedTranscript` bucket (still counted as transcribed; a + corrupt full source stays in its own bucket — a retry can still bring a clean copy), a transcribe siding in the + channel flow, and on the video page a status line ("Salvaged transcript — 38:55 of 1:40:00 of audio.mp4 decoded. No + transcript for …") with the transcribe card's tone at attention. Not the `incompleteTranscript` bucket: its action + is delete-and-re-download, which is the corrupt-full-source retry's job here. +- **Ops**: `transcribe-one {…, "salvage": bool}` (checked a boolean at the door); help and COMMANDS.md. + +## Q3: the bucket stays honest + +A failed refetch keeps the corrupt-full-source status and its history (Q1's "anything else" path, pinned by the +whole-path test: a fake yt-dlp answering the prefetch with a 429 leaves the sidecar corrupt-full-source with +`["metadata-prefetch", "audio-checked-primary", "metadata-prefetch"]` and the kept file in place). The snapshot stays +the single classifier: it reads the sidecar's status as before; the only addition is `salvagedTranscript`. + +| Commit | What | +| --- | --- | +| `fc0942e7` | Q1: corruptRefetch.ts, renameMediaFile, the retry prefilter, scanDecodable + the test kit, the replay bucket, the Retry card, the sentences; ops help, COMMANDS.md | +| `72ef936b` | Q2: salvageDecode, transcribeOne salvage, parakeet-stitch --salvage, transcribe-outcome `salvaged`, the `salvagedTranscript` bucket, the video page's status; ops help, COMMANDS.md | +| `1d327f32` | Q2: a salvage that finds nothing missing is a clean transcript | +| `88e03d2f` | editor: the status is not a chore card (videoChoreCards); the e2e retry scenario; CHANGELOG | +| (this commit) | this record, FACTS | + +Gates (from the worktree root; every tsc and suite behind the shared heavy lock after 16:29): +- tsc: common, editor, mcp package-scoped clean at each commit; `pnpm -r exec tsc --noEmit` clean at the branch tip. +- common: 4253 at the branch's start (1 failing that run — the run overlapped my first edits; not reproduced) → + 4279, all pass. New: `ytdlp/corruptRefetch.test.ts` 9 (one through `downloadOneManaged` with a fake yt-dlp), + `lib/salvageAudio-server.test.ts` 7 (real ffmpeg), `controller/transcribeSalvage.test.ts` 2 (the real stitch + wrapper over a fake parakeet-cli that "transcribes" tone bursts: cues at the source's burst times ±60 ms, none in the + gap), `mediaTier-server` +3, `mediaTier` +3 rows, `channelSnapshot` +1, `transcriptionApps` +1, `jobSpec` +1 bucket. +- test:scripts: 1024 (1021 + 3 skipped) → 1027 (1024 + 3 skipped), none failing (`parakeet-stitch.test.mjs` +3). +- editor unit: 310 → 310, all pass (the transcribe-one door check is inside an existing test). +- mcp: 372/372. +- `docs cli --check`, `docs files --check`, `docs env --check`: clean. +- e2e: `audio-check-scenarios.spec.ts` (with the new retry scenario) NOT RUN — held on the orchestrator's word while + the user systemd bus was down (the e2e build would have run uncapped). Owed: that one spec, foreground. + +Not done: no live run (the orchestrator's, after merge); the video page does not list `corruptRefetches` (the +sidecar has them); a clean refetch leaves an existing salvage transcript in place (listed in `salvagedTranscript`; +delete it and transcribe again for a full one); the export/MCP do not mark salvaged transcripts.