Skip to content

Phase 6b: shared seams for the manual re-pull - #1938

Merged
neuromechanist merged 22 commits into
feature/issue-1046-epic-upstream-freshnessfrom
feature/issue-1912-phase6b-shared-seams
Oct 24, 2026
Merged

neuromechanist merged 22 commits into
feature/issue-1046-epic-upstream-freshnessfrom
feature/issue-1912-phase6b-shared-seams

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

Adds the shared seams the manual re-pull (ADR 0111) builds on, with behavior changes only where named. The import scrub takes a scope (only the delta paths) and a per-key sourceOf (a pinned upstream source, a held key, or none) and reads upstream objects at a pinned versionId; assertCopiedRecordingsRead is exported. The finalize tree gate is extracted into src/lib/import-finalize-gate.ts (verifyManifestObjects, treeGate, registerTreeKeys) with its messages unchanged. The generated participants.tsv becomes a standard edit shared by enrichment and the plan (planner version 2). The privacy ledger gains the repull-scrubbed action (a recorded correction in the plan only for lines that are not this one) and the fresh-clone proof accepts a commit that appends such lines. The upstream-moved refusal now names the re-pull command. The plan's to-tag check orders by OpenNeuro creation time through one shared helper (upstreamSnapshotOrder, also used by the staleness verdict) and leaves the check unchecked when the order cannot be read, so a legacy-tag mirror (00006 before 1.0.0) is not mis-ordered.

Phase 6b of epic #1046, part of #1912 (which stays open until 6g). No new route and no migration.

What is in it

  • src/lib/import-scrub.ts, src/lib/import-finalize-gate.ts, src/lib/import-openneuro.ts (gate moved out, behavior unchanged).
  • shared/standard-edits/participants.ts and the planner (PLANNER_VERSION 2); shared/openneuro-snapshots.ts with fetchOpenNeuroSnapshots and upstreamSnapshotOrder.
  • The repull-scrubbed ledger action in the ledger, contract and git library, and the fresh-clone proof.
  • ADR 0111 amendment slice for 6b.

Test plan

  • Full bun test: 19281 pass, 242 skip; the only remaining failure is the website parity test against a stale sibling checkout; after the rebase 864 tests across scrub, import, finalize-gate, repull, staleness, measure, backend, ADR index and pins pass.
  • Typecheck, lint and Biome clean on the touched files.
  • 33 single-line mutants applied; all killed (every target in the plan plus numeric tag order reintroduced and equal creation times treated as newer).
  • That .log.rmet records a versionId per key in production stays unverified here.

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR1938

Version: 0.10.24-PR1938.103c058
Commit: 103c058


🤖 Updated on each push.

scrubImportedTree takes an optional scope (the paths it may read and change) and an optional sourceOf (a source, held, or none per key, in place of the whereis map), so an upstream re-pull can scrub its delta paths only. A provenance file outside the scope is counted as not annotated. The manifest's closing check is exported as assertCopiedRecordingsRead. The importer passes neither option and its suites pass unedited.

Tested: new scope, source and closing-check tests in test/import-scrub.test.ts, each killed by a one-line mutation; the import-scrub suites pass.
UpstreamSource gains a pinned kind (bucket, object, versionId, region), read by httpUpstreamReader at pinnedObjectUrl: the path-style URL with every segment encoded and ?versionId= kept, so an upstream re-pull's scrub reads the version its copy will copy (ADR 0111, decision 8). The size and hash rules apply unchanged.

Tested: the URL's encoding, and a scrub against the S3 stand-in with a newer object current at the path, where both the ranged header read and the download name the version; each killed by a one-line mutation.
The verify, tree gate and register steps of finalizeImport move, with their messages unchanged, to src/lib/import-finalize-gate.ts as verifyManifestObjects, treeGate and registerTreeKeys, so an upstream re-pull's register step runs the same three. DATA_AVAILABILITY_MARKER moves with the gate and import-openneuro.ts re-exports it. finalizeImport keeps its exits.

Tested: test/import-finalize-gate.test.ts on a real git-annex repository with a listing from the S3 stand-in through the real aws, texts pinned word for word; each function killed by a one-line mutation. The finalize suites pass unedited.
The enrichment's placeholder participants.tsv moves to shared/standard-edits/participants.ts (the backend module re-exports it), and the re-pull planner treats it as a standard edit: where upstream ships none, NEMAR's file is explained when it is the placeholder of an upstream tree's subjects, it changed upstream when the subjects did, and N.0.0 gets the placeholder of tag B's subjects. A placeholder edited afterwards stays NEMAR's correction. The body's planner is now PLANNER_VERSION, 2.

Tested: three fixture plans (tag B adds a subject, the same subjects, an edited placeholder) and the shared-path identity; each changed line killed by a one-line mutation. The planner and participants suites pass.
The ledger takes a repull-scrubbed action: an upstream re-pull's delta scrub writes it (ledgerAction) before its one commit, so it holds no history. The planner counts neither scrub action as a recorded correction; the re-import hold still reads import-scrubbed lines only; the ADR 0085 proof tolerates a re-pull's commit as it does the importer's; a retarget still refuses any line but the importer's own.

Tested: the scrub writes the word, a repull-scrubbed line holds nothing on a re-import while the importer's does, a plan with one beside unexplained paths is not refused, the fresh-clone proof tolerates the commit, and a retarget refuses it; each killed by a one-line mutation.
The [openneuro-upstream-moved] refusal of a released mirror now names the re-pull to the new tag, nemar admin repull plan <id> --to-tag <tag>, quoted so the tag is not read with the full stop, before the repair at the recorded tag, which stays last.

Tested: the guard suite, with a new test of the sentence; naming the recorded tag instead is killed.
The re-pull plan's to-tag check no longer compares tags numerically. It reads OpenNeuro's latest and its snapshot list with creation times in one answer (fetchOpenNeuroSnapshots, the staleness report's query and parser, moved to shared/openneuro-snapshots.ts) and orders them through upstreamSnapshotOrder, now the one helper the staleness verdict uses too. Only OpenNeuro's latest created after from_tag is ok; an order the answer cannot establish, or no from_tag, is unchecked, so the plan is not executable. A mirror recorded at legacy 00006 is no longer held behind 1.0.0 by its number. Phase 5's to-tag unit tests move to the creation-order rule.

Tested: unit tests of the helper and the check, the fetch's retry and error paths against a loopback stand-in, and plans over the fixture (legacy tag, same creation time); each changed rule killed by a one-line mutation. The Phase 4 suites pass unedited.
The re-pull fixture adds tag B's participants.tsv by assignment instead of a conditional spread, which typed the edits as possibly undefined. No behavior change.

Tested: test/repull-plan.test.ts.
Append-only amendment dated 2026-10-24: the scrub's scope, sources and pinned reads; repull-scrubbed and the corrected ledger rule; the generated participants.tsv as a standard edit (closing the Phase 5 open item); planner 2; to_tag ordered by OpenNeuro's creation order (correcting the Phase 5 reading); the refusal's re-pull pointer; the finalize gate as functions. Docs only.
A scoped scrub refuses scope-incomplete when a path changed since HEAD is outside its scope, and provenance-out-of-scope, before any download, when a header will change and a provenance file lies outside it (the lead's ruling: refused, not counted). A provenance file that is not a JSON object is counted as provenance_malformed, apart from one that is not a regular file; the importer warns on both as before. The held-key doc names its real basis.

Tested: test/import-scrub.test.ts adds the two refusals, provenance annotated in scope, a malformed one, the read keys of the scope and no-source scrubs, a held key refused by the closing check, and a pinned version gone answering http-404 with no unpinned read; each guard killed by a one-line mutation.
upstreamSnapshotOrder answers list_undated when another snapshot in upstream's list has an unreadable date, since it could be the newest: the plan's to-tag check is then unchecked, and the staleness verdict reads upstream_dates_unreadable instead of stale or upstream_older (a mirror at the stated latest stays current). The check's messages name an unknown from_tag as the mirrored tag (unknown) rather than printing null, and its no-from_tag detail is pinned.

Tested: the helper, the check with [1.0.0 2020, 1.1.0 2021 latest, 1.2.0 undated] from 1.0.0, and the classifier; each change killed by a one-line mutation; the Phase 4 suites pass.
SCRUB_ACTIONS in scripts/scrub/ledger.ts names import-scrubbed and repull-scrubbed once: ledger-cli append refuses both (the importer writes through appendLedger, not the CLI), and the planner reads the set. The proof's exemption, now isScrubLedgerCommit, accepts repull-scrubbed lines beside other files only when the commit carries the Upstream-Snapshot: and Repull-Plan: trailers. The runbook, the design record and the retarget comments say so.

Tested: the CLI refuses both words and appends nothing; fresh-clone twins without trailers, with one trailer, with another action and with an edited earlier line each fail, with cleanup in a finally; each rule killed by a one-line mutation.
The [openneuro-upstream-moved] refusal names nemar admin repull plan <id>, to OpenNeuro's latest snapshot by default, with --to-tag naming the imported tag, which need not be the newer one; the repair at the recorded tag stays last.

Tested: the guard suite, with the sentence pinned; naming the recorded tag instead is killed.
finalizeImport runs in a child process over a local origin (GIT_CONFIG_GLOBAL rewrites the GitHub URL, a dummy token, no system config), the S3 stand-in through the real aws, and a closed API port: a tree key with no object exits 1 with the [nemar-data-unavailable] line, registers nothing and pushes no git-annex branch.

Tested: replacing the gate's condition in finalizeImport with false fails it.
The plan test keeps body.planner equal to PLANNER_VERSION and no longer pins the constant's value, which only detected a change.

Tested: test/repull-plan.test.ts.
The Phase 6b amendment records the lead's rulings: a scoped scrub refuses an incomplete scope and a provenance file outside it (closing the open item), the malformed count, the re-pull commit's trailers for the proof and the CLI's refusal of the scrub words, an undated snapshot never ordering tags, the no-answer case with and without --to-tag, and the refusal's new wording. digest.ts says execution will refuse an older planner's plan in a later slice. Docs only.
The scoped scrub's completeness check reads untracked paths .gitignore does not exclude (git ls-files --others --exclude-standard) beside git diff HEAD, so an untracked path outside the scope also refuses scope-incomplete. The scope docstring says a re-pull's scope must hold every written and deleted delta path and every .gitattributes the annex policy edited (ADR 0060).

Tested: an untracked path outside the scope refuses and inside it is read; dropping the untracked listing is killed.
The provenance-out-of-scope rule counts a planned header change, a date-only one included, since ADR 0091's sentence goes in the same file. The comment says the refusal comes after the ranged header reads and before any recording is downloaded, and that a date-only download that later fails was refused already, the safe side.

Tested: a date-only recording with the provenance pair outside the scope refuses with no download; narrowing the rule to scrubs is killed.
The fresh-clone proof is driven with GitHub's squash shape: the pull request's commits as bullets, the re-pull commit's trailers mid-message and an enrichment bullet last. git reads no trailers there, and the proof refuses with ledger-commit-not-alone count=1; the same squash ending with both trailers passes.

Tested: reading the whole message instead of git's trailers is killed.
The Phase 6b slice says the provenance refusal comes after the ranged header reads and before any recording is downloaded and counts a date-only change, the scope holds untracked, deleted and .gitattributes delta paths, and a squash merge without trailers fails the proof with ledger-commit-not-alone until Phase 6f writes the message. Phase 4a's rule 13 gains an annotation for list_undated, and the classifier's step comments name it. Docs and comments only.
Old git-annex initialises an un-inited local origin on clone, moving its
git-annex ref and failing the before/after check on CI. Also use a fresh
work dir per attempt so retries do not hide the first failure.

Tested: finalize gate test 3x, PR tests, typecheck, lint.
The finalize gate test's origin comment says initialize and artifact. Comment only.

Tested: test/import-finalize-gate.test.ts.
@neuromechanist
neuromechanist force-pushed the feature/issue-1912-phase6b-shared-seams branch from 65177d2 to 103c058 Compare October 24, 2026 21:43
@neuromechanist
neuromechanist merged commit 68620c1 into feature/issue-1046-epic-upstream-freshness Oct 24, 2026
18 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-1912-phase6b-shared-seams branch October 24, 2026 22:18

This branch was previously deployed

1 inactive deployment
npm — 103c0589 Deployed Oct 24, 2026 by neuromechanist via publish #3934
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