Kokoro model download truncates silently — no Content-Length / checksum verification
Repro
On a fresh install with a flaky / interrupted network during first-run Kokoro model download:
$ ls -la ~/Library/Application\ Support/heard/models/
-rw-r--r-- 1 me staff 24936448 Apr 30 14:58 kokoro-v1.0.onnx ← truncated
-rw-r--r-- 1 me staff 28214398 Apr 30 14:57 voices-v1.0.bin
$ /Applications/Heard.app/Contents/MacOS/python -m heard doctor
...
Synth
✗ synth InvalidProtobuf: [ONNXRuntimeError] : 7 : INVALID_PROTOBUF :
Load model from .../kokoro-v1.0.onnx failed: Protobuf parsing failed.
Upstream kokoro-v1.0.onnx is 325,532,387 bytes; on-disk file was 24.9 MB after the download "completed" without raising. ONNX runtime then explodes on next synth, and the daemon never recovers — the broken file sits there forever because is_downloaded() only checks .exists().
Root cause
heard/tts/kokoro.py:_download_with_progress:
urllib.request.urlretrieve(url, tmp)
tmp.rename(dest)
urlretrieve doesn't raise on a connection that closes cleanly mid-stream; the partial file gets renamed atop the destination. There is no:
- Content-Length verification
- Checksum verification (no SHA256 pinned anywhere in the repo)
- Retry on truncation
is_downloaded() is a pure existence check, so the daemon will never re-pull a corrupt file on its own.
Suggested fix
- Pull the resource through
urllib.request.urlopen, readContent-Lengthfrom headers, stream chunks to.part, abort if the file size doesn't match. - Pin a known-good SHA256 for both
kokoro-v1.0.onnxandvoices-v1.0.binin a constants file; verify after download, retry up to N times. - Tighten
is_downloaded()— at minimum checkstat().st_size > 0and against the pinned size; ideally verify the checksum, but that's expensive on a 325 MB file at every daemon start. A.sha256sidecar written after first verification and skipped on subsequent loads would be the cheap fix.
Happy to PR if there's a preferred shape — left a comment on the SSL PR linking here.
Env
- macOS 26
- Heard v0.4
Fixed in 85782e9. Streamed download + Content-Length verification + final byte-count check + 3-attempt retry. Pinned upstream sizes (325,532,387 / 28,214,398) catch truncation deterministically. is_downloaded() now verifies size against the pinned values, so truncated leftovers from pre-fix installs auto-re-download on next launch — no manual cleanup needed. Will ship in v0.4.3.
Thanks @arthursolwayne — clear repro and the SHA256-vs-size tradeoff call you flagged was exactly right.