Skip to content

feat: browser recipe leads with read_window - #1487

Merged
neuromechanist merged 4 commits into
devfrom
feature/recipe-leads-with-read-window
Sep 23, 2026
Merged

neuromechanist merged 4 commits into
devfrom
feature/recipe-leads-with-read-window

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

nemar_read_window's python_browser recipe handed a model open_array plus getitem, whose result is the stored digital counts. A model that plotted that got a figure that looks like EEG and is wrong, with nothing raising. The recipe's own trailing comment pointed at read_window, but a model follows the code, not the comment. OSA's assistant did exactly that when told to plot (OpenScience-Collective/osa phase 3, #432).

At level 0, the lane now leads with the read in physical units, and names the index by the recipe's own contract_base:

index = await eegprep_lean.read_index("nm000103", index_url="https://zarr.nemar.org/nm000103/zarr/index.json")
store = index.store("<store path>")
window = await eegprep_lean.read_window(index, store, group=store.group("eeg_250hz"), start_sample=..., n_samples=...)
  • Why index_url. read_index's default URL is production's. Naming the index by contract_base means a dev or staging server's recipe reads that environment. index_url is new in eegprep-lean 0.1.0.dev2 (eegprep-lean: let read_index take an explicit index URL sccn/eegprep#416), and the snippet says so.
  • The raw read stays. digital = await arr.getitem(...) follows as the alternative, and is the only read at a view level, which read_window does not read.
  • ADR 0071 records this decision and what it costs. The lead fetches the dataset's index.json once: measured on zarr.nemar.org, nm000103's is 2.7 MB of JSON and 98 KB on the wire. The decision also adds a coupling, to eegprep-lean 0.1.0.dev2. ADR 0070 keeps a one-line amendment pointing at it, and its verdict is unchanged. Both reviewers judged an amendment alone a close call, which is why this is a separate ADR.
  • Escaping. Every value written into any lane's snippet is now a JSON.stringify literal, valid in Python and in JavaScript. store.path and group names are free-form strings in the index schema, and they are written into code a client runs.
  • buildReadRecipe now carries index.dataset_id and store.path through to buildHowTo, its only caller. The zod 4 lane description says the same.

Merge order: after sccn/eegprep#416. OSA vendors 0.1.0.dev2 in its phase 3 before its browser lane is live anywhere; until then, OSA's prompt carries its own snippet and does not depend on this recipe's shape. docs.nemar.org does not quote python_browser, so no docs change is needed.

Test plan

  • bun test test/contract-mcp.unit.test.ts (75), and backend/test/mcp-schema-parity, mcp-read-window, mcp-recording-tools and mcp-route (210).

  • New tests:

    • leads with read_window before the raw read;
    • names the dataset id, index_url, the store path and the group exactly;
    • a staging contract_base is named, not production's;
    • every call goes through eegprep_lean.;
    • a view level reads raw and says why.

    Each was mutation-checked (production URL, a bare call, read_window at a view level, raw read first), and each mutation failed its test.

  • The recipe this code emits for nm000103 (from production's index document) ran verbatim on CPython with eegprep-lean 0.1.0.dev2 against the live archive. read_window gave (129, 500) in uV at 250 Hz with labels E1 onward, and the raw read gave int16 counts.

  • Review fixes: an exact-block test for the read_window call, and a round-trip test of a quote and backslash in the path, group and zarr name for all three lanes. Each was mutation-checked: an unescaped path, swapped arguments, and an unescaped zarrita path each failed.

  • bun run typecheck, bun run lint, and the ADR index test.

At level 0 python_browser now reads through read_index, index.store
and read_window, which return physical units with channel labels, and
names the index by the recipe's own contract_base so a dev or staging
server reads its own environment. The open_array read of array_path
follows as the raw alternative, and is the only read at a view level,
which read_window does not read. buildReadRecipe carries the dataset
id and store path through to buildHowTo.

Tested: bun test contract-mcp, mcp-schema-parity, mcp-read-window,
mcp-recording-tools, mcp-route; typecheck; lint; each new test
mutation-checked; the emitted recipe for nm000103 run verbatim on
CPython with eegprep-lean 0.1.0.dev2 against the live archive.
@github-actions

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR1487

Version: 0.10.6-PR1487.d9d614e
Commit: d9d614e


🤖 Updated on each push.

path and group names are free-form in the index schema and are now
written into code a client runs, so each interpolated value in all
three lanes is a JSON.stringify literal, valid in Python and in
JavaScript. Adds an exact-block test for the read_window call and a
round-trip test for a quote and backslash in each lane.

Tested: bun test contract-mcp (75), mcp-schema-parity,
mcp-read-window; each new test mutation-checked.
@neuromechanist

Copy link
Copy Markdown
Contributor Author

Local review, two Sonnet reviewers (code and tests). Every finding is addressed:

  • Unescaped interpolation (store.path and group names are free-form, and are written into code a client runs): every value in all three lanes is now a JSON.stringify literal, with a round-trip test (02a6f543).
  • Amendment or new ADR: the lead changes the call shape and adds an index fetch and a version coupling, so it is ADR 0071, with the cost measured. ADR 0070 keeps a one-line pointer (d9d614e9). The two line breaks the reviewer flagged went with the amendment text.
  • The read_window call pinned only in fragments: there is now an exact-block test, mutation-checked with swapped arguments (02a6f543).
  • The view level is reached by no tool (both read_window call sites pass level "0"): the test now says so. The branch exists because buildReadRecipe accepts a level.
  • Nothing runs the snippet here: by design, as this repository has no Python. The behavioral proof is the consumer's: OSA's frontend/test-data-lane.js runs recipes verbatim in real Pyodide, and in OSA's phase 3 it runs this recipe once it vendors 0.1.0.dev2. A daily OSA workflow will also run production's live recipe verbatim against the vendored wheel. The CPython run in the description was by hand.

Merge after sccn/eegprep#416.

This branch was previously deployed

1 inactive deployment
npm — d9d614e9 Deployed Sep 23, 2026 by neuromechanist via publish #2812
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.

1 participant