Skip to content

fix: recover from corrupt cache.json + write compact sorted cache - #139

Draft
aiolibsbot wants to merge 2 commits into
bdraco:mainfrom
aiolibsbot:koan/cache-robustness
Draft

fix: recover from corrupt cache.json + write compact sorted cache#139
aiolibsbot wants to merge 2 commits into
bdraco:mainfrom
aiolibsbot:koan/cache-robustness

Conversation

@aiolibsbot

@aiolibsbot aiolibsbot commented May 17, 2026

Copy link
Copy Markdown

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.json currently crashes the whole index build with JSONDecodeError. 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 in vim and 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(): on OSError / ValueError (covers JSONDecodeError) → log a WARNING and leave self.cache empty. Same for valid JSON whose root is not an object.
  • write_to_new(): pass sort_keys=True, separators=(",", ":") to json.dumps.

Testing

  • New tests cover corrupt-JSON recovery, non-object-root recovery, and the compact-sorted on-disk format.
  • Full suite: 17/17 passing locally.

🤖 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)

  • Branch is not pushed to remote

Generated by Kōan post-mission quality pipeline

aiolibsbot and others added 2 commits May 17, 2026 17:08
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant