Repository navigation
Conversation
CacheStore inherits WrapperStore's mutating methods, which forward straight to the source store. Each one it does not override writes or deletes around the cache, so later reads serve stale data; zarr-developers#4696 fixed this for clear and delete_dir. Close the rest: - `_set_many` writes each pair through `set`. - `set_if_not_exists` drops the cached entries for its key, since whether the source wrote is not reported. - `set_sync` and `delete_sync` raise `TypeError` instead of bypassing the cache; `_supports_sync_io` already keeps zarr's own code off them. A test classifies every WrapperStore method as safe to inherit or required to be overridden, so a method added to WrapperStore fails until it is handled. Assisted-by: ClaudeCode:claude-opus-5-5
`_remove_from_tracking` dropped an entry from the size map without subtracting it from `current_size`, so `delete`, `set` with `cache_set_data=False`, and a missed read leaked budget. The previous commit made `set_if_not_exists` a new caller, and zarr calls it on the parent group's metadata for every array created, so the leak grew until eviction emptied the cache. `_remove_from_tracking` now releases the size, and `_evict_key`, `_invalidate_range_entries`, `delete_dir` and `_track_entry` all go through it. `_track_entry` releases the entry it replaces before making room, so eviction cannot release that size twice. `_set_many` writes only the last value for a repeated key. Tests check `current_size == sum(key_sizes)` after every mutator, with and without `cache_set_data`, and across repeated array creation. The classification test now covers methods inherited from `Store` as well. Assisted-by: ClaudeCode:claude-opus-5-5
`_update_access_order` tested `entry_key in cache_order` before awaiting the lock, so a concurrent miss that evicted the entry while the hit waited made `move_to_end` raise `KeyError` out of a plain read. Test membership inside the lock. Also test that replacing a tracked value under size pressure keeps the new value cached with its size counted once; no test covered that change from the previous commit. Assisted-by: ClaudeCode:claude-opus-5-5
Assisted-by: ClaudeCode:claude-opus-5-5
…through-mutators # Conflicts: # src/zarr/experimental/cache_store.py # tests/test_experimental/test_cache_store.py
d-v-b
marked this pull request as ready for review
December 4, 2026 15:12
This branch has not been deployed
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.
🤖 AI text below 🤖
CacheStorekeeps its cache consistent with the source store for every write and delete it inherits:set_if_not_existsand_set_manynow update the cache, andset_syncanddelete_syncraiseTypeErrorinstead of writing around it. Its size budget no longer leaks when entries are deleted, and concurrent reads no longer raiseKeyErrorwhen an entry is evicted.Stack: zarr-developers#4696 merged upstream (12b4721) and has been merged in here, so this PR now shows only its own changes. Fork draft #495 is stacked on top of this PR.
Agent notes
Why.
CacheStoresubclassesWrapperStore, whose write and delete methods forward straight to the source store. Each oneCacheStoredoesn't override bypasses the cache, and later reads serve stale data. zarr-developers#4696 fixesclearanddelete_dir. A review of zarr-developers#4696 found the rest, and adversarial review of this branch found two older bugs on main.Commits.
fix(experimental): keep CacheStore coherent for every inherited write:_set_manywrites throughset.set_if_not_existsdrops the key's cached entries, because whether the source wrote isn't reported.set_syncanddelete_syncraiseTypeError;_supports_sync_ioalready keeps zarr's own code off them.WrapperStoreandStoremethod as safe to inherit or required to be overridden, so a newly added method fails the test until someone decides which it is.fix(experimental): release cached sizes in one place in CacheStore. Fixes a leak incurrent_size:_remove_from_trackingdropped entries without subtracting their size.delete,setwithcache_set_data=False, and a read of a missing key all leaked budget on main.set_if_not_existsa frequent new caller, since zarr calls it on the parent group's metadata for every array created. The leak then grew until eviction emptied the cache._remove_from_trackingnow releases the size and every path goes through it._track_entryreleases the entry it replaces before making room. Previously, eviction could delete the new value from the cache store and release the old size twice._set_manykeeps only the last value for a repeated key.fix(experimental): check CacheStore LRU membership under the lock. On main, a cache hit could raiseKeyErrorfrommove_to_endwhen a concurrent miss evicted the entry while the hit waited for the lock.Not addressed (all also on main).
set/deleteof the same key can cache the old value: the source is read outside the lock, and the cache is written afterwards.max_sizeare written to the cache store before the size check, untracked.All three come from the same design: tracking and cache-store writes happen as separate, unlocked steps across many call sites. Fixing them as a class means one locked "install entry / drop entry" pair, with a per-key version counter to reject stale fills from read misses.
Behavior change:
CacheStore.set_sync/delete_syncused to write through to a sync-capable source; they now raise.CacheStoreis experimental, and the old behavior served stale reads afterwards.Verification.
tests/test_experimental/test_cache_store.py: 81 passed. The new tests fail on zarr-developers#4696's head (10 failures), and the size-accounting tests also fail on the first commit alone (7 failures), which is how the leak was confirmed.tests/test_experimental,tests/test_store/test_wrapper.pyandtests/test_store/test_logging.py: 262 passed. mypy and ruff (pre-commit pin) clean.Adversarial review. Three rounds by fresh reviewer agents.
set_if_not_existsinvalidation exposed the size leak in_remove_from_tracking. Fixed in the second commit.Store(fixed); a misleading test comment (fixed); repeated keys in_set_manycould leave cache and source different (fixed, last-wins)._invalidate_keybetween its three steps, which predates this branch.KeyErrorrace on main (fixed in the third commit)._track_entrychange (test added in the third commit).KeyErrorwhen the fix is reverted.🤖 Generated with Claude Code