Skip to content

Zarr: adopt biosigio 1.2.10 - #1552

Merged
neuromechanist merged 7 commits into
devfrom
feat/zarr-biosigio-1.2.10
Sep 29, 2026
Merged

neuromechanist merged 7 commits into
devfrom
feat/zarr-biosigio-1.2.10

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Adopts biosigio 1.2.10 (biosigio#140, closing #136) in the Zarr converter, on dev only. The <1.2.10 cap in scripts/zarr/requirements.txt listed what adopting it needed; this PR does those things and then raises the cap.

Changes

1. fix: publish case-only sidecar matches bounded (e71d3f7)

  • The per-channel map is no longer republished. biosigio 1.2.10 adds matched_case_insensitive, {sidecar_name: channel_label}, to its channels_tsv_units report, and store_metadata copied that report into every store's index entry verbatim. That map has one entry per matched channel, in every store entry. The new bound_units_report (in generate_zarr.py) replaces it with:
    • units_report.matched_case_only: an integer count, at least 1. It is absent when there are no case-only matches, which is how the other unmatched_* counts behave.
    • units_report.matched_case_only_examples: at most CASE_MATCH_EXAMPLES_MAX (5) strings of the form "<channels.tsv name> -> <store label>", in channels.tsv row order. It is present exactly when the count is.
    • Every other key biosigio reports passes through unchanged. A value of an unknown shape is dropped rather than republished.
  • Why the bound happens in store_metadata. Bounding at that point means the map never reaches the entry. The previous code only touched units_report when the converter had resolved channels_rel, so a report without it would still have been published verbatim. The full map now travels only as the _case_matches diagnostic, which _-prefixed stripping keeps out of the published entry, and sidecar_join_report reads it from there. I confirmed by reading the code that store_metadata is the only place that republishes channels_tsv_units. The store's own zarr.json still holds biosigio's full report, which is the store's own metadata.
  • The same declaration in all three mirrors: shared/zarr-index.schema.json, shared/contract/zarr-index.ts (zod) and backend/src/mcp/schemas.ts (z4).
  • The JSON Schema refuses the raw map. It declares matched_case_insensitive as {"not": {}}, so the converter's pre-upload self-check refuses an index that carries it. The zod mirrors stay passthrough, so a consumer does not reject an index over it.
  • Reworded texts. unmatched_channels now says a row reaches the channel it names exactly, or (from 1.2.10) the one channel it names in another letter case when that match is unambiguous. unmatched_case_only stays declared, for older stores, and is described as "differed only in case and was not matched: converted before 1.2.10, or the case match was ambiguous".
  • Tests.
    • TypeScript: the JSON Schema maxItems and both zod .max() bounds are tied to CASE_MATCH_EXAMPLES_MAX, which the tests read from generate_zarr.py. They follow the UNMATCHED_EXAMPLES_MAX pattern in test/zarr-schema-contract.test.ts and backend/test/mcp-schema-parity.test.ts. There are also rejection cases for a zero count, non-string examples, and the raw map.
    • Python: unit tests of bound_units_report, and a test that the schema bound equals the constant.
    • This commit passes on both 1.2.9 and 1.2.10. The old canary's 1.2.10 branch was updated to the bounded fields.

2. feat: adopt biosigio 1.2.10 in the converter (45c5f61)

  • The pin is now biosigio[zarr,meg,mef3,hdf5]>=1.2.10,<1.2.11 in all three places at once:

    • requirements.txt
    • the BIOSIGIO_SPEC fallback in hallu-zarr.sh, together with BIOSIGIO_FLOOR="1.2.10", which setup()'s post-install floor probe uses
    • test_hallu_zarr_config.py

    The upper bound is still a cap that is raised on purpose for each release. The comments in requirements.txt and hallu-zarr.sh now say what 1.2.10 adds, and that the three texts and the bounded field were done in this change.

  • Floor tests.

    • 1.2.9 joins the parameters that must be refused. It is also the case where a string comparison would go wrong against a 1.2.10 floor.
    • The accepted versions are now 1.2.10, 1.2.11, 1.10.0 and 2.0.0.
    • I also ran the real floor probe against real venvs: 1.2.10 exits 0 and 1.2.9 exits 3.
  • The canary now runs against the real 1.2.10 in CI. It is renamed test_a_case_only_row_is_applied_and_reported_per_biosigios_join, and CI installs from requirements.txt. It asserts biosigio's case matching directly instead of branching on it. It runs through convert_one on a real EDF whose header has FP1-F7 and a sidecar with Fp1-F7, on both exporters, and checks:

    • the sidecar's V is applied and the channel is converted
    • unmatched_channels: 0, and no unmatched_case_only and no warning
    • matched_case_only: 1 with ["Fp1-F7 -> FP1-F7"], and no raw map in the entry
    • the store's own attributes still hold biosigio's full map
    • the merged index validates against the schema
  • New end-to-end tests through convert_one (real files, biosigio 1.2.10):

    • An ambiguous case row (FZ and Fz in the file, fz in the sidecar) stays unmatched, is reported under unmatched_case_only, and keeps the importer's unit.
    • A 300-channel EDF with a sidecar in a different case: matched_case_only: 300, 5 examples, units_report under 600 bytes. Compared with the same recording under an exact sidecar, the entry grows by less than 400 bytes; biosigio's map alone would be about 9 KB. The index validates.
    • The existing repeated-label CHB-MIT test (test_every_repeated_label_is_served_on_both_exporters) still passes on 1.2.10: all channels are present, the gate passes, and the index and manifest validate.
  • Updated .memory/repeated-channel-labels-collapse-stores.md, which said the texts still claimed exact matching.

Other 1.2.10 changes, checked against this repo

  • select_channels raising, add_channel, the EDF export sidecar: nothing here calls select_channels, add_channel or the EDF exporter (checked with git grep over scripts).
  • XDF, EEGLAB, neo and Trigno now record channel_labels_deduplicated. label_renames already reads that key for any importer, so positions_for_renamed_labels and unmatched_raw_label now also cover those formats. Nothing needed changing.
  • Trigno keeping repeated channels, and EEGLAB/XDF/neo suffixes that no longer take a real label (Fz, Fz, Fz_2 becomes Fz, Fz_3, Fz_2): these change the bytes of a regenerated store only for files with such collisions. See below.

Engine stamp (ADR 0033): not bumped, on purpose

ZARR_ENGINE_VERSION is unchanged.

  • What the stamp is for. ADR 0033 defines it as a statement that discovery widened. It exists so a back catalog that the old engine could not see reconverts itself. The ADR rejects library patch releases as a trigger by name, because every one would requeue the archive.
  • 1.2.10 discovers exactly what 1.2.9 did. It changes the bytes of a regenerated store only in two cases:
    • A channels.tsv that differs from the file's labels only in case. The row is now applied, and a unit that differs converts the samples, as with nm000110's FP1-F7 against Fp1-F7.
    • An XDF, EEGLAB, neo or Trigno file whose repeated labels collide with a label it really uses.
  • Why a bump would be wrong. It would requeue the whole archive, which is days of compute and an S3 rewrite, to change a small cohort. That is the same reasoning under which 1.2.8 and 1.2.9 did not bump it.
  • Recovery is evidence-driven. Stores converted since the join report was added (0.10.9) show the first case as units_report.unmatched_case_only, so a targeted --dataset or requeue --status done --dataset <id> --execute run fixes them. Older stores do not carry the report and need to be found from their channels.tsv.
  • Stores already published stay served until requeued (ADR 0005). A merge only changes what the next conversion does.

Tests run

  • pytest on biosigio 1.2.10 (installed with uv pip install --refresh --no-cache), across test_generate_zarr.py, test_zarr_queue.py, test_purge_non_raw_stores.py, test_find_collapsed_channel_stores.py and test_hallu_zarr_config.py: 917 passed, 5 skipped (Linux-only). The 58 failures are all in test_hallu_zarr_config.py and all come from this host's bash 3.2 (hallu-zarr.sh requires bash 4+); the unmodified branch fails the same way (56, plus the 2 new floor parameters). No bash 4+ is available on this host, so CI (bash 5) is where these run. The pin tests that do not need bash pass.
  • scripts/test_patch_duration.py and test_patch_power_line_frequency.py pass on 1.2.10.
  • Commit 1's join and convert_one classes pass on biosigio 1.2.9 as well.
  • A deliberate regression (republishing the raw map) fails the canary and the 300-channel test.
  • bun test zarr mcp: 879 pass at the root and 679 pass in backend/. The ADR index test passes, and bun run lint and the typecheck hooks are clean.
  • ruff: no new findings compared with origin/dev. ty: no findings on changed lines.

Follow-ups (not in this PR)

  • The public index contract page (docs.nemar.org/platform/zarr/index-contract/) should describe matched_case_only and matched_case_only_examples, and the reworded unmatched_case_only.
  • After dev -> main, requeue nm000110 and any dataset whose index shows unmatched_case_only, one dataset at a time. find_collapsed_channel_stores.py --case-only --all lists them (see the review round below).
  • The store contract page (docs.nemar.org/platform/zarr/store-contract/) should say that a store's root zarr.json still carries biosigio's full per-channel matched_case_insensitive map in its channels_tsv_units report (a root attribute from the streaming exporter, under recording_metadata from the in-memory one). This is by design: only the index entry is bounded, because it repeats per store in one document, while the store's attributes are that store's own metadata.

Review round 1

3. fix: heal a carried raw case-match map on merge (acb5fb1)

  • merge_index carries unchanged stores from the prior index verbatim. An entry published with biosigio's raw matched_case_insensitive map (a 1.2.10 run before the converter bounded it: staging, an exemplar, an ad hoc --dataset on a branch) would be re-carried by every incremental run and fail the pre-upload schema check each time, until a --clean rebuild.
  • Each carried entry whose units_report holds the map now goes through bound_units_report. The count and examples are derived from the map and the map is dropped, so the entry heals on the next merge. Other entries are carried as they were, and prior is not mutated.
  • Test: a prior index with such an entry (40 matches), which the schema refuses as published, merged with a new store. The merged index validates, the carried entry has matched_case_only: 40, 5 examples, no raw map, and its other keys unchanged. The test fails without the fix.

4. feat: find stores whose sidecar missed by case (1ccac5f), docs: name the case-only detector for requeues (f9a06d3)

  • find_collapsed_channel_stores.py --case-only is a read-only mode that reads each dataset's index.json and nothing else. I chose a mode over a separate script because it reuses the same HTTP client, Retry-After handling, pacing, catalog walk and exit-status rules.
    • It flags entries with units_report.unmatched_case_only > 0: stores converted before 1.2.10, where the sidecar's type and unit were not applied. It also flags stores where the case match was ambiguous, which a requeue does not fix; the docstring says so.
    • It counts separately, as unverifiable, the entries that have no join report (no units_report.unmatched_channels); no_units_report is broken out. The docstring, the stderr progress line and the report's unverifiable_note say plainly that these cannot be enumerated from the index. They can only be found by comparing each recording's channels.tsv with the store's labels.
    • It counts entries where 1.2.10 did match by case (matched_case_only) for information only.
    • Exit status: 1 when anything is flagged. Otherwise 2 when a dataset was unreadable, any entry is unverifiable, or the --all catalog walk was incomplete; "unchecked" is never reported as clean. The report has its own format name (nemar-zarr-case-only-join-report).
    • --repo-dir and --labels are refused with --case-only.
  • Tests run against a real local HTTP server laid out like the zarr host. They cover the mix of verdicts, a request log showing that only index.json is read, a 503 that outlives the retries, a 404, an index without a stores list, Retry-After on a 429, and an incomplete --all walk. No git repository is involved, because this mode never reads one.
  • The requirements.txt comment and .memory/repeated-channel-labels-collapse-stores.md now name this mode as the way to find affected datasets. They also say the XDF/EEGLAB/neo/Trigno collision case has no detector. The memory file also lost a stale sentence that said 1.2.10 was capped out.

5. fix: check the biosigio cap and pre-releases (9b6f64f)

  • setup()'s post-install check in hallu-zarr.sh is now two-sided. The installed biosigIO must be a final release in [BIOSIGIO_FLOOR, BIOSIGIO_CAP) (new BIOSIGIO_CAP="1.2.11"). The probe exits 3 below the floor or when the version is unreadable, 4 at or above the cap, and 5 for a pre-release or dev build. setup() prints a distinct FATAL for each and stops before the queue is touched.
  • The packaging path and the fallback now agree. The fallback accepts only a canonical final release (N(.N)*, with an optional .postN and +local), so 1.2.10rc1 and 1.2.10.dev0 are refused on both paths. Before, a tuple of leading digits read them as 1.2.10 and accepted them.
  • Tests:
    • The accepted set is now 1.2.10, 1.2.10.post1 and 1.2.10+local.1.
    • 1.2.11, 1.2.11.post1, 1.10.0 and 2.0.0 must be refused with the cap FATAL.
    • Five pre-release and dev spellings must be refused on both paths.
    • BIOSIGIO_CAP must be the < half of BIOSIGIO_SPEC.
    • A table of 21 versions is run through the probe exactly as extracted from the script, on both paths. That test needs no bash, so it also runs on macOS.
    • The ack_run fixture's default version moved from 9.9.9 to 1.2.10.
  • The real probe run against real venvs: biosigio 1.2.9 exits 3 and 1.2.10 exits 0. The setup() block, run under bash, prints the floor FATAL for 1.2.9, biosigio 1.2.10 for 1.2.10, and the cap and pre-release FATALs for 1.2.11 and 1.2.10rc1 stubs. Real biosigIO venvs always have packaging (matplotlib imports it), so the fallback path is covered by the stub table only.

Operational note: the first retry after deploy is a full rebuild

This is existing design, stated here so it is not a surprise. pending_retry_worklist limits a retry round to the pending recordings only when the published index was built with the same commit, engine, biosigIO version and provenance. Every index built before this deploy says biosigio_version: 1.2.9. So the first retry round for a dataset with pending recordings falls back to a full rebuild ("the index was built with a different biosigIO"). Later rounds are pending-only again.

Tests run (this round)

  • pytest on biosigio 1.2.10 (installed with uv pip install --refresh --no-cache), across test_generate_zarr.py, test_zarr_queue.py, test_purge_non_raw_stores.py, test_find_collapsed_channel_stores.py and test_patch_power_line_frequency.py: 944 passed, 5 skipped (Linux-only).
  • test_hallu_zarr_config.py: the 51 tests that do not need bash 4 pass, including all the new probe and cap/spec tests. The 74 that invoke hallu-zarr.sh fail on this host's bash 3.2 only (requires bash 4+), so CI (bash 5) is where they run.
  • bun test zarr mcp: 879 pass at the root and 679 pass in backend/.
  • ruff: no new findings compared with origin/dev, compared by rule and message. ty: no new diagnostics on the changed files. shellcheck: clean.

biosigio 1.2.10 reports every channels.tsv row it matched only by
ignoring case in a per-channel map, which units_report republished
verbatim. Replace it with a count (matched_case_only) and at most five
examples, declared in the JSON Schema, zod and MCP z4 mirrors, and
refuse the raw map in the schema. Reword unmatched_channels and
unmatched_case_only, which said matching is exact.

Tested: bun zarr-schema-contract and mcp-schema-parity; pytest join
and convert_one classes on biosigio 1.2.9 and 1.2.10.
Raise the pin to >=1.2.10,<1.2.11 in requirements.txt, the hallu-zarr.sh
fallback and BIOSIGIO_FLOOR, and test_hallu_zarr_config.py. The case-only
canary now asserts 1.2.10's join on real EDFs through convert_one; new
tests cover an ambiguous case row and a 300-channel case-differing
sidecar whose index entry stays small. ZARR_ENGINE_VERSION unchanged.

Tested: pytest converter suites on biosigio 1.2.10 (hallu config tests
that need bash 4+ not runnable on this macOS host); ruff no new findings.
@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR1552

Version: 0.10.10-PR1552.3911b28
Commit: 3911b28


🤖 Updated on each push.

@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review record

One Sonnet 5.5 review pass. No critical findings. Verified by the reviewer: every path that builds a units_report (local and remote channels_rel, in-memory and streaming exporters, --retry-pending) goes through store_metadata, which bounds the map, so a freshly converted entry cannot carry biosigio's per-channel matched_case_insensitive map; the deploy path is safe (flock -n precedes setup(), so a parallel --dataset run exits 3 while a drain holds the lock; a mid-dataset drain never re-runs setup and stops at the dataset boundary; a failed install makes the post-install probe exit and setup stop with FATAL before the queue is touched); the zod and MCP mirrors are .passthrough(), so nothing consumer-side rejects the new keys; positions_for_renamed_labels never overwrites and correctly gives EEGLAB renames like Fz_3 the position of Fz; the engine-stamp argument (ADR 0033: no bump, since 1.2.10 does not widen discovery) is sound; the canary and the 300-channel size bound are deterministic; the Linux CI job that runs the hallu config tests passed, so the 58 macOS failures were the bash 3.2 guard.

# Finding Resolution
1 (important) merge_index copies prior entries verbatim: an entry published earlier on 1.2.10 with the raw map would fail the schema's {"not": {}} refusal on every later incremental merge, wedging the dataset until a --clean rebuild merge_index passes each carried entry through _heal_carried_units_report, which turns a raw map into the bounded count and examples and drops the map (pure; the prior index is not mutated). Real test: a prior index with a 40-entry raw map (which the schema refuses as published) merged with a new store gives a schema-valid index with matched_case_only: 40, 5 examples, no map, all other keys unchanged; fails without the fix
2 (important) "Requeue affected datasets" was not actionable: the detector only found short channel counts New --case-only mode of find_collapsed_channel_stores.py (reuses the HTTP client, Retry-After, pacing, catalog walk and exit rules): reads only index.json, flags entries with unmatched_case_only > 0, counts entries with no join report as unverifiable and says plainly they must be found from their channels.tsv. Exit 1 when anything is flagged, else 2 when a dataset was unreadable, any entry is unverifiable or the walk was incomplete. Real local-HTTP-server tests (503 past retries, 404, missing stores, 429 with Retry-After, incomplete --all, a request log proving only index.json is read). Requirements comment and memory entry name it and say the XDF/EEGLAB/neo/Trigno collision cases have no detector
3 The floor check was one-sided and the two comparison paths disagreed on 1.2.10rc1 Two-sided: new BIOSIGIO_CAP="1.2.11" with separate FATALs for each probe exit (3 below floor or unreadable, 4 at or above the cap, 5 pre-release or dev); the fallback path now accepts only a canonical final release, agreeing with the packaging path; a test ties BIOSIGIO_CAP to the < half of BIOSIGIO_SPEC; a 21-version table runs the extracted probe on both paths without bash. Real probe on real venvs: 1.2.9 exits 3, 1.2.10 exits 0
4 First retry after deploy is a full rebuild Stated in the PR body: biosigio_version differs (1.2.9 vs 1.2.10), so pending_retry_worklist falls back to a full rebuild for datasets with pending recordings (existing design)
5 The store's root zarr.json still carries the full per-channel map By design (only the index is bounded); recorded as a follow-up for the docs store-contract page (docs issue nemarOrg/docs#51 updated)

Verification: 944 passed, 5 skipped on biosigio 1.2.10 (test_generate_zarr.py, test_zarr_queue.py, test_purge_non_raw_stores.py, test_find_collapsed_channel_stores.py, test_patch_power_line_frequency.py); bun test zarr mcp 879 at the root and 679 in backend/; ruff and ty no new findings vs origin/dev; shellcheck clean. The 74 test_hallu_zarr_config.py tests that invoke hallu-zarr.sh need bash 4+ and run in Linux CI. Engine stamp unchanged (ADR 0033).

@neuromechanist
neuromechanist enabled auto-merge (rebase) September 29, 2026 16:46
@neuromechanist
neuromechanist merged commit 9f672d3 into dev Sep 29, 2026
12 checks passed
@neuromechanist
neuromechanist deleted the feat/zarr-biosigio-1.2.10 branch September 29, 2026 16:51
neuromechanist added a commit that referenced this pull request Sep 29, 2026
* docs: CHANGELOG entry for 0.10.10

Covers #1550 (Sonnet 5.5 enrichment, DOI lookups, relation guard) and
#1552 (biosigio 1.2.10 case-only sidecar matches). Claims checked against
the merged code.

* docs: add #1556 to the 0.10.10 entry

Failed-lookup warnings, the lookup-stage deadline, the over-cap marker,
and the summary now printing warnings. Changelog format test passes.
@neuromechanist neuromechanist mentioned this pull request Sep 29, 2026

This branch was previously deployed

1 inactive deployment
npm — 3911b282 Deployed Sep 29, 2026 by neuromechanist via publish #2964
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