Handy/src-tauri/src
Viren Mohindra 58cda3f3b3
fix: sha256 verification to prevent corrupt partial download loop (#1095)
* fix: add SHA256 verification to prevent corrupt partial download loop

Fixes issue #858 — corrupt .partial files caused an infinite loop where
a failed/cancelled download would resume from EOF, pass extraction, and
loop forever with no way to recover without manual file deletion.

Three-part fix:
- Add sha2 crate and compute_sha256() helper; verify hash post-download
  before extraction/rename for all 15 built-in models. Hash mismatch
  deletes the .partial so the next attempt starts fresh.
- Delete .partial on extraction failure (independent of checksums) so
  corrupt archives can't re-enter the loop via the same path.
- Emit model-download-failed event from the command handler so all
  callers (ModelsSettings, Onboarding) get consistent error feedback
  via a central store listener rather than per-caller return-value checks.

SHA256 hashes hardcoded alongside each model's URL in ModelInfo.
Custom models (sha256: None) skip verification silently.

* chore: remove doc comment from sha256 field

Doc comments on exported specta types propagate into bindings.ts as
inline JSDoc — not useful in generated TS. Removing at the source.

* test: add SHA256 verification unit tests

Extracts inline verify logic into ModelManager::verify_sha256() and
covers all four branches:
- None expected hash → skipped (custom models)
- Matching hash → ok, file kept
- Mismatched hash → error returned, partial file deleted
- Unreadable file → error returned

Ensures corrupt partial downloads are always cleaned up so the next
attempt starts fresh.

* chore: cargo fmt

* fix: clear cancel flag on sha256 failure, spawn_blocking for hash, fallback cleanup

- remove cancel_flags entry on sha256 failure to prevent a stale flag
  from immediately cancelling the next retry attempt (HIGH)
- add fallback state cleanup in modelStore when result.status != ok,
  so spinner clears even if model-download-failed event is missed (HIGH)
- run compute_sha256 in spawn_blocking to avoid stalling the async
  executor while hashing large model files (up to 1.6 GB) (MEDIUM)

* emit some more events for the ui to pick up

* add translations + format

---------

Co-authored-by: CJ Pais <cj@cjpais.com>
2026-03-21 14:19:26 +08:00
..
audio_toolkit feat(audio): use device default sample rate and always downsample (#1084) 2026-03-19 08:53:03 +08:00
commands fix: sha256 verification to prevent corrupt partial download loop (#1095) 2026-03-21 14:19:26 +08:00
helpers WIP: Add tauri-specta for generating TS bindings (#322) 2025-11-27 17:07:22 +07:00
managers fix: sha256 verification to prevent corrupt partial download loop (#1095) 2026-03-21 14:19:26 +08:00
shortcut feat(audio): lazy stream close for bluetooth mic latency (#747) 2026-03-19 14:12:43 +08:00
actions.rs fix: keep Windows microphone guidance Windows-only (#1032) 2026-03-15 22:44:48 +08:00
apple_intelligence.rs feat: implement structured outputs for post-processing providers (#706) 2026-02-17 12:14:00 +08:00
audio_feedback.rs feat: add portable mode to NSIS installer (#807) 2026-03-06 12:07:11 +08:00
cli.rs feat: add CLI parameters for linux (#792) 2026-02-17 12:48:43 +08:00
clipboard.rs Add "external script" paste method (#638) 2026-02-19 17:07:16 +08:00
input.rs refactor enigo input (#441) 2025-12-12 16:33:49 +07:00
lib.rs improve history performance (#1107) 2026-03-21 12:06:29 +08:00
llm_client.rs feat: implement structured outputs for post-processing providers (#706) 2026-02-17 12:14:00 +08:00
main.rs feat: add CLI parameters for linux (#792) 2026-02-17 12:48:43 +08:00
overlay.rs attempt to clean up warnings on build (#1037) 2026-03-14 11:42:42 +08:00
portable.rs feat: add portable mode to NSIS installer (#807) 2026-03-06 12:07:11 +08:00
settings.rs feat(audio): lazy stream close for bluetooth mic latency (#747) 2026-03-19 14:12:43 +08:00
signal_handle.rs attempt to clean up warnings on build (#1037) 2026-03-14 11:42:42 +08:00
transcription_coordinator.rs fix: transcription lock-up race condition & add small debounce (#824) 2026-02-16 22:18:50 +08:00
tray.rs be able to change models from the tray (#1002) 2026-03-14 12:19:06 +08:00
tray_i18n.rs fix(i18n): tray menu shows Simplified Chinese when Traditional Chinese is selected (#901) 2026-03-01 10:39:14 +07:00
utils.rs fix: transcription lock-up race condition & add small debounce (#824) 2026-02-16 22:18:50 +08:00