Repository navigation
Phase 3: tag-pinned imports and the upstream-moved guard - #1924
Merged
neuromechanist merged 37 commits intoOct 24, 2026
Merged
neuromechanist merged 37 commits into
neuromechanist merged 37 commits into
Conversation
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR1924Version: 🤖 Updated on each push. |
Three refusal markers for epic #1046 Phase 3 (mirror lag, upstream moved, annex-uuid conflict), defined once in shared/ so the CLI and the Worker import the same literal. The CLI re-exports them from src/lib/import-markers.ts. Typecheck passes; no behavior yet.
Adds the mirror_lag and upstream_moved causes (labels mirror-lag, upstream-moved) and lets annex_uuid_conflict match the #1320 preflight's marker as well as git-annex's own wording. The summary for annex_uuid_conflict now names both recoveries. Tested with import-failure-cause.test.ts; each new rule mutated and caught.
A refusal for a tag not yet on OpenNeuro's GitHub mirror is quarantined as mirror_lag instead of not_found_dataset, stays a retry candidate, and is parked as mirror_lag once the 14-day window has passed. It sends no quarantine mail and files no issue on failure; the retry engine files its one admin issue when it parks it. The plan's effects move into applyRetryPlan so they run in tests on real SQLite. Tested: import-retry, import-mirror-lag-recovery and the issue and error suites; each rule mutated and caught.
The retry engine parks a released mirror whose upstream moved (a re-pull's job, ADR 0111) and an annex-uuid conflict (#1320) at once instead of re-dispatching an import that refuses the same way every time. Both are read through the classifier so the park reason and the issue label agree. Tested in import-retry.test.ts; each rule mutated and caught.
The auto-import puts the tag discovery found in the onboard dispatch (client_payload.openneuro_tag) and in its audit row; the retry engine sends none, so a retry is prepared at whatever OpenNeuro names then. A malformed tag is left out. shared/openneuro-tag.ts defines the tag shape once. Tested: auto-import unit tests, the retry dispatch through a local GitHub stand-in, and autoImportTick against the real GraphQL in the integration tier; each mutated and caught.
prepare clones the OpenNeuro mirror at the upstream tag it imports (the --tag it is given, else OpenNeuro's latest from GraphQL), never the default HEAD (ADR 0111 decision 10). A tag that cannot be resolved or is not on the mirror yet refuses with [openneuro-mirror-lag] before the dataset record is created. Every refusal ends in refuseImport: it clears stale staging so copy and finalize cannot act on an earlier manifest, then prints the marker as the last failure line. Tested: import-tag-pin (real git-annex upstream with two tags and a HEAD past both; S3 stand-in with the real aws CLI), the reporter fed a real refusal, and against real OpenNeuro in the integration tier; each rule mutated and caught.
Imports one dataset at a named upstream snapshot tag, passed to prepare (--phase prepare), the --local driver, and the workflow dispatch as openneuro_tag only when given, so a dispatch without it keeps the shape an older workflow accepts. Refused with a batch, with copy or finalize, and for a value that is not a snapshot tag. Tested: the argument rules and dispatch fields, the help text the workflow greps, and the real CLI refusing an absent tag (integration tier); each mutated and caught.
recordedUpstreamTag reads the SourceDatasets entries naming the dataset's own ds (their Version, then a 10.18112/openneuro DOI, then the URL), never NEMAR's top-level Version, and answers null when they disagree. A stand-in for Phase 2's sourceSnapshotOf until both merge. Tested against the live on003645 and on004362 shapes and every disagreement case; each rule mutated and caught.
Step 4c reads the upstream tag origin/main records. Unrecorded or equal: the same-version hard reset, as before. Different: a released dataset refuses with [openneuro-upstream-moved] before any reset, S3 setup or push (a re-pull's job, ADR 0111); an unreleased one is retargeted with git reset --soft origin/main, so the new tag's tree lands as a fast-forward. Release state comes from hasReleasedVersion, asked only on a move; not knowing is a plain failure. decideReimportBase replaces decideReimportMainReset, and git-annex-remote.test.ts now drives baseOnOriginMain instead of a hand copy. The API surface pin gains hasReleasedVersion. Tested with real git-annex repos for every recorded form, and the released-version answers through a local backend (integration tier); each rule mutated and caught.
Before prepare configures nemar-s3 it compares the annex-uuid at the bucket prefix with the nemar-s3 uuids the git-annex branch records (after Step 4b's merge). It proceeds when the bucket has none or exactly one branch uuid matches; otherwise it refuses with [nemar-annex-uuid-conflict], both uuids, and the recovery that fits: remove a marker no branch records, or reconcile and delete nothing. A bucket it cannot ask is warned about and the remote set up as before. The git-annex export pin gains preflightBucketAnnexUuid and the test-only uuidsNamedInRemoteLog. Tested with real git-annex remote.log files and the S3 stand-in through the real aws CLI; each rule mutated and caught.
CHANGELOG Unreleased entry for Phase 3 (behavior, production changes, deploy coupling and version skew), and a dated ADR 0111 amendment recording decision 10 as built and the lead's rulings on retarget, the mirror-lag cap and parking annex conflicts. adr-index test passes.
A first import or a retarget appends {DOI, URL, Version} for the
pinned tag to SourceDatasets, from the tag alone and kept in git;
never after a hard reset, or when an entry already names the ds.
applyConceptDoiToDescription (shared/standard-edits/description.ts,
which doi.ts re-exports) now compares DOIs normalized and adds no
second entry for a dataset an entry already names, so the recorded
tag stays known.
CHANGELOG and the ADR 0111 amendment describe both.
Tested: import-tag-pin (entry shape, round trip through the reader,
git blob under an annex-everything policy), the guard reading the
entry the import writes, concept-doi-description; mutated and caught.
The capture test that runs refuseImport in a child process left its temp directory behind on every run. It is removed in a finally now. import-capture-workflow.test.ts passes.
ImportRefused.marker is now the ImportRefusalMarker union exported from shared/import-markers.ts. Corrects three comments: the tag pattern's bash pin belongs to the workflow PR, PinnedClone.latestTag is null only for an explicit tag whose lookup failed, and the upstream marker's backend copy predates shared/. Typecheck passes.
recordedUpstreamTag counts a URL only on openneuro.org's dataset pages or the OpenNeuroDatasets GitHub mirror (tree, releases, .git); any other host names no OpenNeuro dataset. The DOI and URL parsers move to shared/openneuro-tag.ts, readRecordedUpstreamTag says why nothing is recorded (none or disagree), entries may be null, and the header lists the three behaviors that differ from Phase 2's parser. Tested in import-upstream-tag.test.ts; each rule mutated and caught.
appendSourceDatasetEntry skipped whenever any entry named the dataset, so an untagged one (a concept DOI, a dataset page) left the recorded tag unknown and the upstream-moved guard blind. It now skips only when a tag is already recorded, completes an untagged entry that names this dataset alone in place (Version, and DOI or URL if missing), and appends beside an entry naming two datasets. Null entries are kept. Tested in import-tag-pin.test.ts, DOI-only and URL-only shapes included; each rule mutated and caught.
applyConceptDoiToDescription threw on SourceDatasets: [null] in the predicate Phase 3 rewrote; it now skips anything but an object, and an entry naming the dataset by its OpenNeuro page also stands for it. The comment says upstream's own DatasetDOI is dropped when an entry for the same ds exists at another tag. New tests: an upstream DOI newer than the entry, the live on004362 DOI-only shape, a page-only entry and a null entry, the last also at the shared module directly (shared/standard-edits/description.ts); mutated and caught.
bidsToDataCite turned the importer's SourceDatasets entry into two IsDerivedFrom relations, its DOI and its OpenNeuro page. The page is skipped when it names the same OpenNeuro dataset as the entry's DOI; any other URL is kept. Tested in datacite.test.ts; mutated both ways and caught.
The #1320 preflight could call a conflict (and advise removing the bucket marker) on evidence it did not have. It now answers unchecked when Step 4b's fetch or merge failed (fetchOriginAnnexBranch tells a missing origin branch from a failure), when git cannot read the branch's remote.log, or when origin has a git-annex branch that records no nemar-s3; a missing aws binary is unchecked too. The removal advice appears only for the complete case, conditioned on no clone recording the uuid. annexUuidPreflightAction is the choice prepare acts on. The git-annex export pin gains the two helpers. Tested with real repos and the S3 stand-in; each rule mutated and caught.
A failed git fetch origin main read as a first import, so the guard never ran; only git's "couldn't find remote ref main" is a first import now, and any other failure stops prepare before anything is reset or pushed. decideReimportBase reads the recorded tag before it looks at the branch, so a detached HEAD or an adjusted branch cannot skip the guard, and an unreleased import off main is refused rather than retargeted. Tested with real repos; each rule mutated and caught.
When origin/main has no readable recorded tag (no description, one git cannot read, one that is not JSON, no tagged entry, or entries that disagree) the guard cannot fire, as ADR 0111 requires. Step 4c now prints a warning naming the reason and returns it as unrecorded, instead of swallowing it in a bare catch. Not a refusal. Tested with real repos for each reason; each mutated and caught.
A retarget takes the new tag's tree whole, so origin's .nemar/corrections.jsonl would go with the old one. Step 4c now refuses, before any reset, when that ledger holds any line other than the importer's own import-scrubbed one, or a line it cannot parse, naming the count (ADR 0085). Tested with real repos; each rule mutated and caught.
The upstream-moved refusal ends with the command that repairs the released version at the tag it mirrors, nemar admin import-openneuro <ds> --tag <recorded tag>, which passes the guard; the classifier's summary says so too, and that the retry engine never runs it. The annex-uuid summary says an operator restarts a parked import by hand after fixing the marker. Tested in the guard and classifier tests; mutated and caught.
With --tag the latest-tag lookup only decides a warning, so it now makes one attempt with at most a 10-second timeout instead of three retried ones. Tested: a failing GraphQL is asked once and the clone goes ahead; mutated and caught.
A refusal, and a failure of the clone at the tag or of the guard, removes the work directory this run created (read-only annex directories included) and keeps one the caller named with --dir. Those two failures now end in prepareImport like refusals do. The refuseImport and ImportRefused comments now say staging is cleared only when the run persists it, that copy and finalize then fail at once on the missing manifest, and what the cleanup catch is for. Tested in a child process; mutated and caught.
test/import-prepare-pin.test.ts runs prepareImport in a child against local repos (git url insteadOf rewrites of the two GitHub URLs) and a local backend: released and moved refuses with nothing pushed and its work dir removed; unreleased and moved retargets and records the new tag (and warns that it is not OpenNeuro's latest); same tag and unrecorded tag take the hard reset, the latter recording nothing. shouldRecordSourceEntry is the extracted entry decision; ImportOptions gains openNeuroLookup for the GraphQL endpoint. The sweep's tick after its S3 reads is retryCandidateInput plus runRetryTick, run on real SQLite from the stored datetime. The importTag, released and sourceId wiring, the entry condition and the window read were each mutated and caught.
decideRetryAction's numbered rules are in the order they apply, and the note on parking upstream_moved and annex_uuid_conflict now says it is a backstop: classifyRecovery has no rule for either marker and a failure usually quarantines the row by dataset state first. classifyRecovery says why the mirror-lag override also bypasses has_doi, made_public and has_version. Tests reset the GraphQL fixture before each test, and in CI a missing aws CLI fails instead of skipping the S3 tests. Suites pass.
ADR 0111: annotates the not-yet-built statements and decision 10's "retried, not parked" bullet (decisions 4 and 10 are built; mirror lag parks after 14 days), dates the amendment 2026-10-24, rewords the park of upstream_moved and annex_uuid_conflict as the backstop it is, and records the round's changes and the window's anchoring limit. CHANGELOG: the #993 line names the unrecorded case, staging is cleared only when the run persists it, and the workflow pair lands first; the --tag help says dispatch needs the updated workflow. adr-index and tag-option tests pass.
Under the full unit-pure run (no --timeout, so bun's 5 s default) the four Step 4c tests in git-annex-remote.test.ts timed out at 5,001 ms; they and the tag-pin tests that clone real repositories now carry an explicit 60 s timeout, as the other git-backed suites do. Both files pass.
An import-scrubbed ledger line whose scrub blanked a JSON value or scrubbed a git-held recording means origin's history still holds the originals; a retarget would drop the line, skip earlierHistoryHold and report no hold. Such a line now refuses the retarget like a recorded correction. The comment and the ADR amendment no longer say Step 5b's scrub re-applies the old line. Tested with nonzero counts (and a zero-count line that still retargets); mutated and caught.
Step 4c and Step 4b told a missing ref by git's English "couldn't
find remote ref", and the guard told a missing file by "does not
exist in"; git localizes both ("Konnte Remote-Referenz main nicht
finden"), and init.ts already forbids matching them. Missing refs now
come from git ls-remote --exit-code (status 2) and missing paths from
git ls-tree's listing. Tested under LC_ALL=de_DE.UTF-8 (German
messages on this machine): first import, missing description, missing
ledger and an absent git-annex branch; each reverted to a message
match and caught.
appendSourceDatasetEntry returns disagree, with a warning, when entries already record different tags for the dataset, instead of adding a third. The in-place completion leaves an untagged entry alone (and appends beside it, with a warning) when it already carries a Version that is not a tag or a DOI or URL that is not text, so it no longer overwrites them. Tested in import-tag-pin.test.ts; mutated and caught.
The header said nothing in the Decision section was built, with the same annotation under it as under the section; it now says decisions 4 and 10 are built per their amendments, and the one annotation stays under the section. adr-index passes.
The 14-day window test now runs in America/Los_Angeles and restores TZ with Reflect.deleteProperty in a finally, so reading the zoneless SQLite datetime as local time fails on a UTC runner too. Mutation-proven: the old test survived the misread under TZ=UTC; the new one catches it. Tested with bun test, TZ=UTC and default zone.
The upstream-moved guard and the SourceDatasets record now read the
tag with sourceSnapshotOf (shared/source-snapshot.ts); the Phase 3
reader src/lib/import-upstream-tag.ts is gone, and hasSourceEntryFor
uses isOwnSourceEntry. Where the two differed the parser wins: a tag
is numeric and dotted, an entry naming two datasets gives no tag, and
the mirror's .git URL names no dataset. The record is written only
when the parser then reads it as the tag ("unreadable" otherwise, with
a warning), which replaces the "disagree" outcome and the old append
beside a two-dataset entry. sameUpstreamTag stays the guard's equality.
Tests moved to the parser, with the three changed cases named; ADR
0111 and CHANGELOG updated. Tested: Phase 3 suites, source-snapshot;
five mutations caught.
applyConceptDoiToDescription drops upstream's DatasetDOI when an entry for the same dataset exists; "for the same dataset" is now the shared parser's isOwnSourceEntry, so publication and every reader of the tag agree. The mirror's .git clone URL, which no reader counts as the dataset's, no longer stands in for upstream's DOI. Tested with standard-edits-description (tree URL dropped, .git URL kept beside) and concept-doi-description; the wider match mutated back and caught.
neuromechanist
force-pushed
the
feature/issue-1909-phase3-tag-pin
branch
from
October 24, 2026 11:38
0b0e8aa to
78b26df
Compare
git annex init commits, and the CI runners have no git identity, so every Phase 3 test that clones through cloneOpenNeuroAtTag failed there (unit-pure and integration-dev) while passing on a machine with a global one. A new helper, test/helpers/git-identity.ts, sets GIT_AUTHOR_* and GIT_COMMITTER_* in process.env for the file and restores them after; no global git config. The live test also clones into a fresh directory per attempt, so a --retry is not failed by the directory an earlier attempt left. Tested with HOME empty, GIT_CONFIG_SYSTEM=/dev/null and a global config holding only user.useConfigOnly: 36 failures before, none after.
neuromechanist
merged commit Oct 24, 2026
dd5ebec
into
feature/issue-1046-epic-upstream-freshness
14 checks passed
This was referenced Oct 24, 2026
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 3 of epic #1046 (ADR 0111 decision 10): an import is pinned to an upstream snapshot tag, never the mirror's default HEAD, and an import whose recorded upstream moved is refused or retargeted instead of silently reset (#993).
The auto-import dispatches at the tag discovery found (
openneuro_tagin the cron payload, only when non-null); other entry points resolve the latest tag from OpenNeuro at run time.cloneOpenNeuroAtTagandnemar admin import-openneuro --tagpin the clone.baseOnOriginMainrefuses with[openneuro-upstream-moved]when origin/main records a tag and a version was released, and retargets an unreleased import. A tag not yet on the mirror refuses with[openneuro-mirror-lag](transient). The first import or retarget appends a{DOI, URL, Version}entry toSourceDatasets, and the concept-DOI de-duplication indoi.tsis normalized so it cannot add a second entry for the same upstream dataset. The #1320 annex-uuid preflight refuses before any copy. New failure causesmirror_lag(14-day retry cap, then parked with one admin issue and no per-attempt mail) andupstream_moved; the retry engine also parksannex_uuid_conflict.The workflow change (
onboard-openneuro.ymlopenneuro_taginput) is deliberately NOT in this PR: it ships as its own PR todev(branchfeature/issue-1909-phase3-workflow) plus a mirror PR tonemarDatasets/.github, workflow pair first. Version skew was tested in both directions: an old workflow with the new CLI still pins (the CLI asks OpenNeuro for the latest tag), and a new workflow with an old CLI skips--tagwhen the help text lacks it.Deviations and interpretations: the recorded tag is read only from
SourceDatasetsentries (the top-levelVersionon the live mirrors is NEMAR's own 1.0.0); tag equality is exact after dropping a leadingv; "released" means anydataset_versionsrow; an unrecorded tag never trips the guard.recordedUpstreamTagis a local reader to be swapped for the Phase 2 shared parser after #1920 merges. Nothing was deployed or run against production.Test plan
s3-remoteexport pin, fixed in 2ed7240; the website parity test fails only against a stale../websitesibling checkout, unrelated)Closes #1909
Part of epic #1046