Skip to content

feat(zarr-storage): add a Zarr-agnostic storage package with a new store API - #488

Closed
d-v-b wants to merge 32 commits into
mainfrom
feat/zarr-storage
Closed

d-v-b wants to merge 32 commits into
mainfrom
feat/zarr-storage

Conversation

@d-v-b

@d-v-b d-v-b commented Dec 1, 2026 •

Copy link
Copy Markdown
Owner

🤖 AI text below 🤖

Add zarr-storage, a new package with a Zarr-agnostic key-value storage API: Store and AsyncStore views over memory, local-filesystem and obstore backends, with the same operations as sync methods and as coroutines, conditional reads and writes (get_if_changed, put_if_absent, put_if_match, delete_if_match), byte-range reads, reads into caller buffers, and batches (get_many, get_into_many, put_many, delete_many). Every store view carries a Context holding the resources its operations draw on (a ThreadPool, and a Limiter per backend resource key, with process-wide defaults), and store.limited(n) bounds a burst of operations within the context's limit. The package ships a conformance suite in zarr_storage.testing that any backend can run.

Supersedes #460 (the package and its store API) and #464 (contexts and resource limits, stacked on #460): this branch combines both, adds the repository wiring every sub-package has, and fixes what review found. It is meant to go upstream to zarr-developers/zarr-python as one PR. Nothing in zarr uses the package yet.

Maintainer setup needed before the first release, as for the other sub-packages:

  • a zarr-storage GitHub label (the labeler applies it);
  • a Read the Docs subproject zarr-storage whose configuration file is packages/zarr-storage/.readthedocs.yaml;
  • PyPI and TestPyPI trusted publishers for zarr-storage-release.yml, with environments zarr-storage-releases and zarr-storage-releases-test.
What the API is

packages/zarr-storage/DESIGN.md is the contract (also rendered as the docs site's Design page); it records which source each decision came from (TensorStore, zarrs, HTTP and Rust object_store, earlier zarr-python store proposals).

  • Store (sync methods, close/with) and AsyncStore (the same names as coroutines, aclose/async with) are views of a backend at a root, sharing one base where the key grammar, the root, read-only and closed states are enforced; backends only see backend paths. store / "a", as_async() and as_sync() return views on the same backend; the constructed store owns the backend. There is no value equality: shares_backend and overlaps answer what callers ask.
  • Keys: no leading/trailing /, no empty, . or .. segments, no NUL. Prefix arguments name directories ("a" ≡ "a/"), so list("lat") never sees lat_bnds/….
  • Results are closed unions of frozen types, each method returning only the outcomes it can produce (get → Found | Missing, get_if_changed → … | Unchanged, put_if_absent → Written | Rejected, …). Conditional operations are separate methods, and capabilities a backend lacks are type errors.
  • get_into is generic in the buffer type the backend reads into (host Buffer, or a device buffer for GPU direct storage); the caller allocates.
  • Batches: get_many/get_into_many (lazy, as reads finish) and put_many/delete_many (eager, in order); a failure raises BatchError with what completed and what remains.
  • Contexts (modeled on TensorStore's): a ThreadPool and a Limiter per resource key, immutable, with child contexts; limited(n) nests within the parent's limit instead of replacing it.
  • Backends: MemoryBackend; LocalBackend (staged writes renamed into place under per-directory locks taken ancestor before descendant; unique nanosecond mtime stamps so generations don't repeat on filesystems that reuse inodes; delete_dir walks by file descriptor and never through a symlink); ObjectStoreBackend over obstore.
Repository wiring

Matches zarr-metadata, zarr-indexing and zarr-http-server: a test/ruff/pyright/docs workflow (zarr-storage.yml, Python 3.11–3.14), a release workflow on zarr_storage-v* tags (zarr-storage-release.yml, which tests and builds the docs from the unpacked sdist), the package's mkdocs site and Read the Docs config, the changelog check, labeler and release-notes exclusion, the root Justfile recipe, and entries in the root README table, docs/subprojects.md and the main site's nav. The root .readthedocs.yaml skips the main docs build for PRs that only touch the package.

The changelog fragment is changes/488.feature.md; rename it to the upstream PR's number when this goes upstream.

Testing
  • zarr_storage.testing.StoreSuite plus capability mixins (ConditionalPutSuite, ConditionalDeleteSuite, ConditionalRaceSuite, KeyAndDirectorySuite, PickleSuite, UniqueGenerationsSuite) and refusing counterparts. Every test runs through Store and again through an AsyncStore over the same backend.
  • StoreSuite.test_state_machine: a Hypothesis state machine driving random operations, batches included, through random views against a dict model.
  • Race and interleaving tests for the local backend's locking, a tripwire that fails any blocking obstore call made on an event-loop thread, and tests for the limiter, thread pool and batch runners (cancellation, interrupts, deadlock shapes).
  • 1788 tests pass on macOS with Python 3.11, 3.14 and free-threaded 3.14, and on Linux (python:3.12-slim). pyright strict, ruff and mkdocs build --strict are clean; the sdist builds, holds no symlinks, and runs its tests and docs build unpacked.
Review record

The agent ran four rounds of adversarial review with fresh reviewer agents on the combined branch, confirming each finding with a reproduction before fixing it.

Round 1 (whole package):

  • Serious, fixed in 95b83c6: LocalBackend.delete_dir("link/sub") followed a symlinked parent and deleted data outside the root.
  • Serious, fixed in a1ce892: on a store that reports neither an ETag nor a version (an HTTP server without ETags), every value had one generation, so get_if_changed returned Unchanged for changed values.
  • Serious: a cancelled AsyncStore write over a sync backend still ran after the caller moved on. 2ff082e fixed it by taking slots before work went to the pool; round 2 showed that deadlocks, so 17d525c restored slots on pool threads and skips an operation cancelled before it gets its slot.
  • Serious, not fixed (documented under "Open" in DESIGN.md): a burst through a limited(1) view of a sync backend can occupy every thread of a shared pool. Removing it needs a pool per limiter or slot-aware dispatch; the only cheap fix deadlocks (above).
  • Minor, fixed: a slot lost to Ctrl-C while waiting (2ff082e, kept in 17d525c); a batch kept starting queued operations after a failure (same); a pickled derived view became the backend's owner (same); an AsyncStore operation awaited on its own pool's thread deadlocked (same); staged files leaked when a write failed part way, reserved names were case-sensitive, a root that is a file gave a misleading error, a dangling symlink parent retried 64 times (95b83c6); DESIGN.md inaccuracies and references to private planning documents, undocumented protocols, private types in public signatures (e4e1c33); the package's monorepo wiring (b9467df).
  • Minor, not fixed (listed under "Open"): obstore passes its own errors through for keys the grammar allows and obstore refuses (control characters; # plus digits on its LocalStore); case-insensitive filesystems alias distinct keys; an AsyncStore batch's tasks still waiting for a slot run after a failure; a slot granted to a task whose loop closes without running it is lost.

Round 2 (fix diffs):

  • Serious, fixed in 17d525c: 2ff082e created a hold-and-wait deadlock once a pool thread needed a slot (a sync Store on a pool thread, or a backend delegating to a Store).
  • Serious, fixed in d85f5a9: a directory swapped for a symlink mid-walk was still followed by delete_dir (the rmtree race); it now walks by file descriptor with O_NOFOLLOW where the platform allows. Windows junctions are now skipped (not run on Windows).
  • Minor, fixed in d85f5a9: get on a FIFO blocked forever; a write under a special file retried 64 times; an absolute backend path looped forever; the docs quickstart used a closed store. Fixed in 17d525c: a spurious loop error on 3.14 from re-shielding (the code was removed).

Round 3 (fix diffs):

  • Serious, fixed in abd57b8: the inline path on a pool thread took slots with a blocking acquire, deadlocking an event loop running there when another task held the slot across an await.
  • Serious, fixed in abd57b8: a two-stat parent check let a concurrent delete_dir turn a retryable write into KeyConflictError.
  • Minor, documented: delete_dir holds two descriptors per directory level; a derived view pickled without its owner has no owner.

Round 4 (abd57b8 only): no serious finding. Minor, fixed in 79be01e: a symlink loop as a key's parent raised a raw ELOOP instead of KeyConflictError.

Round 5 (79be01e only): no serious finding, so review stopped after two clean rounds. Minor, not fixed (older than these commits): a symlink loop deeper in a key's path (a -> a, put("a/b/k")) still raises a raw ELOOP from mkdir; on Windows, where a loop reports EINVAL, a write would retry until it gives up (not run on Windows).

Not in this PR
  • Using the package from zarr, moving the current store API, and the hierarchy layer.
  • fsspec and zip backends, composition (retry, caching, range coalescing), get_ranges_into, concurrent sync batches on obstore, transactions.
  • A Windows CI run (the Windows rules are unit-tested only).

🤖 Generated with Claude Code

d-v-b and others added 23 commits November 17, 2026 16:20
…ore API

Add `packages/zarr-storage`, a key-value storage layer that knows nothing
about the Zarr spec. `DESIGN.md` is the contract.

- `Store` is a view of a backend at a root: the one place that checks the
  key grammar, applies the root, and enforces read-only and closed states.
  `store / "a"` returns a view on the same backend; the constructed store
  owns the backend's lifecycle; there is no value equality
  (`shares_backend`, `overlaps` instead).
- Prefix arguments name directories; `list_dir` yields `Key`, `Prefix` or
  `Entry`; `delete` removes one key and `delete_dir` a directory.
- Reads return `None` for a missing key and take byte ranges (range,
  offset, suffix); `get_into` reads into a caller's buffer. Writes and
  deletes take `if_match` / `if_none_match` and report `applied=False`
  instead of raising. Every method has an `_async` twin.
- Backends: `MemoryBackend`, `LocalBackend` (staged writes renamed into
  place under per-directory locks, unique nanosecond mtime stamps so
  generations don't repeat on filesystems that reuse inodes), and
  `ObjectStoreBackend` over obstore.
- `zarr_storage.testing`: a conformance suite with capability mixins, run
  through both the sync and async methods, plus a Hypothesis state machine
  that checks random operations through random views against a model.

Assisted-by: ClaudeCode:claude-opus-5-5
Assisted-by: ClaudeCode:claude-opus-5-5
…l operations

Reads return `Found | Missing` (and `FoundRanges`, `Copied`) instead of
`ReadResult | None`, so a missing key is a value an HTTP 404 maps onto.
`get_if_changed` adds conditional reads that return `Unchanged` without
reading bytes (HTTP 304, obstore `If-None-Match`).

Conditional writes become their own methods: `put` returns `Written`,
`put_if_absent` returns `Written | Rejected`, `put_if_match` and
`delete_if_match` live in the `WritableIfMatch` and `DeletableIfMatch`
capability protocols. Each method returns only the outcomes it can
produce, and `delete_if_match` on an object store is now a type error
rather than a runtime refusal. Backends share one implementation per
operation, parameterized by a precondition function.

Assisted-by: ClaudeCode:claude-opus-5-5
…s into

`ReadableInto` and `ReadableIntoAsync` are now generic in the type of
buffer the backend writes into, and `Store.get_into` accepts exactly that
type. Host backends are `ReadableInto[Buffer]` and convert the buffer
themselves; a GPU direct storage backend can be `ReadableInto` of its
device buffer type, so passing it host memory (or the reverse) is a type
error. The caller allocates, so the store needs no allocator.

`Store.get_into` no longer falls back to `get` plus a copy for backends
without `get_into`: the method is a type error on them. The obstore
backend gains `get_into` (a read, then a copy), using the shared
`copy_into` helper.

Assisted-by: ClaudeCode:claude-opus-5-5
Store gains get_many, get_into_many, put_many and delete_many, with async
twins. A batch is a loop of the single operation run concurrently where
the backend can, with no atomicity: reads are lazy and yield
(request, result) pairs as they finish; writes are eager and return
results in the order given. Keys are checked before any operation
starts, and a write batch naming a key twice raises ValueError. After a
failure a batch starts nothing new, lets running operations finish, and
raises BatchError (an ExceptionGroup) whose completed and remaining
fields survive except*.

Store runs any backend's batches serially; the optional ReadableMany,
ReadableIntoMany[O] and WritableMany capabilities (and async twins) let
a backend run them its own way. LocalBackend runs them on its thread
pool, and ObjectStoreBackend's async batches keep `concurrency`
requests in flight. The shared runners live in zarr_storage._batch.

The state machine's new batch rules found a race in ObjectStoreBackend:
a read or delete under a file, concurrent with deleting that file,
raised the store's raw error. A refusal carrying ENOTDIR is now read as
an absent key directly, instead of by re-checking the parents.

Assisted-by: ClaudeCode:claude-opus-5-5
Store keeps the sync operations; the new AsyncStore offers the same
operations under the same names as coroutines and async iterators
(`await astore.get(k)`, `async for k in astore.list()`), so neither
class carries the other's methods. Both derive from a private _View that
holds the backend, root, read-only flag and ownership, and does key
validation, root joining and read-only checks once. `store.as_async()`
and `astore.as_sync()` are non-owning views on the same backend.

Lifecycle differs between the two: Store has close() and `with`;
AsyncStore has `await aclose()` and `async with`, which awaits a
ClosableAsync backend's aclose (new capability, for cleanup that awaits a
client session) and calls close on any other. LocalBackend gains aclose,
running its pool shutdown on a worker thread.

BREAKING CHANGE: Store's `*_async` methods are gone; use
`store.as_async()` or construct an AsyncStore.

Assisted-by: ClaudeCode:claude-opus-5-5
…ackends

Add two resources that backends share, after TensorStore's context
resources: ThreadPool runs blocking work, and Limiter caps operations in
flight for threads and tasks on any event loop in one first-come,
first-served queue. Pass one to several backends to bound them together;
left out, a backend uses a process-wide default (ThreadPool.default(),
max(4, cpu_count) threads; one Limiter(32) per obstore store class).

LocalBackend takes `threads` and runs async operations and batches on
it; closing the backend no longer shuts a pool down, since whoever
creates a pool owns it. ObjectStoreBackend takes `concurrency`, a
Limiter, and holds a slot for every operation, sync and async, single
and batched, instead of bounding each async batch on its own. A slot is
re-entrant within one operation, so an operation that calls another
can't wait on itself. A batch started on one of its pool's own threads
runs on that thread rather than wait on the pool. Pickling keeps
resources shared: pickle stores each object once, and defaults unpickle
as the receiving process's defaults.

BREAKING CHANGE: LocalBackend's `concurrency: int` is now
`threads: ThreadPool`, and ObjectStoreBackend's `concurrency` is a
Limiter instead of an int. LocalBackend.aclose is gone.

Assisted-by: ClaudeCode:claude-opus-5-5
Resources move from backends to a Context that every store view carries,
as in TensorStore. A Context holds a ThreadPool and a Limiter per
resource key, is immutable, and resolves keys through its parents to
process-wide defaults. Backends hold no resources: each names the
`resource_key` its operations are limited under ("local", "memory",
"obstore.<StoreClass>"), and the store gates every operation with the
context's limiter for that key.

Store and AsyncStore take `context=`, and gain `with_context` and
`limited(n)`, a view whose operations together run at most n at once.
`Limiter(n, within=parent)` holds a slot of both, so a scoped limit
never escapes the one it narrows (where TensorStore's child contexts
replace a resource, this nests). Slots are taken innermost first, and
where the work runs: AsyncStore runs a sync-only backend on the
context's thread pool and takes the slot on the pool thread, so no
operation holds a slot while it waits for a thread.

LocalBackend is now sync-only; AsyncStore adapts it. Batches run single
operations concurrently under the context (a Store batch on the pool, an
AsyncStore batch as tasks, up to the limiter's limit), which also makes
sync obstore batches concurrent. Native batch methods receive the
context. Slots are no longer re-entrant: re-entrancy through a context
variable leaked into tasks and, on free-threaded 3.14, into new threads,
letting a fan-out run unbounded under one slot.

BREAKING CHANGE: LocalBackend's `threads`, its async methods and
ObjectStoreBackend's `concurrency` are gone; pass resources in a
Context. Backends must provide `resource_key`. Batch protocol methods
take the context.

Assisted-by: ClaudeCode:claude-opus-5-5
The cache is a `CachePool` in the store's context, off by default. Its bytes
live in a tier, which is any writable store, so range reads, batches and the
conformance suite come from the tier. An in-memory index holds what a store
can't: source generations, ages, absences and eviction order.

Assisted-by: ClaudeCode:claude-opus-5-5
… its siblings

Add the package's test/lint/typecheck/docs workflow and release workflow,
its Read the Docs site (mkdocs config, API pages, DESIGN.md rendered as a
page), `__version__`, and the repository entries every sub-package has:
labeler, release-notes exclusion, changelog check, root Justfile recipe,
README table row and sub-project card.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A sync backend's operation through an `AsyncStore`, and each operation of a
`Store` batch, took its slot on the pool thread that ran it. A burst on a
`limited(1)` view then parked every pool thread waiting for that one slot,
stalling every other store on the pool, and a write cancelled while it waited
still ran later, overwriting newer writes.

Slots are now taken by whoever hands work to the pool (the task, or the
batch's calling thread) and given back by the pool thread when the work
finishes, so pool threads never wait for slots. `ThreadPool.run` never starts
cancelled work that is still queued, waits for cancelled work already running
before propagating the cancellation, and runs inline on its own threads. A
batch cancels its queued operations after the first failure. A thread
interrupted while waiting for a slot gives the slot back, and a pickled
derived view stays derived instead of becoming the backend's owner.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…linked directories

`delete_dir` checked only the last component for a symlink, so
`delete_dir("link/sub")` deleted `sub` in whatever directory `link` pointed
to, outside the root. `delete_dir`, `list` and `list_dir` now treat a
symlink anywhere between the root and their target as the end of the tree,
and listings report only what `get` reads as a key: regular files and
symlinks to them, not symlinks to directories, dangling symlinks or special
files.

Also: a write that fails while staging (a full disk, an interrupt) removes
its partial file; reserved names are refused in any case, as case-insensitive
filesystems read them; a write under a dangling symlink raises
`KeyConflictError` instead of retrying 64 times; and a root that is a file
raises `NotADirectoryError` saying so.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hat identifies no value

A store that reports neither an ETag nor a version (an HTTP server that
sends no ETag) gave every value the generation `("obstore", None, None)`,
so `get_if_changed` read the new bytes, found the generations equal, and
discarded them as `Unchanged`. Such a generation now never reads as
unchanged.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n upstream

Drop references to private planning documents and prototypes; list every
capability protocol and conformance mixin under its right heading; say that
native batches draw on the context themselves; describe the new slot,
cancellation and symlink rules and the obstore generations that identify no
value; and list the known gaps under "Open". Give every capability protocol
a docstring, type `shares_backend`/`overlaps` with the public store
classes, export `Slot`, and merge the fork's two changelog fragments into
one, to be numbered after the upstream pull request.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…am PR is numbered

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ons cancelled before theirs

2ff082e moved slot acquisition before work went to the pool. That
removed one stall but created a deadlock: once a pool thread itself needs a
slot (a sync `Store` used on a pool thread, or a backend that delegates to a
`Store`), every thread can wait for a slot held by work queued behind them.
This restores the original rule, so no operation holds a slot while it waits
for a thread, and keeps the fixes that don't depend on it:

- an `AsyncStore` operation of a sync backend whose task is cancelled before
  it takes its slot is skipped, so a cancelled write no longer lands long
  after its caller moved on;
- `ThreadPool.run` runs inline on the pool's own threads;
- a `Store` batch cancels its queued operations after the first failure;
- a thread interrupted while waiting for a slot gives it back;
- a pickled derived view stays derived.

The stall a `limited(1)` burst can cause on a shared pool is listed under
"Open" in DESIGN.md.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mlink is never followed

`delete_dir` checked for symlinks by path, then walked by path, so whoever
could write the root could swap a directory for a symlink between the check
and the walk and have files outside the root deleted (the classic rmtree
race). Where the platform has `dir_fd` (not Windows), `delete_dir` now
opens each directory relative to its parent with `O_NOFOLLOW`, locks it
through that descriptor, and unlinks a name that turned into a link instead
of following it, as `shutil.rmtree` does. On Windows the path walk skips
directory junctions, which `is_symlink` doesn't report.

Also: backend paths are checked against the key grammar, so an absolute path
or `..` passed to the public backend can't leave the root; a FIFO or device
in a key's place reads as absent instead of blocking `get`; a write under any
non-directory name raises `KeyConflictError` at once; and the docs
quickstart runs as written.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ck a write's parents with one stat

Two regressions from the previous fixes, found in review:

- `ThreadPool.run` runs inline on the pool's own threads, and the inline call
  took its slot with a blocking acquire. On an event loop running inside the
  pool's work, that blocked the loop's thread while another task on the same
  loop held the slot across an await, so neither could proceed. On those
  threads `AsyncStore` now takes the slot with `async with` and runs the
  operation inline.
- `_has_key_parent` asked `exists()` and then `is_dir()`, so a concurrent
  `delete_dir` between the two made a retryable write raise
  `KeyConflictError`. It now decides from one `stat`.

DESIGN.md also states the cancellation rule precisely and lists two known
limits: descriptor use per directory level in `delete_dir`, and a derived
view pickled without its owner.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`_has_key_parent` let `ELOOP` from its `stat` escape, where it used to raise
`KeyConflictError` for a symlink loop in a key's parent.

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>
d-v-b and others added 4 commits December 1, 2026 21:19
…at changes the disk

`LocalBackend(root, create=True)` let a keyword decide whether constructing
a backend made directories. `LocalBackend(root)` now reads the filesystem
and changes nothing, raising `FileNotFoundError` for a missing root and
`NotADirectoryError` for a file; `LocalBackend.create(root)` makes the
directory and any missing parents first. The `create` keyword is gone.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d's root on write

A write made its staging directory with `mkdir(parents=True)`, so a write to
a backend whose root's parent was gone (an unmounted volume) rebuilt the
whole path on whatever filesystem was there. A write now recreates only the
root itself, which an enclosing backend's `delete_dir` can remove, and
raises `FileNotFoundError` if the directory above it is gone.
`LocalBackend.create` also resolves a relative root once, and names a
dangling symlink in the root's place as one.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…writes

Record the design: a `Mappable` capability whose `map` returns a mapping of
one generation (safe because LocalBackend never changes a file in place),
kept apart from `get` because mapped bytes do their I/O when touched; and a
`WritableRange` capability that patches a copy and renames it into place,
cheap where the filesystem clones files. Writes in place would weaken other
operations' guarantees, so they'd need a backend type of their own.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ilesystem it was on

28c1c19 made writes recreate only the root itself, which broke nested
backends whose root an enclosing `delete_dir` removed together with a
directory above it, and `_probe_exact_times` still rebuilt the whole path.
The concern was never depth but filesystems: the backend now records the
root's device, and every path that creates directories goes through one
check (`_ensure_root`) that recreates the root and missing parents only on
that device. A write to a root whose volume was unmounted, whether its path
is now missing or an empty mount point, raises `FileNotFoundError`. Key
directories are made from the root down, so they never climb above it, and
`create`'s error names both cases it can't tell apart.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t the unmounted-volume case as open

Reverts 28c1c19 and 2034196. Both changed how writes recreate a removed
root and the directories above it, so that a write to an unmounted volume
would not rebuild its path elsewhere; review found that each broke the
retries the write path relies on under a concurrent `delete_dir` (deeper
nested roots, EINVAL on macOS, the file-time probe). The write path is back
to the reviewed version, and DESIGN.md lists the unmounted-volume behavior
under "Open" with what a fix would need. Kept: `LocalBackend.create`
resolves a relative root once and names both cases it can't tell apart.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@d-v-b

d-v-b commented Dec 1, 2026

Copy link
Copy Markdown
Owner Author

🤖 AI text below 🤖

Follow-up commits pushed after the PR opened, and what review found in them.

  • 5f31fea: LocalBackend(root) now changes nothing on disk (a missing root raises FileNotFoundError), and LocalBackend.create(root) makes the directory; the create= keyword is gone. Review found nothing serious.

  • b4539dd: DESIGN.md plans a Mappable capability for memory-mapped reads and a copy-on-write WritableRange capability (cheap where the filesystem clones files). Docs only.

  • 28c1c19 and 2034196, reverted in c90326a: these tried to stop writes from rebuilding a missing path above the root (for example after its volume is unmounted). Review found serious regressions in each:

    • 28c1c19 broke nested backends whose root sits two levels below an enclosing delete_dir, and the file-time probe bypassed the rule.
    • 2034196 (a device check) let EINVAL escape during a concurrent delete_dir on macOS, left the probe's retry loop incomplete, and could loop forever when no ancestor exists.

    The write path is back to its reviewed version. DESIGN.md lists the unmounted-volume behavior under "Open". c90326a keeps two small create improvements: it resolves a relative root once, and its error names both cases it can't tell apart.

1792 tests pass on macOS (3.11, 3.14, 3.14t) and Linux.

d-v-b and others added 4 commits December 1, 2026 23:19
…ackend one owner

From an audit of the store views' shared base:

- `overlaps` compared backend objects, so two stores over different backend
  objects that see the same keys (two `LocalBackend`s over nested
  directories, the case behind #459's `from_array` data loss) reported no
  overlap. Every backend now names a `Location` (a space and a path, as a
  TensorStore kvstore is a driver spec plus a path): the local filesystem
  for `LocalBackend` and obstore's `LocalStore` alike, endpoint and bucket
  (or account and container, or URL) plus prefix for object stores, and an
  identity-only space for memory stores. `Store.location` appends the root,
  and `overlaps` compares locations. `Location` is exported and `location`
  joins the `Backend` protocol.
- Constructors lose `root=`: the constructed store sees the backend from its
  root and owns it, so a second store over a backend is a view, not a second
  owner whose `close` closes the first's backend.
- Every view is made by one private constructor that sets ownership once,
  instead of four places flipping `_owner` after construction.
- `with_read_only(read_only=True)` becomes `as_read_only()`: the `False`
  form could only repeat the store or raise.
- Write batches check keys (and duplicates) before refusing a read-only
  store, as single writes do, and a store that is read-only because its
  backend can't write says so.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…als out of them

From review of 8dc17a1:

- An obstore `LocalStore` with a relative prefix resolved it against the
  working directory each time `location` was read; it is now read once,
  when the backend is made, as the store resolves its own.
- An HTTP store's location held the whole URL as its space, so nested URLs
  never overlapped; the space is now the scheme and host, and the URL's path
  is the path.
- User names, passwords and query strings (a presigned URL's signature) are
  dropped from URLs and S3 endpoints, and an endpoint's trailing `/` no
  longer makes a different space.
- `Location` refuses a path that isn't a normalized directory.
- `copy.copy` of a store returns the store, instead of a second owner of the
  same backend object.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ormalize URL paths

From review of ba5e2d0:

- The location was pickled with the backend, but an unpickled `LocalStore`
  resolves a relative prefix again against the receiving process's working
  directory, so the store wrote to one place and reported another. The
  location is now left out of the pickle and recomputed.
- URL paths (an HTTP store's, an S3 endpoint's) are decoded and normalized
  (empty and `.` segments dropped, `..` applied), so `https://h/a//b` builds
  instead of raising and percent-encoded names compare as keys. Default
  ports are dropped, IPv6 hosts keep their brackets, and an endpoint whose
  port isn't a number no longer makes construction raise.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Decoding `https://h/a%00b` gave a location path with a NUL, which
`Location` refuses, so building a backend over a URL obstore accepts raised.
Such a segment now stays encoded; no key can hold a NUL, so it overlaps no
decoded name.

Assisted-by: ClaudeCode:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@d-v-b

d-v-b commented Dec 1, 2026

Copy link
Copy Markdown
Owner Author

🤖 AI text below 🤖

Follow-up from an audit of the store views' shared base (_View), and what review found in it.

  • 8dc17a1 (the audit's fixes):

    • overlaps now compares data locations, not backend objects. Every backend names a Location, a space plus a path, so two backend objects over the same data are detected (the overlap case behind fix(array): detect overlapping source and destination across store roots #459). The local filesystem is one space shared by LocalBackend and obstore's LocalStore; object stores use endpoint and bucket plus prefix.
    • The constructors lose root=, so a backend has one owner.
    • One private constructor sets ownership.
    • with_read_only(bool) becomes as_read_only().
    • Write batches check keys before read-only.
  • Review of 8dc17a1 found three medium issues, fixed in ba5e2d0:

    • a relative LocalStore prefix resolved against the current working directory on every read;
    • HTTP URLs never overlapped when nested;
    • credentials in URL userinfo and query strings appeared in repr(location).

    Minor items, also fixed: endpoint trailing slashes, Location path validation, and copy.copy making a second owner. Case-insensitive filesystems still alias distinct names; DESIGN.md documents this.

  • Review of ba5e2d0 found one serious issue, fixed in 8af4f06: the location was pickled, but an unpickled relative LocalStore resolves again against the new working directory, so it wrote to one place and reported another. Minor items, also fixed: https://h/a//b raised on construction, percent-encoded paths, default ports, IPv6 hosts, and non-numeric ports.

  • Review of 8af4f06 found nothing serious. Minor, fixed in fce03f9: a URL path containing %00 raised on construction.

  • Review of fce03f9 found nothing serious, so review stopped after two clean rounds. Not fixed, because it errs toward reporting overlap (safe): https://h/%00 and https://h/%2500 now compare as overlapping, and %2F in a URL path merges segments. fce03f9's message says the kept segment "overlaps no decoded name"; that is not quite true, for this reason.

1824 tests pass on macOS (3.11, 3.14, 3.14t) and Linux; the docs build is strict-clean.

@d-v-b

d-v-b commented Dec 3, 2026

Copy link
Copy Markdown
Owner Author

🤖 AI text below 🤖

Replaced by #490 (the package, with zarr's store code in zarr_storage.legacy) and #491 (this PR's API, moved to zarr_storage.experimental, stacked on 490).

@d-v-b d-v-b closed this Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant