Repository navigation
Phase 1: typed verdicts for missing companion data - #1808
Merged
neuromechanist merged 13 commits intoOct 16, 2026
Merged
neuromechanist merged 13 commits into
neuromechanist merged 13 commits into
Conversation
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.
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR1808Version: 🤖 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.
neuromechanist
merged commit Oct 16, 2026
fc3f141
into
feature/issue-1800-epic-zarr-coverage-gaps
14 checks passed
This was referenced Oct 16, 2026
Merged
6 tasks
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 untilretry_exhausted.Commit 1 adds three NEMAR-side codes,
companion_missing,split_part_missingandepoched_recording, each with its own reason and listed in thefailure.codedescription ofshared/zarr-index.schema.json. They sit outsideRETRYABLE_CODESandSTORAGE_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 whoseDataFileis untracked with no same-stem.eegor.dat(extension case ignored, the biosigio#132 recovery), and an EEGLAB.setwhose samples are in an untracked, undeclared (ADR 0073).fdt, are refused ascompanion_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 issplit_part_missing(only when the tree lacks it), a three-dimensional.setisepoched_recording, and a.fdtwhose size disagrees with its header, pyedflib's bareOSErrorfrom the streaming EDF and BDF source, and the four bareOSErrormessages biosigIO's tolerant fallback raises for a truncated EDF or BDF arecorrupt_or_truncated. Any other code passes through untouched.The bare
OSErrorrule 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 inclassify_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 andTestStreamingRefusalCanary. Run against the local biosigio checkout that carries the fix, the canary fails with a message saying exactly that. The.fdtsize 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 andrequire_companionsare permanent.One extension of the plan's
.setrule, for review: the plan names the same-stem.fdtonly, but biosigIO's_read_fdtreads the same-stem file first and the name embedded inEEG.datasecond, so a.setwith no same-stem.fdtwhose embedded name is tracked beside it converts today (measured, and pinned bytest_a_set_whose_embedded_fdt_name_is_tracked_beside_it_still_converts).require_companionstherefore 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 pureTestFailureVerdictcases. Three existing tests described the old behavior and were updated, not weakened:TestConvertOneEeglabSidecarOvercountnow tracks the.fdtit writes, and the undeclared-.fdtcases inTestDeclaredFdtConvertOneandTestMainConvertsADeclaredFdtnow expectcompanion_missingnaming the file instead of the reader's "none was found".python scripts/zarr/test_generate_zarr.pywith 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).test_generate_zarr.pywithrequirements.txtand 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 (theRLIMIT_DATAbackstop,/proc/meminfoandclear_refsare 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.hallu-zarr.sh --teston 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.
TestReaderRefusalsThroughConvertOne.test_a_split_chain_without_its_next_part_is_split_part_missingfails, along with 6 pure cases inTestFailureVerdict.TestReaderRefusalsThroughConvertOne.test_an_embedded_epoched_set_is_an_epoched_recordingfails..fdtsize rule (rule 3):TestReaderRefusalsThroughConvertOne.test_a_fdt_of_the_wrong_size_is_corrupt_or_truncatedfails.OSErrorrule (rule 4):TestStreamedEdfRefusalThroughConvertOne.test_both_exporters_type_the_refusal_alike, bothTestMainAnnexMissingVerdict.test_a_streamed_refusal_*cases, bothTestFallbackTruncationThroughConvertOneconversions that stream a refused file, and the two pure cases that type the pyedflib text and the fallback's four messages fail. Dropping only itserrnoguard failsTestFailureVerdict.test_a_host_condition_is_not_a_refusal(the EIO and ENOSPC cases) andtest_a_host_condition_is_not_a_fallback_truncation; replacing its exacttype(...) is OSErrorwithisinstancefailstest_the_same_words_from_another_exception_are_not_a_refusalandtest_a_host_condition_is_not_a_fallback_truncation; reading the cause chain instead of the exception alone failstest_a_refusal_behind_another_exception_is_not_the_refusal,test_a_fallback_truncation_behind_another_exception_is_not_the_truncationandtest_the_walk_follows_exactly_exc_plus_five_links.failure_verdictnot wired intoconvert_one: eight full-tier tests fail, one per rule 1 to 3, the streamed-refusal conversion, both fallback-truncation conversions, and bothmain()cases.TestCompanionMissingThroughConvertOne.test_a_brainvision_header_without_its_data_file_is_companion_missingfails; removing the same-stem sibling exemption failstest_a_stale_brainvision_header_with_a_same_stem_data_file_converts.TestCompanionMissingThroughConvertOne.test_an_eeglab_set_without_its_fdt_is_companion_missingfails; removing the embedded-name exemption failstest_a_set_whose_embedded_fdt_name_is_tracked_beside_it_still_converts.require_companionsnot wired intoconvert_one: bothcompanion_missingfull-tier tests fail.companion_missingtoSTORAGE_STATE_CODESor toRETRYABLE_CODESfailstest_the_new_codes_join_neither_code_set,test_a_run_of_only_new_codes_is_deterministicand both companion full-tier tests; deleting any one new reason, or the codes from the schema description, failsTestTypedVerdictCodes.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.
Blocking, fixed in 7c3527d. Rule 4 read the
__context__chain, and biosigIO runs its tolerant EDF read inside theexceptblock that caught pyedflib's refusal, so a hostOSError(EIO) raised by that read carried the bare refusal as its context and became terminalcorrupt_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_linksnow 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_refusalasserts that a refusal behind another exception is not the refusal, and a real EDF that pyedflib refuses and biosigIO recovers is converted withOSError(EIO)injected atmne.io.read_raw, the fallback's one read of the samples, on both exporters. biosigIO's own host-condition tests usechmod 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.Important, fixed in 402b76f.
git ls-tree --name-onlyandgit diff --name-statusC-quote any name with a non-ASCII byte, sohead_filesheld a string no file has, and a header naming a tracked data file with a non-ASCII name (not the recording's stem) was refusedcompanion_missinghere although it converts on the base branch. Both listings now use-zand 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, fromdiscovered_countand from the incremental worklist, and a sidecar with such a name is invisible to the lookups that readhead_files. This fix therefore widens discovery for any dataset that has such a name. ADR 0033 says a widening needs a deliberateZARR_ENGINE_VERSIONbump, and this pull request does not bump it, so the owner can plan the requeue: the bump re-queues everydonedataset 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.pyhas its ownls-treecall 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 withcore.quotePathpinned on, coveringgit_ls_files,git_diff_name_statuswithcompute_worklist,discover_primaries, andrequire_companionsfor a BrainVision header and an EEGLAB.setnaming a tracked non-ASCII file.Important, fixed in efcb71f (tests only). Deleting
sibling in head_files orleft every.settest green, because the existing test has no file and cannot fail. The base converter converts a.setwhose embedded name is stale (BIDS renamed the.fdtwith it) when a same-stem.fdtis tracked, measured by running the base converter on that shape, and so does this branch. A unit test and aconvert_onetest now pin it, and both fail with the clause deleted.Nit, fixed in 4c99c2f. A v7.3
.setwith several epochs and an absent.fdtgotcompanion_missingwhere the base converter givesnot_continuous, because biosigIO refuses the epochs before it asks for the.fdt.require_companionsnow leaves that file to the reader.test_an_epoched_v73_set_without_its_fdt_keeps_the_epoched_verdictpinsnot_continuous, with controls: a continuous v7.3 file without its.fdtis stillcompanion_missing, and a classic epoched file without its.fdtis too (base givesfile_read_errorthere, the planned relabel; with its.fdtit converts, flattened).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.Nonenow restores the production default, and the test watches which writerwrite_storewas handed (stream_to_zarror none), so the path that ran is asserted rather than assumed.Nit, rejected. The BrainVision detail names the
DataFilethe header supplies. That name is already public in the tracked.vhdrfile in the dataset repository, so the index discloses nothing new. No code change.Residual, fixed in 689fdbe.
failure_verdicttested the exception's.codefor membership in a frozenset, so an unhashable code (a list) raisedTypeErrorout ofconvert_one'sexceptbranch; a.codethat is not a non-empty string is now read as absent, andtest_a_code_that_is_not_a_nonempty_string_is_absentfails on the previous code (TypeErrorfor a list or dict, a wrong verdict for the other values).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'sclassify_read_error(...) from ein each importer, andMaxShieldProbeFailedfrom the splitValueError); 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_toois rewritten to the cause contract astest_the_walk_does_not_follow_the_implicit_context, and the gate counts are those of the final tree below.Important, fixed in 6b9fd27. Rule 4 typed only pyedflib's text, but biosigIO's tolerant fallback raises its own bare, errno-less
OSErrorfor a file it finds cut short or with an unusable header (four messages inimporters/_edf_tolerant.py, biosigIO 1.2.11), so a streamed EDF whose first channel hasphysical_maxequal tophysical_min, cut to 60% of its length, was left uncoded and retried untilretry_exhausted, where the in-memory path types itcorrupt_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 otherOSErrorkeeps 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 throughconvert_oneon both exporters, a streamed file with an impossible signal count (streamed only, because biosigIO's in-memory path reports that file as a genericfile_read_error), and a canary case that fails when biosigIO types the fallback's errors.Nit, fixed in 34edb6c. New tests build a real temporary git repository with plumbing and pin
git_ls_files,git_diff_name_statusandcompute_worklistover 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 reachingremove.git_diff_name_statusnow raises when the-zfield list does not pair up as status and path, instead of zipping it short, with its own test.Nit, rejected. The
failing_diskhelper stubsmne.io.read_rawto 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 andconvert_onearound 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_DATAbackstop twice,RLIMIT_DATAcannot be set here,clear_refsand/proc/meminfo, all Linux-only);test_hallu_zarr_config.py238 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_truncatedwhereNoneis 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 withsibling in head_files ordeleted, in the fast and full tiers; finding 4, the epoched test fails withcompanion_missingwherenot_continuousis expected; finding 5, the BDF+ case fails with the old helper becausestream_to_zarris 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 wherecorrupt_or_truncatedis 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-renamesor removing the pairing check each fails between one and four of the seven new tests.Still not run: the sampled regression,
hallu-zarr.sh --teston 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.