fix(cache): handle directory cache entries (#326, #327) + tests (Tier D)#331
Merged
Conversation
…326, #327) StructuredOutputCache treated each on-disk entry as a file, but PydanticModelDumper writes a *directory* (class_info.json + model_dump.json): - Eager load filtered `iterdir()` on `is_file()`, which matched nothing and silently disabled batch loading entirely (#326). Switched to `is_dir()`. - Type-mismatch / load-error eviction called `Path.unlink()` on those directories, raising instead of evicting (#327). Routed all five eviction sites (sync + async) through a `_remove_cache_entry` helper using `shutil.rmtree(..., ignore_errors=True)`. Adds regression tests covering the now-reachable paths: eager load populating memory, corrupted-entry cleanup, and sync/async disk type-mismatch eviction. Closes #326 Closes #327 Co-Authored-By: Claude Opus 4.8 <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
Coverage series (follow-up to #325), Tier D — cache bug fix + tests (the double-win: fixes two real bugs and makes the previously-dead code in
generation/_cache.pyreachable and covered).StructuredOutputCachetreated each on-disk entry as a file, butPydanticModelDumperwrites a directory (class_info.json+model_dump.json):cache_dir.iterdir()onis_file(), which matched nothing, so the batch "load existing cache into memory" step was silently dead. → switched tois_dir().Path.unlink()on those directories, raising (IsADirectoryError/PermissionError) instead of evicting. → all five eviction sites (sync + async) now go through a_remove_cache_entryhelper usingshutil.rmtree(..., ignore_errors=True).Tests
Regression tests for the now-reachable paths: eager-load populating memory, corrupted-entry cleanup, and sync + async disk type-mismatch eviction (the latter is the exact case that used to crash — re-adds the test I had to drop in #325 when it surfaced the bug).
Closes #326
Closes #327
Notes
ruff check,ruff format --check, andmypy --strict(Python 3.10). Execution left to CI (unit-testsjob).🤖 Generated with Claude Code