Fix JsonCacheInfoRepository metadata loss on quick exit (#491) - #519
Merged
Conversation
Replace the 3-second write debounce with serialized write-through and atomic temp-file replace so cache info is durable when mutating futures complete (#491). Co-authored-by: Cursor <cursoragent@cursor.com>
Keep contributor- and agent-specific guidance out of the shared repository. Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
✨ What kind of change does this PR introduce? (Bug fix, feature, docs update...)
Bug fix for
JsonCacheInfoRepositorypersistence, plus ignore localAGENTS.mdfiles.JsonCacheInfoRepositorydebounces disk writes by 3 seconds. If the app is force-stopped or killed before that timer fires (anddispose()/close()is not called), cache metadata updates are lost. DirectwriteAsStringto the JSON file can also leave an empty/corrupt file if interrupted mid-write.🆕 What is the new behavior (if this is a feature change)?
insert/update/deleteFuture means the change is on disk..tmpsibling withflush: true, then rename over the destination for atomic replace.FlutterError.reportErrorand retried on a later mutation orclose().deleteDataFile()also removes an orphaned.tmpfile.AGENTS.mdis gitignored so agent/contributor notes stay out of the shared repo.💥 Does this PR introduce a breaking change?
No.
🐛 Recommendations for testing
flutter_cache_manager/:dart format --set-exit-if-changed .flutter analyzeflutter testtest/repositories/json_file_repository_test.dartstorage tests (persist withoutclose, no leftover temp file, failed write reported and retried onclose).📝 Links to relevant issues/docs
Fixes #491
Related durability concerns also touch empty/corrupt JSON reads (#450), but this PR focuses on write timing and atomic replace rather than read recovery.
🤔 Checklist before submitting
Made with Cursor