Skip to content

Unpack each model pack on its own, so a broken speaker pack can't stop transcription - #40

Merged
billlyzhaoyh merged 3 commits into
mainfrom
fix/38-per-pack-cache
Nov 26, 2026
Merged

billlyzhaoyh merged 3 commits into
mainfrom
fix/38-per-pack-cache

Conversation

@billlyzhaoyh

@billlyzhaoyh billlyzhaoyh commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #38.

What changed

The verified-pack resolver (app/src-tauri/src/models.rs) unpacked every verified speech pack into one shared cache folder, named by a hash of the whole set. If any one pack failed to unpack (a corrupt entry, a full disk), the error stopped everything:

  • every import and crash recovery, with speakers on or off;
  • every recording start.

After #37, unpacking was the last place a broken speaker pack could still cost the transcript.

Each pack now unpacks into its own folder, verified-models/pack-<manifest sha256>/, like the LLM pack's existing llm-<sha256>/:

  • Transcription: verifies only asr packs, and takes the newest one whose zip lists every file the model needs (each ASR pack carries Silero VAD). Only that pack is unpacked.
  • Speakers: resolve_verified_speaker_dir resolves the newest verified diarization pack on its own.
    • No verified speaker pack: the "isn't installed" note.
    • A pack that can't be unpacked (or loaded, or run): the "Speakers couldn't be labelled, so this transcript has none. (…)" note.
  • Stop: resolves only the speaker pack, so it no longer re-hashes the transcription packs (about 600 MB for Parakeet) when it finishes.
  • Old shared folders: folders with a 64-hex name directly under verified-models/ are removed when transcription models resolve. The pack-… and llm-… folders stay.
  • Engine:
    • Diarizer needs only the speaker models; SherpaEngine's diarize hands off to it, so process and the examples are unchanged.
    • speaker_model_files() and transcription_model_files() are the file lists; required_model_files combines them.
  • Removed: the resolver's diarize flag, and the Keep the transcript when speakers can't be labelled on import or recovery #37 notes saying the app relied on the shared folder.

/simplify

The second commit changes no tested behaviour.

Fixed:

  • Verifying and choosing packs: one function verifies the packs of a given task, newest first.
    • The ASR, speaker and LLM resolvers share that ordering and one unpack helper.
    • Transcription stops at the first pack that has the files, so it opens fewer zips.
  • AppHandle wrappers: the three repeated the same setup; they now share one helper.
  • Engine: SherpaEngine and Diarizer share one file check. Diarizer moved below the trait impl, so that impl no longer shows as moved.
  • Recorder: keeps only its thread count, not a whole config.
  • Edge case: a verified speaker pack missing its files now says "couldn't be labelled" rather than "isn't installed".

Skipped:

  • Cleaning up leftover per-pack folders: when a pack is upgraded, its old pack-<sha>/ folder stays. Removing it deletes more than was agreed (old shared folders only), so that's for a follow-up.
  • Hashing every installed ASR pack on each transcription: this was already the case on main. Verifying only the chosen pack would mean reading an unverified zip's directory first.
  • Dropping the resolver's check that every file unpacked: it's the resolver's fail-closed check.
  • The diarizer_for test hook: the approved speaker-step test needs it.

Tests

Test packs are built and signed during the tests with the committed test key, using ed25519-dalek (already a dev-dependency) and modelpack::canonicalize. There are no new binary fixtures.

The first version signed through a dev-dependency on tools/modelpack-sign. That changed the features of crates sherpa-onnx-sys's build uses. On CI's partly matching cache, sherpa-onnx-sys was then rebuilt without re-fetching its prebuilt library, so the Linux and Windows app-backend jobs failed with "could not find native static library sherpa-onnx-c-api". The third commit drops that dependency, and all 12 checks pass.

  • Reproduces A speaker pack that fails to unpack still stops transcription #38: a_speaker_pack_that_fails_to_unpack_does_not_stop_transcription_models_resolving.
    • On main it failed with extracting zip entry sherpa-onnx-pyannote-segmentation-3-0/model.onnx: Invalid checksum.
    • The test pairs the ASR fixture with a signed speaker pack whose zip has a corrupt entry. Transcription models now resolve, and the speaker resolver returns the unpack error.
  • speaker_models_resolve_from_the_speaker_pack_alone, including Ok(None) when only an ASR pack is installed.
  • resolving_removes_the_old_shared_cache_folders.
  • the_speaker_step_says_why_a_transcript_has_no_speakers: the speaker-step test approved on Keep the transcript when speakers can't be labelled on import or recovery #37, giving the exact "isn't installed" note, and the "couldn't be labelled" note for a pack that fails to unpack.
  • Replaced: resolve_verified_models_dir_in_fails_closed_when_diarization_models_missing tested the removed diarize = true mode. The Ok(None) case above covers it.

Results:

  • app backend: 64 passed
  • engine: 32 passed
  • cargo check --all-targets: no warnings for app or engine
  • scripts/check-no-network.sh: passes

Verified in the desktop app

tauri dev on macOS, on the release-style verified-pack path:

  • KINDTECH_PACKS_DIR pointed at packs signed with the test key: a real Parakeet v2 int8 pack (from the bench models) and a speaker pack.
  • No KINDTECH_MODELS_DIR.
  • Detect speakers was ticked, and planted recordings were recovered.
  1. Speaker pack that can't be unpacked: a file sat where its cache folder goes, so unpacking failed with a real file-system error. The transcript opened from verified-models/pack-b3a9…/ with all 44 words and diarized: false. The note read "…Speakers couldn't be labelled, so this transcript has none. (clearing partial cache …: Not a directory (os error 20))". A planted old-layout folder was removed.
  2. Speaker pack removed: the next recovery opened with "The speaker-detection pack isn't installed, so this transcript has no speakers. Add it on the Models page."

Both cases were run again after /simplify, with the same results.

The app was driven through Accessibility only, without keystrokes. Stop with speakers on wasn't driven, because it would record from the microphone; it shares the speaker step above.

… can't stop transcription

The resolver unpacked every verified speech pack into one shared cache
folder. One pack that failed to unpack (a corrupt entry, a full disk)
stopped every import, recovery and recording, speakers on or off.

Each pack now unpacks into its own folder, verified-models/pack-<sha256>/,
like the LLM pack's llm-<sha256>/:

- Transcription verifies `asr` packs only, picks one whose zip lists the
  model's files (each carries Silero VAD), and unpacks only that pack.
- The speaker step resolves the `diarization` pack on its own
  (`resolve_verified_speaker_dir`). No pack gives the "isn't installed"
  note; one that can't be unpacked gives "Speakers couldn't be labelled".
- Stop resolves only the speaker pack, so it no longer re-hashes the
  transcription packs.
- The old shared folders (64-hex names) are removed when resolving.

The engine gains `Diarizer`, which needs only the speaker models, and
`speaker_model_files()`; SherpaEngine's diarize hands off to it.

Tests sign packs with the committed test key through a dev-dependency on
tools/modelpack-sign. The `diarize = true` resolver test is replaced by
the speaker resolver's `Ok(None)` case.

Closes #38
From /simplify on #40.

- `verified_packs` takes the task and returns verified packs newest first;
  `verified_packs_of` and `pick_pack` are gone. Transcription stops at the
  newest pack whose zip lists its files, opening fewer zips. The speaker
  step takes the newest verified speaker pack, so one missing its files
  says "Speakers couldn't be labelled (…)" rather than "isn't installed".
- One `unpacked(pack, cache_base, prefix)` serves speech packs (`pack-`)
  and the LLM pack (`llm-`), and the LLM resolver shares the newest-first
  rule.
- `with_installed` builds the packs folder, cache folder, key and engine
  versions once for the three AppHandle wrappers; `packs_dir` reuses
  `app_cache_base`.
- Engine: `transcription_model_files(asr_model)` sits beside
  `speaker_model_files()`; `required_model_files` combines them.
  `SherpaEngine::new` and `Diarizer::new` share `require_files` and
  `model_path`, and `Diarizer` moves below the trait impl so the impl's
  diff stays small.
- The recorder's `Finished` keeps only `num_threads`, not a whole config;
  the debug override's file check is shared (`holds_all`).
The dev-dependency on tools/modelpack-sign changed the features of crates
sherpa-onnx-sys's build uses (rand_core/getrandom, ring, rustls, ureq).
On CI's partly matching cache, sherpa-onnx-sys was then rebuilt without
re-fetching its prebuilt native library, and the app backend jobs on
Linux and Windows failed to find `sherpa-onnx-c-api`.

The tests now sign packs with ed25519-dalek (already a dev-dependency)
and `modelpack::canonicalize`, encoding the signature with base64, which
is already in the tree through `modelpack` with the same features.
@billlyzhaoyh
billlyzhaoyh merged commit 8b2419c into main Nov 26, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A speaker pack that fails to unpack still stops transcription

1 participant