Skip to content

SNIRF screening and generic HDF5 string scan (A4) - #2385

Merged
neuromechanist merged 20 commits into
feature/issue-2182-epic-pq-evidencefrom
feature/issue-2186-snirf-screen
Nov 26, 2026
Merged

neuromechanist merged 20 commits into
feature/issue-2182-epic-pq-evidencefrom
feature/issue-2186-snirf-screen

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Part of #2186. Part of #2182.

Card A4 of the publication-queue plan: .snirf files are screened with SNIRF semantics and .h5/.hdf5 with a generic string scan, both through A3's walker (shared/hdf5-meta.ts, unchanged) under A1's registry and page-cached source.

What changed

  • shared/readers/snirf.ts: the SNIRF reader. Every /nirs{i} group is screened. SubjectID follows readSubjectId (exported as the one shared rule; card A5 applies it to the EEGLAB subject field): nothing for a placeholder, the BIDS subject label or a short code (at most 12 letters, digits, - or _ that the slot name test does not flag); snirf-subject-name (identifier) when a token of letters only is name-like; snirf-subject-freetext (review) otherwise, including letters fused with digits (lead ruling B). MeasurementDate at day precision is snirf-measurement-date, a date kind (ADR 0090), never gating on its own.
  • shared/readers/hdf5-generic.ts: the generic reader and the text rules both readers share. hdf5-identifier-field applies the scanner's JSON identifier-key set to HDF5 field names (birth date at day precision is identifier, year or year-month is review, placeholders fire nothing; contacts are review). hdf5-freetext-name (identifier) only in person fields (PERSON_FIELDS: person words minus thing words, and a bare name, which names its own object); letters fused with digits there are hdf5-freetext (review). Everywhere else, including probe, stimulus and aux labels, only the local-user-path rule applies (hdf5-freetext, review).
  • shared/readers/hdf5-incomplete.ts: the one mapping from Hdf5Incomplete to the registry's reasons (A5 imports it), and walkForReader: a source refusal past the limits is partial (limit) with the findings so far, the reader's time is enforced at 80% of timeMs as partial (time) with the findings so far, and any other source failure is rethrown (a failed read, never partial or clean). The adapter uses A1's RangeSource directly (A3's local interface is structurally the same, so no wrapper) and imports only types from the registry, to avoid a module cycle.
  • Six new kinds with KIND_COPY entries; snirf-subject-name, hdf5-freetext-name and hdf5-identifier-field are direct kinds; snirf-measurement-date is a date kind.
  • Registration: READERS is now EDF, SNIRF, HDF5. .snirf, .h5 and .hdf5 stay in OTHER_RECORDING_EXTENSIONS, because the report's closed KNOWN_FORMATS list is built from it and stored reports and ZIP members still name them.

Limits (SNIRF and HDF5)

48 MiB fetched, 1,000 fetches, 180 s, and the walker's entry cap raised to 100,000. Measured over HTTP range reads: a typical file's metadata takes 1.7 MiB (p50) to 6.9 MiB (p90) in 27 to 104 fetches, because the page cache reads 64 KiB pages and large files spread object headers among their data. High-density files with thousands of measurementList groups need far more: 13 MiB in 203 fetches for 31,800 entries, 38 MiB in 573 fetches for 66,500 entries. The earlier 16 MiB cap left 49 of 296 files partial (limit); these caps leave none.

False-positive gate

scripts/dev/reader-fp-measure.ts over 296 public SNIRF files from 30 OpenNeuro fNIRS datasets (up to 10 per dataset, spread across each dataset's list), anonymous HTTP range reads through the registry's page cache; nothing is written to disk. The generic reader ran over the same 296 files (all HDF5) with --any-extension; OpenNeuro's fNIRS datasets hold only 8 .h5 files.

Reader Complete Partial Failed
snirf 215 61 (time 37, corrupt 14, unsupported-version 10) 20 (HTTP 403)
hdf5 216 60 (time 36, corrupt 14, unsupported-version 10) 20 (HTTP 403)

Findings per 100 files (identifier / review):

Kind snirf hdf5
hdf5-identifier-field 9.80 / 0 9.80 / 0
snirf-subject-freetext 0 / 3.38 n/a
hdf5-freetext 0 / 0 0 / 3.38
snirf-measurement-date (date kind, never gates) 0 / 65.20 n/a
  • Identifier findings: all 29 are true positives: a DateOfBirth metaDataTag at day precision, in 29 of the 296 sampled files (ds004514: 10, ds004541: 9, ds005963: 10). Those conversions will be blocked until the field is scrubbed; the copy's remedy says so.
  • Review findings (excluding the date kind): 3.38 per 100, all from ds007990, whose SubjectID is a cohort word fused to digits.
  • time partials come from a home connection at 16 files in parallel; the screen reads from storage in the same region. The 403s are two datasets (ds008544, ds008892) whose objects are not anonymously readable.

Deviations from the card (accepted by the lead)

  1. A field named just name is not a person field: it names its own object (a stimulus, an aux channel, a group). Without this, the generic reader made about 8 identifier findings per public SNIRF file.
  2. Ruling B (letters fused with digits are review) applies to person fields as well as SubjectID.
  3. "At most 512 KiB read per fixture" is asserted on the bytes the reader asks for; the page cache fetches 64 KiB pages, so fetched bytes are larger (Homer3: 169 KB asked, 633 KB fetched) and are capped at 1 MiB in the test.
  4. No separate role for stimulus, aux and probe labels: with the bare-name exemption their field names name no person, so the generic rules already give them the local-path rule only (a separate role became untestable dead code).
  5. .snirf, .h5 and .hdf5 stay in OTHER_RECORDING_EXTENSIONS, because KNOWN_FORMATS is built from it.
  6. Existing tests that used .hdf5/.h5 as unscreened examples now use .nwb; the A1 contract tests that stub a .snirf reader run with EDF only.

Byte budget at the file's size

A boundary test (a byte budget of size - 1 serves every byte but the last; asking for the last is refused) pins A1's page cache at maxBytes = size - 1 and = size. My earlier note that a clipped page "never reports limited" was a misreading: re-measured on snirf-two-groups.snirf at a budget of size - 1, the reader's highest byte asked is 277,647 of 277,802, so it is complete with nothing withheld; a read that needs a clipped byte is refused and marks the source limited. Marking every budget-clipped page as limited would make every EDF/BDF file partial (its 256-byte budget clips the first page of every file), so cachedSource is unchanged; three mutations of its budget logic fail the boundary test.

The time partials in the gate are not re-measured here; the lead records them as a risk, to be measured on the first production re-screen.

Tests

  • test/readers-snirf.test.ts, test/readers-hdf5-generic.test.ts: real fixtures and h5py-written variants (README beside them): a two-group file built by copying /nirs with the oracle script's writer (both groups fire), a made-up SubjectID name (fires snirf-subject-name), the real files' placeholders (fire no subject kind), no read range overlapping any dataTimeSeries and at most 512 KiB asked per fixture (the page cache rounds that up: Homer3 asks 169 KB and fetches 633 KB), truncated files partial, a failing source rethrown.
  • A revert check per rule: 31 one-line mutations (each rule, both directions of the short-code bound, the thing and person lists, the bare-name exemption, the birth-date precision split, the placeholder set, the walker reason mapping, limit, time and rethrow, registration, the direct and date kinds); all 31 fail the targeted tests.
  • Existing tests that used .snirf, .h5 or .hdf5 as unscreened examples now use .nwb, and the A1 contract tests that stub a .snirf reader run with EDF only.

Gates: bun run typecheck and bun run lint clean; bun test test/readers-snirf.test.ts test/readers-hdf5-generic.test.ts test/identifier-fleet.test.ts: 198 pass, 0 fail. Pure tier: 27,869 pass, 4 fail; the failures (website account-copy parity, which reads a sibling website checkout, and one git-annex UUID retry test) fail the same way on the base branch, and the fourth (the pinned date-kind list) is fixed in this PR.

@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@PR2385

Version: 0.10.40-PR2385.d43a493
Commit: d43a493


🤖 Updated on each push.

…nce' into feature/issue-2186-snirf-screen

# Conflicts:
#	scripts/dev/reader-fp-measure.ts
#	shared/identifier-readers.ts
#	shared/identifier-scan.ts
#	shared/identifier-screen-copy.ts
#	shared/identifier-screen-report.ts
#	test/identifier-coverage-contract.test.ts
#	test/identifier-screen-report.test.ts
@neuromechanist

Copy link
Copy Markdown
Contributor Author

Merge gate (lead): head d43a493; every remote check passes. Review: round 1 panel, 2 important findings (strings skipped for size came back complete; numeric identifier fields were ignored) and 5 more fixed; a seam fix gives one shared person-field rule for NIRx and HDF5; round 2 delta review resolved every item and found a behavior change, now fixed in d43a493 (describing-field exclusion, whole-token matching, the "-1" placeholder) and verified by the lead from the diff and 332 targeted tests. No third round. False-positive gate: 296 public SNIRF files; the identifier findings are all day-precision DateOfBirth true positives.

@neuromechanist
neuromechanist merged commit f6942e0 into feature/issue-2182-epic-pq-evidence Nov 26, 2026
31 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-2186-snirf-screen branch November 26, 2026 01:01
This was referenced Nov 27, 2026

This branch was previously deployed

1 inactive deployment
npm — d43a4935 Deployed Nov 26, 2026 by neuromechanist via publish #4924
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