Repository navigation
Conversation
…s#4697) * chore(mypy): remove the no-op strict = false override mypy applies `strict` only when it is true, so `strict = false` in a per-module override is ignored. The 14 entries listed there (modules and globs) were already checked strictly. Remove the block, and reword the TODO on the `ignore_errors` list that pointed at it. Assisted-by: ClaudeCode:claude-opus-5-5 * test(fsspec): take test_fsspec off the mypy ignore list Narrow the subgroup returned by `AsyncGroup.getitem` to `AsyncGroup` before calling `group_keys`, which was the module's only mypy error, and remove `tests.test_store.test_fsspec` from the `ignore_errors` list so the module's own code is type-checked like the rest of the tests. Assisted-by: ClaudeCode:claude-opus-5-5 * test(v2): ignore numcodecs' Pickle deprecation warning in pickle tests numcodecs main now warns that its Pickle codec is deprecated whenever one is created, and the suite turns warnings into errors, so the pickle decode-gate tests in test_v2.py fail in the upstream-dependencies job. Those tests create Pickle codecs on purpose, so ignore that warning for them. Released numcodecs doesn't warn, so the filter ignores the warning rather than requiring it. Assisted-by: ClaudeCode:claude-opus-5-5 * test(fsspec): use get_group instead of narrowing getitem's result `AsyncGroup.get_group` returns an `AsyncGroup` and raises if the member is an array, so the test needs no isinstance assert to type-check. Assisted-by: ClaudeCode:claude-opus-5-5 * test(v2): match the Pickle deprecation comment to upstream zarr-developers#4680 Assisted-by: ClaudeCode:claude-opus-5-5
Writing a cache entry (cache-store write plus size/LRU tracking) and dropping one (cache-store delete plus tracking release) were separate, unlocked steps spread over many call sites. Concurrent reads and writes could leave untracked data in the cache store, tracking with nothing behind it, or a stale value cached forever: - a read miss fetched the source outside the lock and then cached the result, even if a `set` or `delete` of the same key completed in between; - values larger than `max_size` were written to the cache store before the size check rejected them, and stayed there untracked; - overlapping `set` calls on one key installed their values in lock order, which need not match the order the source applied them. `_install_entry` and `_drop_entry` now do the whole change under the lock. Every source read and write registers a `_PendingOp` before it starts; a write that completes marks the other operations on its key as overlapped. An overlapped read does not cache what it fetched, and an overlapped write drops the entry instead of caching its value. `delete_dir` and `clear` mark every operation under their prefix. Settling the cache after a source operation is shielded from cancellation. A source operation that raises still leaves the cache as it was. A Hypothesis state machine drives random, partly concurrent sequences of every operation through yielding stores and checks after each step that tracking matches the cache store exactly and that everything cached equals the source. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r-developers#4669) * fix(sharding): keep whole-shard reads in the buffer's own memory The fused pipeline's fast path for reading a whole uncompressed shard copied the shard to host memory with `as_numpy_array()`, then assigned each chunk into the output buffer. Under `zarr.config.enable_gpu()` the output is a CuPy array, which refuses host arrays, so the read failed. The fast path now uses `as_array_like()`, as `BytesCodec` does. The stored-byte-order view dtype is now computed by one helper, `BytesCodec._stored_dtype`, shared by the per-chunk and fast paths. It handles structured data types, so the fast path no longer has to decline them. Closes zarr-developers#4654 Assisted-by: ClaudeCode:claude-opus-5-5 * docs(changes): add fragment for the whole-shard device read fix Assisted-by: ClaudeCode:claude-opus-5-5 * test(sharding): draw structured data types in the bulk-decode property test The whole-shard fast path now takes structured data types, so its equivalence test with the per-chunk path draws a mixed-endian struct. The changelog fragment now says the structured fast path applies to FusedCodecPipeline only. Assisted-by: ClaudeCode:claude-opus-5-5 * docs(changes): number the fragment for the upstream PR Assisted-by: ClaudeCode:claude-opus-5-5
A caller cancelled while the source write was in flight skipped the cache update, but the write may still have landed (LocalStore writes in a thread; remote stores may commit before responding). The old value then stayed cached. `set`, `delete`, `set_if_not_exists`, `delete_dir` and `clear` now drop the affected entries when cancelled; a store exception still leaves the cache as it was. A failed eviction while installing an entry also left the replaced value in the cache store untracked, where reads would serve it; the entry is now dropped on any failure there. `delete_dir` and `clear` release tracking and byte-range entries before the cache-store I/O, so a cache-store failure cannot leave in-memory ranges of deleted keys. Found in adversarial review of the previous commit. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`Store.delete_dir` and `clear` delete key by key, so one that raises may have deleted some keys; those stayed cached and were served afterwards. A failed `delete_dir` or `clear` now checks which tracked, range-cached or in-flight keys under its prefix the source no longer has and drops those entries, keeping the rest (so a deletion that fails before touching the source still leaves the cache as it was). A failed single-key write may also have reached the source, so it drops the key's entry, as a cancelled one already did. Tests: - one coherence helper, used by the state machine and the targeted tests, also checks that the cache store holds exactly the tracked keys, that no operation stays registered, and that no empty per-key range dict is left; - the state machine draws reads and writes more often and small `max_size` values, so it fills and evicts; it no longer overrides the Hypothesis profile's example and step counts; it checks `_set_many` leaves the last value for each key in the source; - new deterministic tests: a read's cache update queued ahead of a write's, a cancelled read, cache-store failures while installing, and a partly failed `delete_dir`/`clear`. Every mutant from the adversarial review is now killed under the CI Hypothesis profile. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cancelling a write's caller does not stop a thread-backed source call (LocalStore writes in `asyncio.to_thread`), so dropping the entry at cancellation let a read in the window re-cache the old value before the thread landed. Each source mutation and its cache update now run as one task that cancelling the caller does not stop, so the cache settles when the source call has really ended, and the special cancellation branches go away. Tracking is now the one source of truth for full-key hits: only tracked keys are served, and `_drop_entry` releases tracking before deleting from the cache store. A failed cache-store delete, or data a persistent cache store held from an earlier session, can then cost a hit but never serve a stale value. A failed `delete_dir`/`clear` now also drops entries when asking the source whether a key still exists fails. `_set_many` waits for every write before raising the first error, instead of returning while the others still run. Hits no longer take the lock to update the LRU order. `clear_cache` is shielded. Found in the second adversarial review round. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The state machine's source now fails deletes at random, so `delete_dir` and `clear` fail partway while reads and writes are in flight; its `clear` deletes key by key and checks read-only, like a real store. Its `exists` yields, operations are reweighted so the cache fills, errors are matched by message, and a step that leaves a task running fails by name instead of leaking into the next example. New targeted tests: a failed deletion of keys cached only as byte ranges, and of keys with a read in flight; `clear_cache` keeping reads in flight supersedable; a failing source read; filling `max_size` exactly. Coherence is checked before the reads that could repair it. Prose uses American spelling. Found in the second adversarial review round. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tion guide (zarr-developers#4694) Scalar indexing returned a NumPy scalar in Zarr-Python 2 and returns a 0-dimensional numpy.ndarray in Zarr-Python 3, following the Python array API standard. Arrays whose shape is () changed in the other direction. The migration guide covered neither, so the change was only visible from the Array.__getitem__ doctest.
…rs#4696) * fix: invalidate CacheStore entries after bulk deletion * chore: use the pull request number for the changelog
… I/O When a source `delete_dir`/`clear` failed and the cache store then failed to delete the first absent key, settling stopped there and the later absent keys stayed tracked, so reads served values the source no longer had. All absent keys are now released before any cache-store delete, the deletes run together, and the first failure is raised. Canceling a write's caller already did not stop the write; this is now documented on the class. An error the write raises after its caller was canceled is logged instead of being reported by asyncio as never retrieved, and the task is kept referenced until it finishes. Found in the third adversarial review round. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ic-tracking # Conflicts: # tests/test_experimental/test_cache_store.py
Match how `_set_many` picks errors out of `gather` results, and wait in the orphan-logging test until the operation has finished rather than a fixed number of loop turns. Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
Author
|
🤖 AI text below 🤖 Round 5 of the adversarial review (6558a90, the upstream merge 6b5ddd1, and the fragment 4c572bb) found nothing serious or minor. Rounds 4 and 5 both came back without serious findings, so the review loop is finished. Round 5 detailsUpstream merge
Code and test changes
Nits, not acted on
|
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 when reads and writes run concurrently. A read that races a write no longer caches the value the write replaced, values larger thanmax_sizeare no longer written to the cache store, and failed, canceled or partly failed writes and deletions no longer leave stale entries. Canceling a write no longer stops it from reaching the source store.Stack: this PR is stacked on #494 (
fix/cachestore-passthrough-mutators), which is stacked on upstream zarr-developers#4696 (now merged). Merge #494 first. This branch has upstreammainmerged in (for zarr-developers#4696); #494 has not, so until it does, this PR's diff also shows those upstream commits. The commits to review are the ones after2f24bc9d6.Design
All cache changes now go through two locked primitives:
_install_entrywrites the cache store and tracks the entry in one step under the lock._drop_entryreleases tracking and then deletes from the cache store, also under the lock.Tracking is the one source of truth for full-key hits: only tracked keys are served. A failed cache-store delete, or data a persistent cache held from an earlier session, can cost a hit but cannot serve a stale value.
Races between reads and writes. Every source read and write registers a
_PendingOpbefore it starts. When a write completes, it marks the other in-flight ops on its key as no longercurrent. An overlapped read does not cache what it fetched. An overlapped write drops the entry rather than guess which value the source kept.delete_dirandclearmark every op under their prefix. Ops are forgotten when they settle, sopendingholds only in-flight work.Cancellation. Each source mutation runs as one task together with its cache update (
_run_to_completion). Canceling the caller does not stop the cache from following the source, including forLocalStore, which writes in a thread that keeps running after a cancel. An error raised after the caller left is logged.Failures.
delete_dir/cleardrops the entries under its prefix whose keys the source does not confirm withexists. A deletion that fails before deleting anything therefore still leaves the cache intact, as fix: invalidate CacheStore entries after bulk deletion zarr-developers/zarr-python#4696'stest_bulk_delete_source_error_preserves_cacherequires.Decisions worth a maintainer look:
set,delete,set_if_not_exists,delete_dir,clear). This keeps the cache exact for thread-backed stores. The cost is that, on natively async stores, a canceled write can still land after a later write to the same key. The alternatives that keep writes cancelable either leave the cache stale after a cancel or never cache that key again.existsrather than dropping everything under the prefix. Both reviewers in round 1 preferred dropping everything, which is simpler and always safe, but it would reverse fix: invalidate CacheStore entries after bulk deletion zarr-developers/zarr-python#4696's pinned "source error preserves cache" behavior. Switching is a small change if preferred.Tests
CacheStoreMachine, a Hypothesis state machine, drives random sequences ofset,get(full and byte-range),delete,set_if_not_exists,_set_many,delete_dir,clearandclear_cache. Some steps run concurrently, some go through awith_read_onlyview.max_sizevalues and bothcache_set_datasettings.delete_dirandclearfail partway._assert_cache_coherentchecks:current_size == sum(key_sizes);getmust return the source's value, and no step may leave a task running.ciandnightlyprofiles (about 6 s, 6 s and 18 s).Deterministic tests cover each race and failure path the reviews found:
delete_dir/clear(with and withoutexistsfailing, range-only keys, reads in flight);clear_cachewith reads in flight;max_size;Each fails on the code before its fix.
Mutation testing: 39 mutants of
cache_store.pywere written by a reviewer, run under theciprofile. All non-equivalent mutants are killed. The four survivors are equivalent or only drop more entries.Adversarial review record
Fresh reviewer agents got the diff and files each round. Every finding was reproduced with a probe before it was fixed.
Round 1 (296f991), serious findings in both the code and the tests:
delete_dirdropped byte ranges only after cache-store I/O.delete_dirleft deleted keys cached;pendingleaks unchecked, no coherence check in the targeted tests.LocalStore.deleteon a directory andMemoryStore.clearignoringread_onlyare store bugs, left as follow-ups.Round 2 (c321e9e), serious findings:
existsfailing during a failed deletion dropped nothing;_set_manyreturned while sibling writes still ran, which made the machine flaky (plus a leftover-task assertion in 52e5897);clear_cachewas unshielded.clear_cachesupersession, boundary sizes, failing reads), plus American spelling.ObjectStore.delete_dirkeeps deleting aftergatherraises. That is an ObjectStore bug, left as a follow-up.Round 3 (52e5897), only the fix diff:
Round 4 (6d624cf): no serious findings.
CancelledErrorfrom a cache-store delete replaces the source error (pre-existing behavior);Round 5 (6558a90, upstream merge, fragment): no serious or minor findings; two nits not acted on (fork PR numbers in fragment names; cache-store error masks source error on a doubly failed bulk delete, pre-existing). Review stopped after rounds 4 and 5 came back clean.
🤖 Generated with Claude Code