fix: recover cache metadata sidecars#140
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens the native/file-backed model download cache by making cache metadata (metadata.json) recoverable when the completed deterministic model file is still present, and by treating byte-length / SHA-256 mismatches as cache misses (cleaning up stale artifacts) so re-download policies behave safely. It also documents the metadata invariants/recovery behavior and adds targeted unit tests for the new recovery paths.
Changes:
- Recover missing/malformed/unsupported-version
metadata.jsonsidecars from an existing completed cache file (includingcacheOnly). - Treat recorded byte-length mismatches and stored/caller SHA-256 mismatches as cache misses by deleting stale cache artifacts.
- Add unit tests and update public docs/changelog to describe metadata invariants and recovery behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
lib/src/platform/io/model_download_manager_io.dart |
Adds metadata recovery path and shared verification helpers for completed cache files. |
test/unit/platform/io/model_download_manager_io_test.dart |
Adds tests covering metadata recovery and mismatch-driven re-download behavior. |
lib/src/core/models/download/model_download_manager_base.dart |
Documents recovery/miss policy expectations for implementations. |
website/docs/guides/model-lifecycle.md |
Documents cache metadata invariants and recovery behavior for users. |
website/docs/changelog/recent-releases.md |
Adds release note entry for metadata recovery hardening. |
CHANGELOG.md |
Adds corresponding changelog entry for metadata recovery and mismatch handling. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
❌ Your patch status has failed because the patch coverage (57.97%) is below the target coverage (70.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #140 +/- ##
==========================================
- Coverage 78.38% 78.23% -0.15%
==========================================
Files 75 75
Lines 9646 9696 +50
==========================================
+ Hits 7561 7586 +25
- Misses 2085 2110 +25
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
Closes #134
Production-readiness scope
metadata.jsonis damaged or from an unsupported schema version; the deterministic completed model file is reused without network access.DefaultModelDownloadManagerstable cache entries for HTTP(S)/Hugging Face-derived remote model sources.Test Plan
dart format --output=none --set-exit-if-changed lib/src/core/models/download/model_download_manager_base.dart lib/src/platform/io/model_download_manager_io.dart test/unit/platform/io/model_download_manager_io_test.dartdart test -p vm test/unit/platform/io/model_download_manager_io_test.dartdart analyzedart test -p vm -j 1 --exclude-tags local-onlyReview Notes