Skip to content

Phase 3: uploader-side identifier preflight - #1635

Merged
neuromechanist merged 21 commits into
feature/issue-1610-epic-identifier-screeningfrom
feature/issue-1613-phase3-upload-preflight
Oct 7, 2026
Merged

neuromechanist merged 21 commits into
feature/issue-1610-epic-identifier-screeningfrom
feature/issue-1613-phase3-upload-preflight

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Phase 3 of epic #1610 (issue #1613): the identifier preflight that runs on the uploader's machine.
The decision is recorded in ADR 0087.
Design note: #1613 (comment)

Part of #1613. This does not close the issue: the converter request is a draft for the maintainer to send.

What it does

  • When it runs. nemar dataset upload (and nemar upload) screens the dataset after the account checks, and before the tool checks, BIDS validation, the co-author ORCID step and the create call. A refusal therefore sends nothing. The preflight reads local files only and makes no network request.
  • A second screen. The tree is screened again right before the create call, and that second scan is the record that is sent. The upload stops if the second scan finds direct identifiers, or a condition the acknowledgment did not cover.
  • The same scan as publication. It uses the fleet scan's scanDatasetFromManifest with the clone source, which is what the publication screen uses, through a local reader:
    • 256 bytes of every EDF/BDF header, and nothing beyond the header;
    • side files and tables up to LOCAL_SCAN_LIMITS, one definition now shared with the CI screen.
  • What it walks. The files the upload plan lists. What it cannot see is counted, never skipped:
    • an unlistable directory makes the scan tree-truncated;
    • a broken link, a special file or an unopenable file is never opened, and is a failed read when the scan reads that kind of file;
    • a directory named .gitattributes is walked, because the plan's find lists its files.
  • Verdicts.
    • direct-identifiers: the upload is refused, also under --dry-run. There is no override.
    • A lesser verdict needs an acknowledgment that names every condition found: the verdict, plus unchecked when the scan is incomplete, plus not-screened when some recordings are in formats the scanner cannot read.
    • The acknowledgment is either a prompt that defaults to no (Ctrl+C exits 130), or --acknowledge-identifier-preflight. The flag is repeatable or comma-separated, and its list must match the conditions exactly.
    • --yes never acknowledges, and --dry-run never prompts.
  • What is printed. The report contract's verdicts and count lines (describePreflight), and no value or path. Format names come only from a closed list (KNOWN_FORMATS); anything else is printed and stored as .other.
  • The record. It is stored as identifier_preflight inside the datasets.attestation JSON, so no new column is needed.
    • parseUploaderPreflight is the door: closed kinds, counts and fixed words, no dataset identity, and every field required. It refuses a status cleaner than its counts. It requires an acknowledgment (prompt or flag, never free text) exactly when the gate needs one.
    • A refused record is not stored. The refusal is named by a fixed word and never fails the upload.
    • A resume from the local config records the attestation and the preflight through the new PUT /datasets/:id/attestation (owner or admin, private and never published). Before this, that path dropped the attestation.
    • The detail route serves none of the record. readRecordedPreflight reads it back as recorded, absent or unreadable.
    • A record that was not stored is always a warning that names the cause, never a refusal.
  • Refactor, no behavior change:
    • the report parser's scan body is split out;
    • verdict words and count lines are shared;
    • the format and failure folds move into the contract module and are re-exported by the CI lib;
    • the local-read limits are exported from the fleet lib.
  • Converter request. A draft for MNE-BIDS and MOABB is in .context/draft-converter-subject-info-request.md. Its counts are placeholders until the fleet re-run, it names no dataset or source, and it carries a checklist for the maintainer. Nothing was filed.

Tests

  • test/identifier-preflight-contract.test.ts (22): the preflight record contract, including the closed format list.
  • test/upload-identifier-preflight.test.ts (42): the step, on real trees, walked in name order so output is the same on every filesystem:
    • EDF/BDF headers, BrainVision and EEGLAB files;
    • links, both git-annex's layout and links outside the dataset, plus a broken link and a link to a directory;
    • a FIFO, an unlistable directory, chmod-000 files, and a truncated recording;
    • a 100 KiB side file, 301 exports, and an extension that is a name;
    • the conditions that review hides, and the recheck;
    • an 8 GiB sparse recording, and 24,001 files with 6,000 headers read in about one second.
  • test/upload-identifier-preflight-cli.test.ts (13): real subprocess runs.
    • Refusal, the flag (exact, and comma-separated), --yes, --no, and offline.
    • Past the preflight with no tools on PATH.
    • At a real pseudo-terminal: Enter (no), y, and Ctrl+C.
    • Asserted every time: no request beyond GETs, no .git created, and no name or path in the output.
    • Includes a source pin for the hop from the action to the create call.
  • test/upload-preflight-recording.test.ts (10): the wire, on create and on local resume, and each warning cause.
  • backend/test/identifier-preflight-route.test.ts (15) on real D1, including the fresh create's claim INSERT.
  • Pins updated: datasets route inventory (62 entries) and the API export surface.
  • All new test files run in the required pure tier. The CLI and wire tests name their stand-in in the config file, and the CLI tests strip every TEST_ variable from the child process.
  • Mutation check: 66 one-line mutants, all killed, with git status clean after each.
  • bun run typecheck and biome on every changed source file.
  • Full root suite before the review fixes: 10,789 pass, 105 fail. All 105 failures are in four files this branch does not touch (101 in backend/test/neurobagel-writer.test.ts). They time out at 5 s under concurrent load, and pass when run alone. Second run: 10,914 pass and 7 fail, all in untouched files (see the CI comment).

Review

Two Sonnet reviews ran: code-reviewer and silent-failure-hunter. Findings and their disposition are in the comment below.

For the maintainer

These were defaulted to the stricter reading:

  • refusal under --dry-run;
  • no override for direct identifiers;
  • an acknowledgment that names every condition, exactly, with no free text;
  • unchecked can be acknowledged, as at the admin gate;
  • a record that was not stored warns and continues;
  • no per-file report;
  • a second screen before the create call.

Not covered (ADR 0087, Consequences):

  • later pushes, the web upload and raw git-annex;
  • formats other than EDF/BDF;
  • symlink target text;
  • files the CLI writes after the second screen;
  • kinds inside review.

Split the report parser's scan body from its identity check, name each
state's verdict once with the count lines in one helper, move the
format and failure folds into the contract module (re-exported by the
CI lib), and export the local-read byte limits from the fleet lib.
No behavior change. Tested: identifier report, CI screen, fleet and
scan suites (332 pass).
UploaderPreflight is the scan an uploader's CLI made before sending
anything, parsed at the door like the publication report: closed kinds,
counts and fixed words, no dataset identity, every field required, a
status no cleaner than its counts, and an acknowledgment (prompt or
flag, never text) present exactly when the gate needs one.
describePreflight says each verdict in the screen's own words.
Tested: preflight contract (19) and report (26) suites.
Screens a dataset directory on the uploader's machine with the fleet
scan's clone-source scan (every EDF/BDF header, 256 bytes; side files
at the publication screen's limits), counting unlistable directories,
broken links and special files as unread. Direct identifiers refuse;
lesser verdicts need a prompt or a flag naming the verdict; --dry-run
previews. Tested: 25 step tests on real trees (links, FIFO, sparse
8 GiB file, 24,001 files in about a second).
createOrResumeDataset sends identifier_preflight beside the attestation
on create, and on a resume from the local config (which never reached
the create route, so its attestation was dropped) records both through
PUT /datasets/:id/attestation. A record the backend did not store is
always a warning, never a refusal. Tested on the wire against a Bun
stand-in (8); api export pin updated (recordDepositAttestation).
nemar dataset upload (and nemar upload) runs the preflight after the
account checks and before the tool checks, validation, the ORCID step
and the create call, so a refusal sends nothing. New option
--acknowledge-identifier-preflight <verdict>, limited to the gate's
acknowledge set; help text says what is read and what is printed.
Tested: 7 subprocess runs that end at the preflight (no request beyond
GETs, no .git created, no name or path in the output, offline too).
POST /datasets and the new PUT /datasets/:id/attestation (owner or
admin, private and never published) store identifier_preflight inside
the attestation JSON after the report contract parses it. A refused
record is not stored, never fails the request, and is named by a fixed
word; the detail route serves none of it. readRecordedPreflight reads
it back as recorded, absent or unreadable. Tested: 13 route tests on
real D1; route inventory pin updated (62 entries).
Local screen before anything is sent, the publication screen's scan
and words, no override for direct identifiers, a verdict-bound
acknowledgment with no free text, recorded inside the attestation and
never trusted. Tested: adr-index (passes).
For MNE-BIDS and MOABB, counts only, naming no dataset or source,
with what the maintainer must check before anything is filed. Nothing
was filed. Not tested (prose).
Serialize the attestation (with its preflight) once per create, so the
resume UPDATE and the claim INSERT cannot differ, and keep the PUT
route's publication guard in its UPDATE alone, where the 409 tests can
see it. Adds a preflightRecording unit test. Tested: preflight route
(14), attestation endpoint and detail contract suites.
The subprocess tests stop at the preflight by design, so a source pin
covers the one hop they cannot: the action passes the step's record to
createOrResumeDataset, after the step runs first. Tested: passes; fails
when the argument is dropped.
bun:test does not run a cleanup returned from beforeEach, so every
case left two directories behind. Tested: the three preflight suites
(41 pass) leave nothing in TMPDIR.
formatCoverage takes a format name from the file name, so a file like
sourcedata/Smith.John reads as .john. The preflight now keeps only
names on KNOWN_FORMATS (the scanner's own lists plus BIDS extensions),
folds the rest into .other, and its parser refuses any other name.
The publication report is unchanged. Tested: contract (22).
A non-ReportError from the parser is still refused as preflight-shape,
and is now logged by error class (never the message). Adds a fresh
create test that reads the claim INSERT's attestation. Tested: route
suite (15).
One warning call after create for both answers, so neither branch can
drop it; separate words for a failed request, a refusal, a server that
could not store it, and one that predates the field; a resume with a
preflight and no attestation now says so. The wire test names its
stand-in in the config file, so it runs in the pure CI tier. Tested:
wire suite (10).
From the PR review: walk a directory named .gitattributes (find still
lists its files) and any directory the listing does not type; bind an
acknowledgment to every condition found (the verdict plus unchecked
and not-screened when review hides them), repeatable or comma-separated
and exact; screen again right before the create call and send that
scan; refuse a dataset path that is not a directory; exit 130 on
Ctrl+C at the prompt; deliberate refusals skip the bug-report nudge.
CLI tests run in the pure tier, past the preflight with no tools on
PATH, and at a real pseudo-terminal. Tested: step (39), CLI (13).
Records the condition-bound acknowledgment, the second screen before
create, the closed format list and what a dry run still does. The
converter draft leaves its counts as placeholders until the fleet
re-run. Tested: adr-index (passes).
Pins that a symlink to a directory is listed and not walked, and that a
dataset path that is a file is refused even with the acknowledgment an
unlistable tree would need. Tested: step suite (40).
Covers the case the record contract cannot catch on its own: an
acknowledged scan that gains a condition still parses, so only the
recheck's comparison stops it. Tested: step suite (41); reverting the
comparison now fails it.
A live-tier file earlier in the same process sets the test-tier API
override and keeps it, which the client prefers to the config file. The
wire test sets such overrides aside for its run and restores them, and
still fails closed if the client would go anywhere but its stand-in.
Tested: alone (10) and after identifier-screen-callback-token (19).
@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review record

Two independent reviews ran on the branch before the review-fix commits: Sonnet code-reviewer and Sonnet silent-failure-hunter. Both were briefed that this check decides whether a person's name leaves a machine, and to weigh silent failures and vacuous tests heavily. Neither found a critical issue: no path where a direct identifier or an incomplete scan lets the upload proceed without the stated acknowledgment, and none where content is sent before the verdict. Every finding is listed below with what was done about it.

Fixed

  • A directory named .gitattributes was skipped whole, but the upload plan's find still lists the files inside it. It is now walked; only a file of that name is skipped. A test covers it.
  • A standing acknowledgment of review also covered an incomplete read and unparsed formats, because classifyDataset ranks review above both (found by both reviewers). An acknowledgment must now name every condition found, exactly, through preflightConditions. The flag is repeatable and accepts comma-separated values. Tests use real trees.
  • The scan ran long before the send. In between come the prompts and validation, and some steps write into the tree. The tree is now screened again right before the create call, and that scan is the record sent. The upload stops on a new direct identifier or a new condition.
  • Format names can carry a name, since sourcedata/Smith.John yields .john. The preflight now prints and stores only names from KNOWN_FORMATS, folds the rest into .other, and the door refuses any other name. The publication report is unchanged; see the list for the maintainer.
  • The prompt path had no test. New tests drive it at a real pseudo-terminal with Enter, y and Ctrl+C. They found a real bug: under Bun, Ctrl+C at the prompt exited with status 0 and printed nothing. It now says the upload was cancelled and exits 130.
  • The reader's open and read error branches had no test. Added chmod-000 tests for participants.tsv, a side JSON file and an EDF.
  • The local limits, the uncapped clone source and the format fold had no test. Added tests for a 100 KiB JSON file whose key sits past 64 KiB, for 301 export files, and for a stray extension.
  • The fresh-create warning and the claim INSERT were unverified. There is now one warning call for both create answers, and a backend test reads the INSERT's attestation.
  • Misleading warning causes. The four cases now get separate wording: request failed, refused, could not store, and a server that predates the field. A resume that has a preflight but no attestation now says so.
  • A parser bug was folded into a fixed word with no log. It is now logged by error class. A scan failure now prints the error class and its system code, never the message.
  • A null record could reach the create call. The command now stops on it with an explicit check.
  • Smaller items:
    • a directory that the listing does not type is walked;
    • a dataset path that is a file is refused;
    • the reader buffer is sized to the file;
    • the root-only test reports a skip instead of passing;
    • nested .git and directory-link cases are pinned;
    • deliberate refusals no longer print the bug-report nudge;
    • the ADR's sentence on failed reads is qualified;
    • the converter draft's counts are placeholders until the fleet re-run.

Not changed, with the reason

  • Kinds inside review are not bound to the acknowledgment. That is recorded in ADR 0087. Binding to kinds would make every new kind of review finding break a pipeline, and the publication screen gates on the same verdicts.
  • A dry run whose verdict needs an acknowledgment continues to the rest of the local preview. At a terminal that includes the co-author ORCID lookup, which uses author names (public by design). This is documented in ADR 0087.
  • The POST response fields identifier_preflight_recorded and identifier_preflight_refused are not asserted at the route. Both create branches fail at S3 or GitHub before they respond in a test. The function that builds the fields is unit-tested, and the PUT route asserts them.
  • The DT_UNKNOWN case cannot be produced on APFS. The guard that keeps the walk from following a directory link is pinned by a test.
  • The source pin on the action's hop to the create call stays. Any run that reaches the create call would touch GitHub and git-annex with the machine's credentials.

Process note

  • I ran 65 one-line mutants, each killed, with git status clean after each.

readdir order is the filesystem's: CI's ext4 listed .eeg before .vhdr
where APFS did not, so the printed counts came out in a different order
and unit-pure failed. Children are sorted and subdirectories walked in
that order, so a tree gives the same record and words everywhere.
Tested: step (42) and CLI (13) suites; a walk-order test.
@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR1635

Version: 0.10.13-PR1635.2cdbd87
Commit: 2cdbd87


🤖 Updated on each push.

@neuromechanist

Copy link
Copy Markdown
Contributor Author

CI and full-suite record

  • First push, unit-pure failed on upload-identifier-preflight-cli.test.ts. The cause was that readdir order belongs to the filesystem: CI's ext4 listed .eeg before .vhdr, and APFS did not, so the printed counts came out in a different order. 3c536c2 fixes this by walking the tree in name order. The same tree now gives the same record and the same words on every machine. A walk-order test pins the order, and the matching mutant is killed (66 mutants in all, every one killed).
  • Second push, all green: lint, unit-pure, integration-dev, e2e-sandbox, api-test, scrub-tools and zenodo-sandbox-test.
  • Full local root suite, second run: 10,914 pass, 235 skip, 7 fail. All 7 failures are in files this branch does not touch: git-annex-remote (3), neurobagel-writer (2), completion-argv-guard (1), annex-add-targets (1). They time out at 5 s under concurrent load and pass when run alone, as in the first run (105 such failures there, 101 in neurobagel-writer). Every new test passed in the shared process.
  • npm preview: CI's own preview job published nemar-cli@PR1635 (0.10.13-PR1635.3c536c2) for this PR. Nothing was deployed.

…er-screening' into feature/issue-1613-phase3-upload-preflight
@neuromechanist
neuromechanist merged commit 8c6a477 into feature/issue-1610-epic-identifier-screening Oct 7, 2026
13 checks passed

This branch was previously deployed

1 inactive deployment
npm — 2cdbd87a Deployed Oct 7, 2026 by neuromechanist via publish #3148
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