You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(cache): validate cached model files by size + ETag before reuse
Each completed download now writes a sibling metadata record ({ etag, size,
savedAt }) next to the cached blob. On a later load getModelFile validates the
cached file before trusting it:
- integrity: if the recorded size doesn't match the cached blob's byte length
(truncated / partially-written / corrupt cache), re-download cleanly instead
of feeding ORT a broken model and failing with a cryptic error.
- freshness: a short, timeout-guarded HEAD compares the current upstream ETag
against the one recorded at download time; a clear mismatch means the file
genuinely changed (e.g. a moving 'main' revision moved) and is re-downloaded.
The decision is deliberately conservative and defaults to reusing the cache:
the HEAD is skipped when offline or when there's no recorded etag, and any
failure (blocked HF, timeout, missing etag on either side) keeps the cache. So
offline / firewalled startup stays instant and pinned-revision models never
re-download. Legacy caches without metadata keep working unchanged.
The pure decision (decideCacheAction) is factored out and unit-tested across the
integrity, freshness, and precedence paths.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
0 commit comments