Skip to content

Local Zarr reader: shared read core, engine, nemar zarr read (from #2144) - #2406

Merged
neuromechanist merged 33 commits into
devfrom
feature/zarr-reader-core
Nov 26, 2026
Merged

neuromechanist merged 33 commits into
devfrom
feature/zarr-reader-core

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

This is marordyan's work from #2144 (ADR 0120), carried on an org-owned branch so CI runs with secrets. All credit for the read core, the engine and the CLI goes to marordyan; see #2144 for the design, the phase history, the reviews and the draft docs page.

The branch is #2144's head (98d273b) plus two merges of dev (3ae2464, 521 commits since the fork point 04b9d0b; 203029e, which brings in the 0.10.40 changelog and #2410) and the integration fixes below. The contributor's commits and authorship are kept; nothing was rebased or squashed.

Merge resolutions

  • .context/decisions/README.md: kept every dev entry (including the accepted statuses of ADR 0116 to 0119 and ADR 0121 to 0138) and added the ADR 0120 entry between 0119 and 0121.
  • test/adr-index.unit.test.ts: removed 120 (and its reservation comment) from TOLERATED_GAPS, since the ADR file is now present; the set is [127, 137].
  • CHANGELOG.md: dev's sections are unchanged. The Zarr reader entry (and its summary paragraph, which had auto-merged into the 0.10.34 section) now sits under ## Unreleased (above ## 0.10.40, after Changelog for 0.10.40: legal-process queue, ADR 0138 #2404 moved dev's entries there) as its own ### Local Zarr reader (#2144, ADR 0120) section, with Added, Changed and Known limits.

Integration fixes

  • src/lib/api/client.ts: the API URL override variable is named once, API_URL_OVERRIDE_ENV, and getApiUrl reads it; src/lib/zarr-engine/client.ts uses the constant in the engine's environment allowlist. test/zarr-engine-client.test.ts refers to the constant instead of the literal name, and test/zarr-read-report.test.ts builds its child environment from nothing. Before this, both files named the override literally, which scripts/ci/unit-pure-files.sh reads as "hits the live backend" and moves them out of the pure tier into the live tier. All new test files are now in the pure tier.
  • test/helpers/zarr-engine-standin.ts: runNemar builds the child environment from PATH, HOME and TMPDIR plus the stand-in's variables, instead of spreading the test process's environment (which carries the API URL override and any ambient credential). This also fixes 11 failures that appeared only on a machine with FORCE_COLOR set.
  • test/api-export-surface.unit.test.ts: pins the new API_URL_OVERRIDE_ENV export of lib/api/client (per-module map and post-split additions); the first CI run failed it.
  • test/zarr-engine-client.test.ts: the stand-in engine children read their reply frame from a file in the test directory instead of a base64 literal in bun -e. Linux refuses one argument over 128 KiB (E2BIG), so the two large-reply tests failed on the CI runner while passing on macOS.
  • test/zarr-engine-window.test.ts: the rangeCeiling sweep (about 27 million comparisons) collects violations and asserts once, instead of one expect() per comparison, which took 7.1 s against the 5 s default timeout on the runner. Same comparisons; a mutation of rangeCeiling (dropping the extra chunk) still fails it with the offending geometries listed.
  • No change was needed for the admin command tree (ADR 0135): zarr and engine are top-level groups, no moved-command entry collides with them, top-level help is not tiered, and the help-tier, completion, API export surface, moved-command and release-version-flag tests pass unchanged.
  • The MCP server compiles against the moved read core. dev's only MCP change since the fork (backend/src/mcp/tools/search-datasets.ts, b24d673) is untouched by this branch and kept; backend/src/mcp/server.ts is identical to dev and still registers all six tools.

Production impact (checked against this branch)

  • No migration, no Worker variable or secret, no wrangler change (no file under migrations or any wrangler configuration is in the diff).
  • The MCP tools answer as before: the read_window golden test passes; the other MCP tools changed only imports and comments.
  • One new public route: GET /schemas/zarr-engine-protocol-v0.json (backend/src/routes/schemas.ts).
  • One new CLI runtime dependency: fzstd 0.1.1, the zstd decoder the backend already uses at the same version.
  • package.json version untouched.

What I ran

  • bun run typecheck (root and backend): clean.
  • bun run lint: clean; biome lint --only=correctness/noUndeclaredVariables test/ backend/test/: clean.
  • Root targeted tests (45 files matching zarr, engine, mcp, doctor, adr-index, help-tiers, completion, api-export-surface, moved-commands, schema, docs, release-version-flag, ci-tier-routing): 1,827 pass, 3 skip. The 14 failures of the first run were the two causes fixed above; the six affected files were rerun after the fixes, 150 pass, 0 fail.
  • Backend targeted tests (28 files matching zarr, engine, mcp, doctor, schema, blosc, including the read_window golden test): 825 pass, 0 fail.
  • scripts/ci/unit-pure-files.sh lists every new test file.

What I did not run

  • The full bun test (about 80 minutes): CI runs it.
  • Live-tier files that the merge did not change (completion-network, completion-opportunistic-refresh, completion-refresh-command, docs-fetch, has-zarr-cli-flag, zarr-fidelity-sweep-cli, admin-restructure, cli): they need a live backend, and no command was run against production or staging.
  • mcp-smoke.sh under workerd and the manual production and staging reads reported in Add a local Zarr reader: shared read core, engine and nemar zarr read #2144 were not repeated.

CI notes

  • First run (e644f3c): unit-pure failed on the three issues fixed above. integration-dev shard 6/6 failed in test/repull-execute-prepare.test.ts (upload-failed), the same failure as on dev's own release pull request run; Fix re-pull upload tests under aws-cli 2.42 #2410 fixed it on dev and is merged in here. integration-dev shard 3/6 reported 0 failures and one unhandled error between tests in test/compute-user-e2e-cli.test.ts (the Tapis stand-in's has no subscription), a dev file this branch does not touch.

Known observation, not changed

  • With both FORCE_COLOR and NO_COLOR set in the user's environment, the engine child used to inherit both and Bun printed a warning on the engine's stderr. Resolved in review round 1 (finding 9): the engine child no longer receives FORCE_COLOR, NO_COLOR or TERM.

Review round 1

  • 1. Engine frames are read in linear time (pieces kept apart, joined once per frame): debba19. Test: a 128 MiB frame fed in 64 KiB pieces is read in linear time (3.8 s against a 250 ms bound with the fix reverted).
  • 2. The total of a window's range reads is capped by windowByteBudget, not only each read: 38b6cc1. Test: the window's reads are refused once their total passes the window's budget.
  • 3. The blosc decoder takes the expected decoded size from the caller's geometry and refuses a header nbytes, or a zstd frame content size, that differs before allocating; fzstd decompresses into a buffer of the block's size: d89aca8. Tests in backend/test/blosc-decode.test.ts (header nbytes, frame content size, frame without a content size); the read_window golden test passes unchanged.
  • 4. A NEMAR_ZARR_DISK_CACHE_DIR naming an existing non-empty directory without the marker is never chmodded or written; the cache is off with one stderr line, and nemar engine status (refused under --json) and nemar doctor say why; ADR 0120 updated: 75dd302.
  • 5. A window that fails with decode_error drops every cached entry it read (memory and disk, range bodies and footers), so the next read refetches; the decode_error hint names nemar engine cache clear; ADR 0120 updated: 530919b.
  • 6. CHANGELOG Local Zarr reader section: the inaccurate MCP sentence replaced, and the user-visible effects of fixes 1 to 5 added: 49017d0.
  • 7. nemar doctor turns any non-configuration error from the cache check into a failed check with a fixed message instead of crashing: bac51eb.
  • 8. Shared Zarr log lines use the [zarr] prefix instead of [mcp] and [read_window]: 4f4fd83.
  • 9. FORCE_COLOR, NO_COLOR and TERM are dropped from the engine child environment; ADR 0120 updated: 02ad26b.

Each fix was checked by turning it off once and seeing its test fail. Gates on the fix commits: root and backend typecheck, bun run lint, Biome on every changed file, and the targeted tests (root zarr, engine, contract-schemas, api-export-surface, adr-index: 1,139 pass; backend zarr-core, mcp, blosc-decode: 418 pass). The full suite was not run locally; CI runs it.

Review round 2

  • 1. A JSON cache entry a window stores on a miss (a footer fetched and put) is now recorded beside the entries it hit, so a window that fails with decode_error drops it too; ADR 0120 and the CHANGELOG now say "read or stored": 569f8f4. Test: a footer fetched on a miss that leads to undecodable bytes > is dropped with the window, so the next read fetches the footer again and succeeds (a stand-in footer with every offset one byte late, then the good one); with the put recording removed, the second read fails with decode_error.
  • 2. The frame reader timing test reads a 64 MiB frame in 16 KiB pieces against a 1000 ms bound (4 to 7 ms with the fix): 81b0664. With the pre-debba194 frame-stream.ts restored it took 3.35 s and failed.
  • 3. The streaming body tests assert behavior, not byte counts: the stand-in body ends at 64 MiB and flags it, each test polls up to 5 s for the cancel (with a 10 s test timeout so a missing cancel fails the assertion, not the timeout) and asserts the stream was cancelled and never ended: b4f78d7. A mutant of readBodyCapped that drains the body instead of cancelling fails all three; a mutant that only skips the cancel fails the JSON test, while on the two Range tests the server stream is still cancelled when the unread fetch body is dropped.

Gates on the round-2 commits: root and backend typecheck, bun run lint, Biome on every changed file, and the targeted zarr engine, zarr CLI, doctor, blosc-decode, zarr-core, mcp-read-window and mcp-overview tests (698 pass); the two rewritten test files passed three runs each. The full suite was not run locally; CI runs it.

marordyan and others added 20 commits November 5, 2026 07:06
* Pin read_window output with a golden test

* Move sharding to shared/zarr

* Move blosc decoder to shared/zarr/codecs

* Move isV3Index to shared/zarr

* Point path comments at shared/zarr

* Make golden capture runs fail loudly

* Type isV3Index with ZarrIndexAny

* Rewrap comments that name moved paths
* Rewrap ragged comment in get-events

* Add Fetcher and JsonCache to shared/zarr

* Move shard footer loading to shared/zarr

* Move array metadata loading to shared/zarr

* Move level-0 read loop to shared/zarr

* Move value assembly to shared/zarr

* Check shared/zarr read against zarr-python

* Point moved-function comments at shared/zarr

* Pin read_window error-stage texts

* Test shared/zarr cache contracts

* Soften shared/zarr throw guarantees

* Align shared/zarr loader docs
* Tighten footer cache overwrite check

* Add engine protocol schema and zod mirror

* Check protocol schema against zod mirror

* Add frame codec and cross-language fixtures

* Publish engine protocol schema as v0

* Record read core and protocol ADR

* Allow null id on unreadable requests

* Open responses, keep requests strict

* Add scale, offset and payload limit

* Specify window and range semantics

* Harden frame decoding and its tests

* Compile protocol schema strictly in test

* Fix schema route cache comment

* Align the engine protocol with neuroschema

Squash of the neuroschema alignment fix PR (a2a47e3..d07a787), reviewed in five rounds. Fork CI cannot run on this PR (its base is a feature branch); local gates: targeted root and backend tests, typecheck, Biome, byte-identical fixtures, and a full unit-pure run on d07a787 compared with base 785c172, its new failures rerun in isolation (clean by the pre-registered rule).
Sync the Zarr epic with upstream dev
Sync the Zarr epic with upstream dev
# Conflicts:
#	.context/decisions/README.md
#	CHANGELOG.md
Name the API URL override once (API_URL_OVERRIDE_ENV) and use it in the engine allowlist and its test; build the bad-config child env from nothing. Tested: zarr engine/cli/report suites.
runNemar no longer spreads the test process env into the child. Tested: zarr-cli, zarr-engine-cli, zarr-doctor-cli.
Linux refuses a single argv entry over 128 KiB (E2BIG); the child now reads the frame from the test dir. Tested: zarr-engine-client 36 pass.
27M expect() calls exceeded the 5 s CI timeout; violations are collected and asserted once. Mutating rangeCeiling still fails it. Tested locally.
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR2406

Version: 0.10.40-PR2406.b4f78d7
Commit: b4f78d7


🤖 Updated on each push.

A footer fetched on a miss and put during a window that then fails to decode is now dropped with it. Entry-point test with a misplaced footer; fails with the put recording removed.
64 MiB in 16 KiB pieces, bound 1000 ms. Still fails against the pre-debba194 quadratic reader (3.35 s).
The long-body stand-in now ends at 64 MiB and flags it; the tests poll for the cancel and assert the end was never reached. An unbounded-drain mutant of readBodyCapped fails all three.

This branch was previously deployed

1 inactive deployment
npm — b4f78d77 Deployed Nov 26, 2026 by neuromechanist via publish #5001
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants