Skip to content

Phase 1: typed verdicts for missing companion data - #1808

Merged
neuromechanist merged 13 commits into
feature/issue-1800-epic-zarr-coverage-gapsfrom
feature/issue-1801-phase1-typed-verdicts
Oct 16, 2026
Merged

neuromechanist merged 13 commits into
feature/issue-1800-epic-zarr-coverage-gapsfrom
feature/issue-1801-phase1-typed-verdicts

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Phase 1 of the Zarr coverage epic. Recordings whose data is missing, or whose reader refuses them, now get a typed, terminal verdict where the converter reported an opaque file_read_error, a MaxShield decline, or (for a streamed EDF or BDF refusal) infrastructure that it retried until retry_exhausted.

  • Commit 1 adds three NEMAR-side codes, companion_missing, split_part_missing and epoched_recording, each with its own reason and listed in the failure.code description of shared/zarr-index.schema.json. They sit outside RETRYABLE_CODES and STORAGE_STATE_CODES, so a run that converts nothing and fails only with them is deterministic, and a test pins both sets.

  • Commit 2 adds require_companions, which asks the git tree before any read. A BrainVision header whose DataFile is untracked with no same-stem .eeg or .dat (extension case ignored, the biosigio#132 recovery), and an EEGLAB .set whose samples are in an untracked, undeclared (ADR 0073) .fdt, are refused as companion_missing, naming the missing file by its BIDS path.

  • Commit 3 adds failure_verdict, the one place a reader's refusal becomes a code. It reads the exception and five __cause__ links (never __context__, and rule 4 reads the exception alone) and refines only the generic codes: a missing next FIF split part is split_part_missing (only when the tree lacks it), a three-dimensional .set is epoched_recording, and a .fdt whose size disagrees with its header, pyedflib's bare OSError from the streaming EDF and BDF source, and the four bare OSError messages biosigIO's tolerant fallback raises for a truncated EDF or BDF are corrupt_or_truncated. Any other code passes through untouched.

The bare OSError rule and its canary, TestStreamingRefusalCanary, are temporary until biosigio 1.2.12 ships PR #150, which closes #149, types the streaming refusal and wraps the streaming fallback in classify_read_error. The pinned 1.2.11 still leaves both bare, so rule 4's fallback text match is still needed; at that release it is deleted with its canary case, and so are the rest of the rule and TestStreamingRefusalCanary. Run against the local biosigio checkout that carries the fix, the canary fails with a message saying exactly that. The .fdt size rule is defense until biosigIO types the mismatch, and the epoched rule goes dead when biosigio#142 reads epoched files (#1214 then sets the policy). The split rule and require_companions are permanent.

One extension of the plan's .set rule, for review: the plan names the same-stem .fdt only, but biosigIO's _read_fdt reads the same-stem file first and the name embedded in EEG.data second, so a .set with no same-stem .fdt whose embedded name is tracked beside it converts today (measured, and pinned by test_a_set_whose_embedded_fdt_name_is_tracked_beside_it_still_converts). require_companions therefore also accepts a tracked file of the embedded name beside the .set, read with scipy or h5py only on the rare path that would otherwise refuse; a name it cannot read falls back to the plan's rule. Without it the rule would turn a served store into a failure, which the issue's acceptance criteria forbid. It is one isolated function, _eeglab_fdt_reference, if it should come out.

Closes #1801

Part of #1800

Test plan

Real files and real libraries through convert_one (pyedflib, MNE, scipy, h5py, biosigIO 1.2.11); constructed exceptions appear only in the pure TestFailureVerdict cases. Three existing tests described the old behavior and were updated, not weakened: TestConvertOneEeglabSidecarOvercount now tracks the .fdt it writes, and the undeclared-.fdt cases in TestDeclaredFdtConvertOne and TestMainConvertsADeclaredFdt now expect companion_missing naming the file instead of the reader's "none was found".

  • Fast tier, python scripts/zarr/test_generate_zarr.py with jsonschema and pyarrow only: 844 tests, OK, 52 skipped (baseline 769 tests, 37 skipped; the added skips are the classes and cases that need MNE, scipy, h5py or pyedflib).
  • Full tier, pytest on test_generate_zarr.py with requirements.txt and pyedflib: 1028 passed, 5 skipped, 0 failed (baseline 924 passed, 5 skipped). The 5 skips are the same tests as at baseline and all are macOS host skips (the RLIMIT_DATA backstop, /proc/meminfo and clear_refs are Linux-only), so Linux CI runs them; none comes from a missing dependency or the real-data download.
  • test_hallu_zarr_config.py: 238 passed.
  • bun install && bun test test/zarr-schema-contract.test.ts test/contract-zarr-index.unit.test.ts: 39 pass, 0 fail. backend/test/zarr-index-v3.test.ts: 36 pass.
  • The other zarr script suites that import the converter (queue, purge, collapsed-channel detector, admission ledger, admission across drivers, memory projection, power-line patch): 425 passed, 10 skipped.
  • Each commit passes on its own: commit 1 fast 774 OK (37 skipped) and full 929 passed; commit 2 fast 801 OK (43 skipped) and full 963 passed; the two newest commits likewise (6b9fd27 fast 837 OK, 52 skipped, full 1021 passed; 34edb6c fast 844 OK, 52 skipped, full 1028 passed).
  • Sampled regression, hallu-zarr.sh --test on three converting exemplars (BrainVision, EEGLAB, FIF): not run here, it needs the exemplar datasets on Hallu.

Deletion evidence

Each rule was deleted in turn from the final tree and the new tests run; the full-tier test that fails is named, and the file was restored from git after every run.

  • Split rule (rule 1): TestReaderRefusalsThroughConvertOne.test_a_split_chain_without_its_next_part_is_split_part_missing fails, along with 6 pure cases in TestFailureVerdict.
  • Epoched rule (rule 2): TestReaderRefusalsThroughConvertOne.test_an_embedded_epoched_set_is_an_epoched_recording fails.
  • .fdt size rule (rule 3): TestReaderRefusalsThroughConvertOne.test_a_fdt_of_the_wrong_size_is_corrupt_or_truncated fails.
  • Bare OSError rule (rule 4): TestStreamedEdfRefusalThroughConvertOne.test_both_exporters_type_the_refusal_alike, both TestMainAnnexMissingVerdict.test_a_streamed_refusal_* cases, both TestFallbackTruncationThroughConvertOne conversions that stream a refused file, and the two pure cases that type the pyedflib text and the fallback's four messages fail. Dropping only its errno guard fails TestFailureVerdict.test_a_host_condition_is_not_a_refusal (the EIO and ENOSPC cases) and test_a_host_condition_is_not_a_fallback_truncation; replacing its exact type(...) is OSError with isinstance fails test_the_same_words_from_another_exception_are_not_a_refusal and test_a_host_condition_is_not_a_fallback_truncation; reading the cause chain instead of the exception alone fails test_a_refusal_behind_another_exception_is_not_the_refusal, test_a_fallback_truncation_behind_another_exception_is_not_the_truncation and test_the_walk_follows_exactly_exc_plus_five_links.
  • failure_verdict not wired into convert_one: eight full-tier tests fail, one per rule 1 to 3, the streamed-refusal conversion, both fallback-truncation conversions, and both main() cases.
  • BrainVision companion rule: TestCompanionMissingThroughConvertOne.test_a_brainvision_header_without_its_data_file_is_companion_missing fails; removing the same-stem sibling exemption fails test_a_stale_brainvision_header_with_a_same_stem_data_file_converts.
  • EEGLAB companion rule: TestCompanionMissingThroughConvertOne.test_an_eeglab_set_without_its_fdt_is_companion_missing fails; removing the embedded-name exemption fails test_a_set_whose_embedded_fdt_name_is_tracked_beside_it_still_converts.
  • require_companions not wired into convert_one: both companion_missing full-tier tests fail.
  • Adding companion_missing to STORAGE_STATE_CODES or to RETRYABLE_CODES fails test_the_new_codes_join_neither_code_set, test_a_run_of_only_new_codes_is_deterministic and both companion full-tier tests; deleting any one new reason, or the codes from the schema description, fails TestTypedVerdictCodes.

Published rows

Published rows change only on reconversion: the index entries already on zarr.nemar.org keep their old codes (retry_exhausted, file_read_error, maxshield_probe_failed) until a targeted requeue or the Phase 3 requeue on source-commit drift reconverts the dataset, so this pull request alone moves no number on the catalog.

Review round 2

All eleven review findings are handled in ten commits on this branch, pushed once per review round, one per finding except the two rejected ones, plus 4a1d8e9, a comment-and-canary-wording commit that dates rule 4's removal to biosigio 1.2.12.

  1. Blocking, fixed in 7c3527d. Rule 4 read the __context__ chain, and biosigIO runs its tolerant EDF read inside the except block that caught pyedflib's refusal, so a host OSError (EIO) raised by that read carried the bare refusal as its context and became terminal corrupt_or_truncated, where the base converter leaves it uncoded and retried, in memory and streaming. Rule 4 now reads the exception itself and nothing behind it; rules 1 to 3 still walk the chain because they match a message, not an exception type. test_the_walk_follows_exactly_exc_plus_five_links now asserts the new contract (the five-link bound is checked on rule 3, and rule 4 does not ride the walk at any depth), test_a_refusal_behind_another_exception_is_not_the_refusal asserts that a refusal behind another exception is not the refusal, and a real EDF that pyedflib refuses and biosigIO recovers is converted with OSError(EIO) injected at mne.io.read_raw, the fallback's one read of the samples, on both exporters. biosigIO's own host-condition tests use chmod 000, which cannot reach the fallback because pyedflib's open fails first and raises the host error before any recovery, so the injection is at the read call. The streaming, main() and canary tests are unchanged and green.

  2. Important, fixed in 402b76f. git ls-tree --name-only and git diff --name-status C-quote any name with a non-ASCII byte, so head_files held a string no file has, and a header naming a tracked data file with a non-ASCII name (not the recording's stem) was refused companion_missing here although it converts on the base branch. Both listings now use -z and NUL splitting, which also keeps discovery and the incremental worklist correct. The same bug is present on the base branch: measured over a real repository, a recording with a non-ASCII name is absent from discovery, from discovered_count and from the incremental worklist, and a sidecar with such a name is invisible to the lookups that read head_files. This fix therefore widens discovery for any dataset that has such a name. ADR 0033 says a widening needs a deliberate ZARR_ENGINE_VERSION bump, and this pull request does not bump it, so the owner can plan the requeue: the bump re-queues every done dataset whose stamp is older, not only the affected ones, and until then an affected dataset picks the recordings up only when it is next reconverted for another reason. find_collapsed_channel_stores.py has its own ls-tree call and is unchanged; it is a read-only reporting tool, and a non-ASCII sidecar name is missed there the same way. Tests run over a real temporary repository with core.quotePath pinned on, covering git_ls_files, git_diff_name_status with compute_worklist, discover_primaries, and require_companions for a BrainVision header and an EEGLAB .set naming a tracked non-ASCII file.

  3. Important, fixed in efcb71f (tests only). Deleting sibling in head_files or left every .set test green, because the existing test has no file and cannot fail. The base converter converts a .set whose embedded name is stale (BIDS renamed the .fdt with it) when a same-stem .fdt is tracked, measured by running the base converter on that shape, and so does this branch. A unit test and a convert_one test now pin it, and both fail with the clause deleted.

  4. Nit, fixed in 4c99c2f. A v7.3 .set with several epochs and an absent .fdt got companion_missing where the base converter gives not_continuous, because biosigIO refuses the epochs before it asks for the .fdt. require_companions now leaves that file to the reader. test_an_epoched_v73_set_without_its_fdt_keeps_the_epoched_verdict pins not_continuous, with controls: a continuous v7.3 file without its .fdt is still companion_missing, and a classic epoched file without its .fdt is too (base gives file_read_error there, the planned relabel; with its .fdt it converts, flattened).

  5. Nit, fixed in 6261083. StreamEdfThreshold.use(test, None) kept whatever threshold the earlier file had set, so the in-memory half of the BDF+ case also streamed. None now restores the production default, and the test watches which writer write_store was handed (stream_to_zarr or none), so the path that ran is asserted rather than assumed.

  6. Nit, rejected. The BrainVision detail names the DataFile the header supplies. That name is already public in the tracked .vhdr file in the dataset repository, so the index discloses nothing new. No code change.

  7. Residual, fixed in 689fdbe. failure_verdict tested the exception's .code for membership in a frozenset, so an unhashable code (a list) raised TypeError out of convert_one's except branch; a .code that is not a non-empty string is now read as absent, and test_a_code_that_is_not_a_nonempty_string_is_absent fails on the previous code (TypeError for a list or dict, a wrong verdict for the other values).

  8. Residual, fixed in 3b48315. Rules 1 to 3 still followed __context__ when no __cause__ was set, the pattern finding 1 fixed for rule 4, so this supersedes the statement in finding 1 that they still walk the chain: they now follow __cause__ only, which every wrapping site sets (biosigIO's classify_read_error(...) from e in each importer, and MaxShieldProbeFailed from the split ValueError); three new tests put each rule's refusal in a host error's context and fail on the previous code, test_the_walk_follows_the_implicit_context_too is rewritten to the cause contract as test_the_walk_does_not_follow_the_implicit_context, and the gate counts are those of the final tree below.

  9. Important, fixed in 6b9fd27. Rule 4 typed only pyedflib's text, but biosigIO's tolerant fallback raises its own bare, errno-less OSError for a file it finds cut short or with an unusable header (four messages in importers/_edf_tolerant.py, biosigIO 1.2.11), so a streamed EDF whose first channel has physical_max equal to physical_min, cut to 60% of its length, was left uncoded and retried until retry_exhausted, where the in-memory path types it corrupt_or_truncated. Rule 4 now also types an exactly-OSError, errno-less exception whose text is <path>: followed by one of those four messages (the exact text, at the top level only); every other OSError keeps its retry. Tests: pure cases (the four messages typed; a host error, a subclass, another exception type, near-miss wording and a truncation behind another exception all untyped), a real cut EDF through convert_one on both exporters, a streamed file with an impossible signal count (streamed only, because biosigIO's in-memory path reports that file as a generic file_read_error), and a canary case that fails when biosigIO types the fallback's errors.

  10. Nit, fixed in 34edb6c. New tests build a real temporary git repository with plumbing and pin git_ls_files, git_diff_name_status and compute_worklist over names holding a space, tab, newline, quote, backslash, edge whitespace, bytes that are not UTF-8 and a non-ASCII letter: every name once and byte for byte, no empty trailing field, the A, D, M and T statuses kept, a rename reported as a deletion and an addition, and deletions reaching remove. git_diff_name_status now raises when the -z field list does not pair up as status and path, instead of zipping it short, with its own test.

  11. Nit, rejected. The failing_disk helper stubs mne.io.read_raw to raise a disk error and stays: a disk fault cannot be produced deterministically on a real file, so the stub injects one at the library boundary for the host-error path only, and the file, pyedflib's refusal, biosigIO's fallback and convert_one around it are real.

Gates on the final tree: fast tier 844 tests, OK, 52 skipped (the added skips are the classes and cases that need MNE, scipy, h5py or pyedflib); full tier 1028 passed, 5 skipped, 0 failed, and the 5 skips are the same macOS-only host skips as before (RLIMIT_DATA backstop twice, RLIMIT_DATA cannot be set here, clear_refs and /proc/meminfo, all Linux-only); test_hallu_zarr_config.py 238 passed. The shared schema is untouched, so the bun schema tests were not rerun.

Mutation evidence, each new test run against the code from before its fix: finding 1, the real EIO test fails on both exporters with corrupt_or_truncated where None is expected, along with the new unit cases; finding 2, five of the six new git tests fail on the quoted listing (the sixth is a control that names a file the tree lacks); finding 3, both tests fail with sibling in head_files or deleted, in the fast and full tiers; finding 4, the epoched test fails with companion_missing where not_continuous is expected; finding 5, the BDF+ case fails with the old helper because stream_to_zarr is reached in the in-memory half; finding 9, run against the code from before 6b9fd27, the streaming half of the cut-file test and the impossible-signal-count test fail with no code where corrupt_or_truncated is expected, and so do the four pure fallback-truncation cases, while the in-memory half passes; finding 10, removing the empty-field filter, decoding names lossily, stripping them, splitting them on lines, dropping --no-renames or removing the pairing check each fails between one and four of the seven new tests.

Still not run: the sampled regression, hallu-zarr.sh --test on three converting exemplars (BrainVision, EEGLAB, FIF), which needs the exemplar datasets on Hallu. Finding 2 is the change it would exercise most, since it alters the tree listing every run reads.

StreamEdfThreshold.use(test, None) left the threshold at the 1 an earlier file had set, so the in-memory half of the BDF+ case also streamed. None now restores the production default, and the test checks the writer that ran. Fast tier 818 OK (46 skipped); full-tier refusal class passes, and fails with the old helper.
The EDF refusal rule walked the __context__ chain, so a host OSError raised while biosigIO recovers from a pyedflib refusal became terminal corrupt_or_truncated instead of keeping its retry. Rule 4 now matches the top-level exception only; the walk tests assert that, and a real degenerate-range EDF with EIO injected at the fallback read covers both exporters. Fast tier 820 OK (47 skipped); the new tests fail on the old rule.
git ls-tree and git diff C-quote any name with a non-ASCII byte, so head_files held a string no file has. A header naming a tracked Mueller_01.eeg was refused as companion_missing, and discovery and the incremental worklist already dropped such recordings on the base branch. Both listings now use -z. This widens discovery for datasets with non-ASCII names, which ADR 0033 says needs a ZARR_ENGINE_VERSION bump; not bumped here. Tested over a real repository: fast tier 826 OK (48 skipped), the new tests fail on the old listing.
Deleting 'sibling in head_files' from require_companions left every .set test green, though a .set whose embedded name is stale (BIDS renamed the .fdt with it) then failed companion_missing. Add a unit test and a convert test for that shape: both pass on the base converter and on this branch, and both fail with the clause removed. Fast tier and the full-tier companion classes pass.
A v7.3 .set with several epochs and an absent .fdt got companion_missing, where the base converter gives not_continuous (biosigIO refuses the epochs before it asks for the .fdt). require_companions now leaves such a file to the reader. Tests pin the verdict through convert_one with a continuous v7.3 control and a classic epoched control. Fast tier 829 OK (51 skipped); the epoched test fails without the change.
@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR1808

Version: 0.10.20-PR1808.4a1d8e9
Commit: 4a1d8e9


🤖 Updated on each push.

failure_verdict tested the exception's code for membership in a
frozenset, so an unhashable code (a list) raised TypeError out of
convert_one's except branch. A code that is not a non-empty string is
now read as uncoded and gets the generic handling.

Tested: new TestFailureVerdict case; fast tier 830 OK.
The verdict walk followed __context__ when there was no __cause__, so a
host error raised while a handler held a reader's refusal was typed as
the refusal (split_part_missing, epoched_recording, corrupt_or_truncated)
and lost its retry. Rule 4 already read only the top-level exception.
The walk now follows __cause__ only. Every wrapping site raises from its
cause: biosigIO's classify_read_error(...) from e in each importer, and
MaxShieldProbeFailed from the split ValueError in is_maxshield_fif.

Tests: new cases put each rule's refusal in a host error's context. The
implicit-context test depended on the old walk and is rewritten to the
cause contract; raised_while_handling now catches any exception.
Fast tier 833 OK; full tier 1013 passed, 5 skipped; hallu config 238.
A streamed EDF or BDF that pyedflib refuses and biosigIO's tolerant fallback finds cut short raised the fallback's own bare OSError, which failure_verdict left uncoded, so the recording was retried until retry_exhausted. Rule 4 now also types the four truncation messages the fallback raises (exact tail text, errno-less, top-level OSError only). Tests: pure cases, a real cut EDF through convert_one on both exporters, and a canary case.
Tests build a real repository with names holding spaces, tabs, newlines, quotes, backslashes, edge whitespace and bytes that are not UTF-8, and check that git_ls_files and git_diff_name_status return every name once, byte for byte, with the A, D, M and T statuses and a rename as D plus A. git_diff_name_status now raises on a field list that does not pair up instead of zipping it short.
Comment and canary wording only: biosigio PR #150 (closes #149) types the streaming refusal and wraps the streaming fallback in classify_read_error, so at 1.2.12 the fallback text match, its canary case and the rest of rule 4 are deleted. The pinned 1.2.11 still leaves them bare.
@neuromechanist
neuromechanist merged commit fc3f141 into feature/issue-1800-epic-zarr-coverage-gaps Oct 16, 2026
14 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-1801-phase1-typed-verdicts branch October 16, 2026 15:17

This branch was previously deployed

1 inactive deployment
npm — 4a1d8e98 Deployed Oct 16, 2026 by neuromechanist via publish #3642
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