Skip to content

Phase 7: importer scrubs in place and waits for the screen - #1639

Merged
neuromechanist merged 18 commits into
feature/issue-1610-epic-identifier-screeningfrom
feature/issue-1618-phase7-importer-scrub
Oct 7, 2026
Merged

neuromechanist merged 18 commits into
feature/issue-1610-epic-identifier-screeningfrom
feature/issue-1618-phase7-importer-scrub

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Part of epic #1610. Closes #1618. Decision: ADR 0089 (amends 0060, 0085 and 0086 with their build status). Design note: #1618 (comment)

An OpenNeuro import now scrubs the cloned tree in prepare, with ADR 0085's rules, before anything is copied or pushed. The copy manifest is cut to what the scrubbed tree names, so a re-import cannot copy back a key a correction replaced. Finalize waits for the identifier screen and approves only a clear verdict.

ADR number: #1635 (Phase 3) kept 0087 and #1636 (Phase 5) became 0088, so this branch's ADR is renumbered 0089.

What changed

  • src/lib/import-scrub.ts (new), prepare step 5b:
    • Every recording the copy will copy is read first: a file git holds from the clone, an annexed one by a 256-byte anonymous ranged read of the upstream object (the S3 object by path, or a non-S3 whereis URL at that URL, which the copy's curl fallback fetches). A read must return every byte and state the object's size, which must be the key's.
    • A header scrubEdfHeader changes is downloaded whole, checked against its key (size and sha256), patched in the identification fields only, proven with verifyScrub, annexed as SHA256E and uploaded through ADR 0060's upload leg. Its old key is retired in the git-annex branch with ADR 0085's annexRegistry.
    • Identifier JSON values are blanked at HEAD. Images and documents are counted, never removed. When headers were scrubbed, the provenance file and README get ADR 0085's sentences. One import-scrubbed ledger line is committed, in a commit that names only the scrub's own paths.
  • It fails closed before the push: [nemar-identifier-scrub] refused: <word> with counts. The words are header-unreadable, upstream-size-mismatch, bound-exceeded, content-mismatch, unsupported-key-backend, already-imported-unscrubbed, old-key-still-named, retire-failed, scrub-unverified, upload-failed and scrub-failed.
    • Any other error is named by its class and errno code only, because a file-system error's message carries the path.
    • A header OpenNeuro refuses (403/404 only) also carries the upstream marker.
    • A closing check refuses any upstream recording in the manifest whose header this run did not read.
  • The copy manifest is cut to the committed tree's keys, minus any key the git-annex branch records as dead (restrictManifestToTree). Before this, a re-import reset onto origin/main but took its manifest from upstream's whereis.
  • src/lib/import-publication.ts (new): finalize requests publication and polls the screen state. The wait is at most 45 minutes, cut to what the finalize job's 90-minute timeout leaves. It approves only clear, re-runs a stale screen once, and otherwise returns one of published, already-published, blocked, review or unchecked.
    • A held publication is not an import failure: finalize exits 0.
    • The importer's own holds are written on the request through the deny route, before any approval is asked for, because the screen cannot see them. They apply when the scrub left originals in the pushed history (this run, or an earlier import per the dataset's ledger), or when the manifest has no exact scrub record.
    • A re-run of finalize waits on the request it left open, and never approves one already being approved.
  • shared/identifier-scrub.ts: blankIdentifierJsonKeys, the history rewrite's blank_json rule for one document, parity-tested against the Python, proven by a re-scan. shared/privacy-correction-text.ts: the provenance sentences, moved from the git plan (no behavior change there).
  • Ledger vocabulary gains import-scrubbed. The importer's scanner is a build-time digest of the rule files (src/lib/scanner-rules-digest.ts, a Bun macro), because it runs from the package, not a checkout.
  • Backend: classifier cause identifier_scrub (after upstream_inaccessible); the retry engine parks refusals a retry cannot clear (identifier_scrub_refused).
  • nemar admin import-openneuro --screen-wait-minutes; --normalize-max-gb now also covers the scrub's downloads.

Defaults for the maintainer to confirm

  1. Automatic deterministic scrub (ADR 0085 and the ADR 0060 amendment), not the reviewed per-dataset declaration in the design review on Phase 7: importer scrubs in place on every import and re-pull #1618. Re-pull does not exist yet, and the same upstream bytes give the same SHA256E key ADR 0085's tools produce (pinned by a test).
  2. Most mirrors are in formats the scanner does not parse, so their screen asks for an admin's acknowledgment, and auto-import stops publishing them unattended (ADR 0086's rule; no automatic acknowledgment is built).
  3. A JSON value blanked at HEAD stays in the pushed upstream history (a forward fix, as in ADR 0060), so such an import is held and its request denied with a fixed reason. Rewriting history before the first push would close this and needs git-filter-repo on the runner.
  4. The public Actions log and refusal lines carry counts and fixed words, never a value, path or file name. They do state an outcome per dataset, which ADR 0086's screen workflow deliberately does not.

Rollout (not part of this PR)

  • The onboard workflow file is unchanged on purpose: test/dataset-workflow-parity.test.ts requires it to match the deployed copy byte for byte. Raising finalize's timeout-minutes in both copies, together with FINALIZE_JOB_TIMEOUT_MS, lets the full 45-minute wait apply.
  • The identifier-scrub label does not exist on nemarDatasets/.github yet.
  • Phase 4's run-identifier-screen.yml must be merged in nemarDatasets/.github for the screen to run. Until then every import ends unchecked, and nothing is approved automatically.

Tests

  • test/import-scrub.test.ts (35): real git-annex repositories in an OpenNeuro clone's shape, a type=directory remote for nemar-s3, and an HTTP stand-in for the upstream bucket. It drives prepareImportedTreeForCopy, the one call prepareImport makes, and covers:
    • the first import, Phase 2 key parity, a clean tree, a git-held recording, provenance, --skip-data and the backend override;
    • every reachable refusal;
    • a web-URL source, short and unsized reads, an empty recording, wrapped errors with no path in them, and a failed upload;
    • a re-import of a scrubbed dataset (hold carried from the ledger), a later rewrite clearing the hold and a bad ledger keeping it, a re-import of an unscrubbed dataset, a new upstream recording never copied, and a dead key never copied;
    • the classifier and retry-engine pins.
  • test/import-finalize-screen.test.ts (21): the real finalizeImport against an API stand-in. It covers every screen state, inert states that only sound clean, a timeout, an unreadable or refused status, a missing view, the history and no-record holds and the deny they write, a malformed record, a hold that cannot be written, stale re-run once, a re-run that cannot start, an exempt state, an open request, an approval in progress, and an already public dataset.
  • test/identifier-scrub.test.ts (the JSON rule, with byte parity against blank_json), backend/test/import-failure-cause.test.ts, backend/test/import-retry.test.ts, test/onboard-workflow.test.ts (the wait budget pinned to the workflow's timeout), test/adr-index.unit.test.ts.
  • Mutation checks: 67 one-line mutants, each restored from HEAD before the next. 66 killed. One is equivalent: setTopLevelString's depth === 1 against >= 1, since the walker skips each member's value whole and never reaches depth 2. The closing check is not mutation-tested because it is unreachable once web-URL sources are read; it stays as a backstop. Not guarded by a fast test: the wait budget's fallback in finalizeImport (screenWaitBudget when no --screen-wait-minutes is given), which needs a run of minutes; the budget itself is pinned to the workflow's timeout.
  • Independent review (code-reviewer and silent-failure-hunter, Sonnet). Findings and dispositions are in the review comment on this PR.

The importer's JSON half of the scrub (ADR 0087): the rule of ADR 0085's history rewrite for one document, text-preserving, proven by a re-scan. Tested with unit cases and a parity check against blank_json; bun test test/identifier-scrub.test.ts passes.
Moves the provenance file and README sentences of ADR 0085's git plan to shared/ so the importer writes the same words (ADR 0087). No behavior change; build-git-plan and provenance suites pass.
Adds import-scrubbed to the corrective-action ledger's closed vocabulary, the line the importer writes when it scrubs a tree before its first push (ADR 0087). Typecheck passes; exercised by the importer tests.
gitAnnexAdd and normalizeUnannexedData take an optional SHA256E backend, which outranks an inherited annex.backend attribute; the import scrub uses it so a replaced recording's key is one ADR 0085's tools follow. Typecheck passes.
Prepare's step 5b now runs the identifier scrub (ADR 0087) before the annex-policy step: flagged EDF/BDF headers are downloaded, verified against their key, patched, annexed as SHA256E, uploaded and their old keys retired; identifier JSON values are blanked; images and documents are counted for review; a ledger line is committed. The copy manifest is cut to the committed tree minus dead keys, so a re-import cannot copy back a replaced key. Refusals carry a marker and a fixed word. test/import-scrub.test.ts (22 tests, real git-annex and an HTTP stand-in) passes.
Finalize requests publication, polls the screen state for a bounded time (45 min default, --screen-wait-minutes), approves only a clear verdict, re-runs a stale screen once, and otherwise leaves the request for an admin with a fixed outcome word (published, already-published, blocked, review, unchecked). A held publication is not an import failure. A scrub that left originals in history, or a manifest with no scrub record, is held for a person. test/import-finalize-screen.test.ts (14 tests, real finalizeImport against an API stand-in) passes.
Adds the identifier_scrub cause (label identifier-scrub) for the import scrub's marker, after upstream_inaccessible so a refusal OpenNeuro caused stays retryable by the upstream rule. The marker copies are pinned through a refusal the scrub really raised. backend import-failure-cause tests and the CLI pin test pass.
The deployed onboard workflow's finalize job times out at 90 minutes, and its copy here must stay byte-identical to the deployed one, so the wait for the identifier screen is cut to what the job has left (at most 45 minutes, at least 5). A test pins the constant to the workflow's timeout. onboard-workflow, finalize-screen and workflow-parity tests pass.
Records the Phase 7 decisions (#1618) and amends ADRs 0060, 0085 and 0086 with their build status. adr-index test passes.
Prepare has staged root metadata of its own before step 5b; the privacy-correction commit now names only the paths the scrub changed, so that metadata lands in the commit that describes it. Also replaces an invisible BOM literal. test/import-scrub.test.ts (23) passes.
Two cases no fixture reached: the replacement key is SHA256E when the tree's attributes now name another backend, and the manifest cut refuses a replaced key the tree still names. Both pass.
The git-held case kept a sidecar to blank, which set the history flag by itself, so a mutant that ignored git-held recordings survived. Without the sidecar the flag comes from the recording alone. Passes; the mutant is now killed.
The retry engine blocklisted only upstream-inaccessible rows, so a deterministic scrub refusal (bound-exceeded, already-imported-unscrubbed, unsupported-key-backend, old-key-still-named, scrub-unverified, retire-failed) was re-dispatched to refuse again. It is now parked as identifier_scrub_refused; the slow re-check still recovers a row completed another way. Review finding. import-retry and import-failure-cause tests pass.
Review findings on the import scrub (ADR 0087): a re-import carries the history hold from the ledger (a later history rewrite clears it, an unreadable ledger keeps it); a recording whose whereis URL is not S3 is read at that URL, as the curl fallback copies it; a closing check refuses any upstream recording in the manifest whose header this run did not read; a short or unsized header read is a failure; an empty recording is not read; other errors become scrub-failed or upload-failed naming only their class; staging is chunked and the commit takes a pathspec file; refusals say the copy did not run. 35 tests pass, real git-annex and an HTTP stand-in.
Review findings on the wait (ADR 0087): a history or no-scrub-record hold is written on the request through the deny route before any approval is asked for, and finalize fails loudly if it cannot be; the privacy record must be exactly version 1 with a boolean; a refused status read and a re-run that cannot start end the wait with their own reason; a sandbox exemption is not a reason to approve; an already-open request is waited on, and one being approved is not approved again. Prepare warns when a re-import could not fetch the git-annex branch, and counts provenance files it could not annotate. 21 finalize tests pass.
ADR 0087 now says which recordings are not read and why, the two new refusal words, the parked retries, the holds written on the request, the re-run of finalize, the residuals the review found, and that the importer's log states an outcome. Adds a .memory entry on the byte-pinned onboard workflow. adr-index test passes.
@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review record (pre-PR, 2026-10-06)

Two independent read-only reviews ran on the branch before it was pushed: pr-review-toolkit:code-reviewer and pr-review-toolkit:silent-failure-hunter, both on Sonnet. Both were told that this change decides whether a person's name goes public, and to weigh silent failures and test vacuity heavily. Each finding is listed with its disposition. Every fix has a test, and each new rule was mutation-checked (see the PR body).

Critical

  • A re-import forgot the history hold. A second prepare blanked nothing new, wrote historyHoldsOriginals: false, and finalize would then approve a clean screen over a history that still held the values. Both reviews found this. Fixed: on a re-import the hold is read from the dataset's ledger. It holds while an import-scrubbed line that changed git-tracked content has no later history-rewritten line, and a ledger that cannot be read holds. Tests: the re-import case now asserts the record; a later rewrite clears the hold; a bad ledger line keeps it.
  • A recording whose whereis URL is not S3 was counted as having no source, and the curl fallback then copied it unread. Both reviews found this. Fixed: such a source is read at that URL, and a closing check refuses any upstream recording in the cut manifest whose header the run did not read. Test: a web-URL source is read and scrubbed.

Important

  • Path-bearing error text could reach the public log and the failure issue (fs errors; git-annex stderr from the upload leg). Fixed: errors inside the scrub become scrub-failed or upload-failed, named by class and errno code only. Error classes whose messages are fixed words keep them. Tests: an unreadable file whose name holds an invented surname, and an upload to a removed remote. Neither message contains the name or the path.
  • A short or unsized header read was judged "not an EDF". Fixed: a read must hold every byte it should and state the object's size; otherwise it is short-read or no-length and refuses. Tests for both.
  • The importer-only holds were invisible to admins, so a clean verdict would be approved. Fixed: the hold is written on the request through the existing deny route, with a fixed reason, before any approval is asked for. If it cannot be written, finalize fails loudly. Tests: the deny body for both holds, and three failed attempts raising an error.
  • The privacy record was trusted when merely falsy. Fixed: only version: 1 with a boolean counts. Tests with {}, {version: 1} and {version: 2, ...}.
  • A re-run of finalize exited 1 on the request it had left open. Fixed: an open request is waited on like a fresh one, and one being approved is not approved again (approval-in-progress). Tests for both.
  • The retry engine would re-dispatch refusals a retry cannot clear. Fixed: they are parked as identifier_scrub_refused. The parked words are pinned to the CLI's list.
  • Comment and ADR claims the code did not back ("every recording is read", "only scrubbed bytes are copied", "nothing was copied", the module header's no-path claim, the client-side exemption, the stageAsGit reliance on config over attributes). Corrected in ADR 0087 and the comments. The exemption is gone: an exempt state is now unchecked.
  • The scrub reads the object by path while the curl fallback fetches the version the whereis URL pins. Recorded as a residual in ADR 0087, not changed. A flagged recording is digest-checked against its key, so the difference can only matter for a header that read clean when upstream replaced an object without a new commit. The screen reads NEMAR's copy either way.

Suggestions

  • Stop waiting on a 401, 403 or 404 status read (status-refused); name a failed re-run (rerun-failed).
  • annexRegistry's failure keeps its fixed-word reason; local I/O errors are local-io and not retried; an empty recording is not range-read (no 416).
  • Refusals now say "Nothing was pushed, and the copy phase did not run" (scrubbed objects may already be uploaded).
  • Provenance files that could not be annotated are counted and warned about.
  • A re-import whose git-annex fetch failed now warns that dead marks are unknown to the run.
  • git add is chunked; the scrub commit takes a NUL-separated pathspec file.
  • Tests added for an MD5E key to replace, an unreadable git-held recording, a 403 beside a 500, and an empty recording.
  • A commit subject of exactly 50 characters was reworded.
  • Not changed: the outcome word in the public log. The brief for this phase asks for an explicit outcome per dataset. ADR 0087 says this is the deliberate exception to ADR 0086's no-verdict screen log, and that it is the maintainer's call.
  • Not added: tests for retire-failed and the scrub-unverified proofs. Neither is reachable without injecting a fault into git-annex or into the scrub's own proof. The closing check in prepareImportedTreeForCopy is unreachable after the URL fix, and is kept as a backstop.
  • Not added: a published-build check of the scanner-digest macro. bun build --target bun runs macros, which was measured by hand. A test recomputes the digest from the rule files.

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

Version: 0.10.13-PR1639.378c260
Commit: 378c260


🤖 Updated on each push.

test/setup.ts points TEST_API_URL at a blocked address when there is no live target, and in a single-process bun test that reached this file, whose guard then refused all 21 cases. The file now points TEST_API_URL at its own server for its duration and restores it after. Passes with TEST_API_URL=http://127.0.0.1:1 set and without.
@neuromechanist
neuromechanist merged commit 0e7ee1d into feature/issue-1610-epic-identifier-screening Oct 7, 2026
13 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-1618-phase7-importer-scrub branch October 7, 2026 11:21

This branch was previously deployed

1 inactive deployment
npm — 378c260e Deployed Oct 7, 2026 by neuromechanist via publish #3154
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