fix: recover from corrupt cache.json + write compact sorted cache - #139
Draft
aiolibsbot wants to merge 2 commits into
Draft
fix: recover from corrupt cache.json + write compact sorted cache#139aiolibsbot wants to merge 2 commits into
aiolibsbot wants to merge 2 commits into
Conversation
A truncated or hand-edited cache.json currently crashes the whole index build with a JSONDecodeError. Treat unreadable / non-object cache files as empty instead — the next run rebuilds them by re-hashing wheels, which is slower but never fatal. Also write the cache with sort_keys=True and compact separators so the on-disk bytes are stable across runs (diffs reflect real changes, not dict ordering) and a touch smaller for large indexes. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…'t unreachable Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.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
Make
IndexCache.load()resilient to corrupt / non-object cache files, and write the cache with sorted keys and compact separators.Why
A truncated or hand-edited
cache.jsoncurrently crashes the whole index build withJSONDecodeError. The cache is a performance aid (skip re-hashing unchanged wheels) — losing it should slow the next build, not abort it. Real-world ways to end up with a bad cache: disk-full during write, partial filesystem corruption, an operator opening it invimand saving by accident.The write-side tweak is unrelated but small:
sort_keys=True+separators=(",", ":")makes the on-disk bytes deterministic across runs (real diffs only) and trims a few percent off file size for large indexes.How
load(): onOSError/ValueError(coversJSONDecodeError) → log aWARNINGand leaveself.cacheempty. Same for valid JSON whose root is not an object.write_to_new(): passsort_keys=True, separators=(",", ":")tojson.dumps.Testing
🤖 Generated with Claude Code
Quality Report
Changes: 2 files changed, 92 insertions(+), 6 deletions(-)
Code scan: clean
Tests: failed (command not found)
Branch hygiene: 1 issue(s)
Generated by Kōan post-mission quality pipeline