All four finder agents are in and I've empirically verified the core findings by executing the affected functions. Here's the review. ## Summary The PR adds rectilinear (variable-sized) Zarr v3 chunk support. The read/roundtrip paths look solid and are well-tested. But the **write-side alignment & safety machinery is the weak spot**: the new rectilinear path reuses uniform-grid code (`align_nd_chunks`) that can't handle it, and re-implements validation (`_validate_rectilinear_chunk_alignment`) without replicating the `allow_partial_chunks` / region-start semantics the regular path carefully handles. None of these are exercised here because zarr 3.2.1 is installed (the feature gates off at `<3.2.2`), but they're reachable in CI with the newer zarr. I verified the `chunks.py` ones directly by running them — those functions are pure and version-independent. ## Bugs **1. `align_chunks=True` + rectilinear chunks crashes (chunks.py:29, via grid_rechunk → align_nd_chunks)** — *verified* `validate`/`grid_rechunk` are entered whenever `effective_write_chunks` is a tuple (zarr.py:1394/1400), which is true for rectilinear specs. `grid_rechunk` builds non-uniform backend chunks and hands them to `align_nd_chunks`, which rejects them: ``` align_nd_chunks(nd_v_chunks=((50,50),), nd_backend_chunks=((10,20,30,40),)) → ValueError: "...supports aligning chunks only when backend chunks are of uniform size... this scenario should never occur unless there is an internal misuse." ``` So writing a dask array with `encoding={"chunks":[[10,20,30,40]]}` and `align_chunks=True` dies with an "internal misuse" message on a perfectly valid user encoding. **2. `align_chunks=True` + rectilinear *silently misaligns* when the interior happens to be uniform (chunks.py:50)** — *verified* When the guard above doesn't trip (e.g. `[10,20,30]`), `align_nd_chunks` still assumes a single `fixed_chunk = max(...)` grid: ``` align_nd_chunks(((30,30),), ((10,20,30),)) → ((10, 30, 20),) ``` Output boundaries are 10/40/60, but the true zarr boundaries are 10/30/60 — the middle chunk straddles boundary 30. With `safe_chunks=True` this then gets *rejected* downstream (so `align_chunks` fails to do its one job); without it, the write is unsafe. **3 & 4. The rectilinear validator ignores `allow_partial_chunks` and never checks region-*start* alignment (chunks.py:214-238)** — *both verified* Unlike the regular path, `_validate_rectilinear_chunk_alignment` takes no `allow_partial_chunks` and only discards `total = sum(enc_chunks)` (full-array size), not the region's own end. Two opposite symptoms: - **False reject** of a legitimate partial region/append write whose end is interior to the array: ``` region=slice(0,50), dask=(20,20,10), enc=(20,20,20) → REJECTED (stop 50 isn't discarded) ``` - **False accept** of an unsafe `r+` write that *starts* mid-chunk — exactly what the regular path forbids at chunks.py:336: ``` region=slice(5,60), dask=(25,30), enc=(10,20,30) → ACCEPTED (no region-start check) ``` This defeats `safe_chunks=True`, whose purpose is to prevent that read-modify-write hazard. The region-write test only covers a region (`slice(10,30)`) that lands exactly on boundaries, so neither symptom is caught. **5. Write silently emits a rectilinear spec without checking the `array.rectilinear_chunks` config (zarr.py:~411)** — flagged by two finders `_determine_zarr_chunks` returns `tuple(var_chunks)` for non-uniform dask chunks based only on `_has_rectilinear_chunks()` (a library feature-check). The inline comment says the zarr config is *required*, but nothing enforces it. Previously this raised a clear xarray `ValueError`; now a user on zarr ≥3.2.2 who hasn't enabled the config gets an opaque failure (or unintended rectilinear metadata) deeper in zarr. The friendly-error test only runs when the library lacks the feature. **6. `chunk_layout` now intercepts *all* reads, including zarr v2-format stores, under zarr-python ≥3.2.2 (zarr.py:74-94)** — worth a look `_has_chunk_layout_api()` gates on `_zarr_v3()` (the *library* major version), not the *store's* `zarr_format`. So opening a plain v2 store with zarr-python 3.2.2+ now goes through `zarr_array.chunk_layout` instead of `zarr_array.chunks`/`.shards`, and the direct-read fallback (lines 91-92) becomes dead for v2. Probably fine, but it changes the read path for every v2 array and no v2 test asserts via `chunk_layout`. Worth confirming v2 arrays expose it identically, or gating on the actual store format. ## Simplifications - **chunks.py:172** — `boundaries = [0, *itertools.accumulate(chunk_sizes, initial=0)]` produces a duplicate leading zero (`accumulate(initial=0)` already prepends 0 → `[0,0,10,30,60]`). Harmless (the `(0,0)` pair is always skipped), but misleading. Use `list(itertools.accumulate(chunk_sizes, initial=0))`. - **zarr.py** — `_has_rectilinear_chunks()` is a pure pass-through to `_has_chunk_layout_api()`; collapse to one. And the two predicates `len(set(chunks[:-1])) > 1` / `chunks[0] < chunks[-1]` now appear in both the new rectilinear branch and the v2 error branch of `_determine_zarr_chunks` — factor into one `_chunks_are_rectilinear(var_chunks)` helper so the two paths can't drift. - **doc/user-guide/io.rst:1252** — says `zarr-python >= 3.2`, but whats-new.rst and the code docstring say `>= 3.2.2` (and the code explicitly excludes 3.2.0/3.2.1). Align to 3.2.2. (The section-underline length, flagged by one finder, is actually fine — title and underline are both 35 chars.) ## Recommendation The biggest gap is that `align_chunks` and the partial-chunk/region semantics aren't really handled for rectilinear grids — they reuse uniform-grid machinery. I'd suggest either (a) generalizing `align_nd_chunks` / the validator to be boundary-based for both regular and rectilinear (the deeper fix), or (b) explicitly rejecting `align_chunks=True` with rectilinear chunks and adding `allow_partial_chunks`/region-start handling to `_validate_rectilinear_chunk_alignment`, plus tests for: `align_chunks=True`, a non-boundary-aligned `r+` region write, and a partial trailing region write.