Skip to content

Phase 5b: read-only re-pull plan - #1931

Merged
neuromechanist merged 29 commits into
feature/issue-1046-epic-upstream-freshnessfrom
feature/issue-1911-phase5b-repull-plan
Oct 24, 2026
Merged

neuromechanist merged 29 commits into
feature/issue-1046-epic-upstream-freshnessfrom
feature/issue-1911-phase5b-repull-plan

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds nemar admin repull plan <dataset_id>, the read-only plan for re-pulling a newer OpenNeuro snapshot as a major version (ADR 0111). It compares the recorded upstream tag, the tag to adopt and NEMAR's current tree path by path, classifies every delta path (take upstream, keep ours, explained standard edit, recorded correction, unexplained), and renders the result as a table or JSON. A plan is executable when every preflight is ok, no key is unpinned and no plan refusal applies: an unexplained path or a conflict does not block (a correction replays as N.0.1), except through ledger-correction-unexplained when the privacy ledger records a correction, and a check that could not run (unchecked, for example fetch-bound) always refuses. It writes nothing: not to the mirror, not to S3, not to D1.

Phase 5 of epic #1046 (Phase 5a, the shared standard edits, is already on the epic branch). Phase 6 executes a plan; this PR only produces and binds it.

What is in it

  • src/lib/repull/: read-only guard, sources (tagged upstream tree, current tree, ledger, location logs), digest that binds a plan to its inputs, preflight checks, --from-tag handling, per-path classification (edits.ts, overlay.ts), the dataset_description.json per-key rule (description.ts), plan.ts, render.ts.
  • src/commands/admin-repull.ts and its registration under nemar admin.
  • ADR 0111 amendment dated 2026-10-23 recording the Phase 5 rulings.
  • Tests: plan (25), CLI (13), digest (7), description (5), against real git and git-annex repositories built by test/helpers/repull-fixture.ts; the GitHub stand-in gained the open pull-request list.

Rulings applied

  • SourceDatasets merges three way; an upstream removal is not reverted.
  • A mirror with an unknown tag gets a dry-run plan only; --from-tag is allowed and never recorded as lineage by the plan.
  • Known legacy badge forms and an inherited .gitattributes are explained standard edits (ADR 0060).
  • Presence comes from the location log by default; --bucket-listing uses aws s3api list-objects-v2 when credentials are available.

Test plan

  • bun test on the four repull files: 49 pass, 0 fail
  • Pure tier locally: 17341 pass, 1 fail (account-copy-parity, stale sibling website checkout, unrelated)
  • bun run typecheck, Biome clean
  • 42 of 42 mutations killed (read-only guard, digest, each standard edit, per-key description, SourceDatasets, badges, presence, dead keys, pins, ledger, executability, workdir cleanup, fetch bound, preflight checks)
  • Production dry runs on on003645 and on004362 are deferred until the whole epic is built (owner decision)

Part of epic #1046.

@neuromechanist
neuromechanist force-pushed the feature/issue-1911-phase5b-repull-plan branch from f5bf6e7 to 7cbe955 Compare October 24, 2026 14:14
neuromechanist added a commit that referenced this pull request Oct 24, 2026
Review of PR #1931, A1 and A2. The guard accepted attached forms (-ccore.hooksPath=x, -uevil). Each git subcommand now carries only a fixed list of options in the planner's own spelling, clone and ls-remote take only a GitHub or file:/// URL, fetch only origin, and aws only list-objects-v2 with four named options. readLocationLogsAt takes a git runner, so the planner passes the guard to it; for-each-ref, --batch-check and the unused lazyFetch option are gone.

Tested in the test commit of this round (repull-digest.unit.test.ts; location-logs-at.test.ts still 10 pass).
neuromechanist added a commit that referenced this pull request Oct 24, 2026
Review of PR #1931, A2 to A13. Pins and remote.log are read through the guard; ls-remote carries the clone's credentials; a refused or undelivered blob makes its path unchecked and refuses the plan (fetch-bound); annexed CHANGES keeps its ADR 0085 sentences on an unannex target, and unannex keys need a pin; a bucket listing needs the annex-uuid control; unknown sizes are reported as unknown and a scrubbed key needs a known equal size; only a badge for the catalog's concept DOI is explained, and a DatasetDOI that disagrees refuses; sources is recorded outside the digest; the scratch directory goes on SIGINT and SIGTERM; ledger and metadata parse errors are said; a malformed tag has its own code.

Tested in the test commit of this round.
neuromechanist added a commit that referenced this pull request Oct 24, 2026
Review of PR #1931, C. The help says which outcomes exit 1 and which exit 3, names the NEMAR_CONFIG_DIR default and what the plan writes (only its scratch directory and the plan file); --json with --counts is a usage error; --max-fetch-gb is parsed as a number of GB.

Tested in repull-plan-cli.test.ts.
neuromechanist added a commit that referenced this pull request Oct 24, 2026
Review of PR #1931, B. New fixture variants (privacy edits, near misses, annexed root metadata, every conflict and correction subtype, README.md, no README, the legacy badge, a stale badge, a corrupt ledger, a gitlink, dead and held keys, metadata-only tag B) and tests for each recognizer and its near miss, the ledger refusals, the fetch bound, unannex pins, the other-bucket pin filter, the location-log held branch, the preflight codes the remotes' state produces, the guard's attached forms, the bucket listing control, and the CLI's options, usage errors, xx mapping, 404 rows, missing token and SIGINT cleanup.

Tested: 84 pass across the four repull files.
neuromechanist added a commit that referenced this pull request Oct 24, 2026
Review of PR #1931, C. States exactly what the guard covers and what is outside it, what the plan writes, that Phase 6 recomputes preflight and executability, which outcomes exit 1 and 3, the ds mapping (closing the Phase 2 open item), the unchecked class, dead and unannex keys, and the participants.tsv refusal as left open. The index, AGENTS.md and the design record now say the plan is built and execution is not. Docs only.
@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@PR1931

Version: 0.10.24-PR1931.7602932
Commit: 7602932


🤖 Updated on each push.

neuromechanist added a commit that referenced this pull request Oct 24, 2026
Round 2 review of PR #1931, finding 1. OpenNeuro's latest that is not numerically after from_tag is order-unverified (planned, never executable), not ok: it can be creation order (00006 before 1.0.0) or a step backwards, and the tags cannot tell which. The same tag stays nothing-to-pull. Also says what the 404 the version check reads means.

Tested in this round's test commit (toTagCheck cases and an entry-point plan).
neuromechanist added a commit that referenced this pull request Oct 24, 2026
Round 2 review of PR #1931, finding 2. A JSON parser's message quotes a token of the file (Unexpected identifier "Jane"), which reached the refusals, nemar_owned_edits, stdout and the digest, and varies between runtimes. The ledger and .nemar/metadata.json failures now carry the error's class (SyntaxError) and nothing else.

Tested in this round's test commit (a value-looking token is echoed nowhere in the plan).
neuromechanist added a commit that referenced this pull request Oct 24, 2026
Round 2 review of PR #1931, finding 3. sources is test-bases also when a library caller passes openNeuroGraphqlUrl, not only when the environment redirects a remote (planSources).

Tested in this round's test commit.
neuromechanist added a commit that referenced this pull request Oct 24, 2026
Round 2 review of PR #1931, finding 4. A partly unknown count reads N bytes known, plus M of unknown size; the orphan bound reads at most N bytes, or, with unknown sizes, adds no upper bound; the Markdown row no longer says upper bound beside at least.

Tested in this round's test commit.
neuromechanist added a commit that referenced this pull request Oct 24, 2026
Round 2 review of PR #1931, finding 5. bareDoi lives in edits.ts (trimmed, null for a missing value) and plan.ts and overlay.ts both use it; a missing concept DOI still strips no badge and leaves README.md unknown.

Tested: the repull suites.
neuromechanist added a commit that referenced this pull request Oct 24, 2026
Round 2 review of PR #1931, finding 6. An append-only Extended 2026-10-24 line under the 2026-10-23 amendment says what was settled that day, and the to_tag section says OpenNeuro's latest that is not after from_tag is order-unverified. Headings stay in date order.

Tested: the ADR index test.
neuromechanist added a commit that referenced this pull request Oct 24, 2026
Round 2 review of PR #1931, finding 7. from-tag.ts and preflight.ts no longer blame a dev worker for a 404 versions route, and the long exit-3 help bullet is wrapped and names an order-unverified to-tag.

Tested: typecheck and biome.
Phase 5b (#1911, ADR 0111). A read-only guard for every git, aws and HTTP call the planner makes; bare, depth-1, blob-filtered clones with a bounded explicit blob fetch; the bucket's annex-uuid marker and an optional bucket listing; the from-tag resolution through sourceSnapshotOf; the preflight checks; and the plan file's canonical digest, written 0600.

Tested: test/repull-digest.unit.test.ts (digest stability, volatile fields, guard refusals).
Phase 5b (#1911, ADR 0111 decision 1). The per-path three-way decision (keep ours, take theirs, conflict, correction) over ls-tree maps, with the standard edits recognized by calling the import's and publish's own functions; the README family and dataset_description.json compared as units; N.0.0's targets; the pinned copy manifest minus held and dead keys; local uploads; the ADR 0085 ledger refusal; counts, scrub forecast and the plan body.

Tested: test/repull-plan.test.ts over a real imported mirror and upstream (test/helpers/repull-fixture.ts), 23 tests.
Phase 5b (#1911, ADR 0111). The command reads the dataset row and its version rows (two GETs, a 404 on the rows leaves them unknown), resolves the admin's GitHub token, plans, writes the plan file (default $NEMAR_CONFIG_DIR/repull/<id>/<to>.<digest8>.json, mode 0600) and prints counts only; --json prints the plan, --counts Markdown. Exit 0 executable, 3 planned but not executable, 1 nothing planned. The GitHub stand-in gains the open pull-request list.

Tested: test/repull-plan-cli.test.ts, the real binary against the real datasets router over bun:sqlite, every preflight refusal, 13 tests.
Records the 2026-10-23 rulings Phase 5 builds: plan then execute, the CHANGES privacy sentence as a ledger edit, the three-way SourceDatasets merge, dry-run-only plans for an unknown tag, the legacy edits that are explained, and presence from the location log or a bucket listing; plus the pre-scrub manifest and deletion readings. Docs only.
dataset_description.json was classed as a whole (conflict whenever any key was unexplained and upstream changed another), which hid that corrections and conflicts are per key (ADR 0111 decision 1). It now takes its worst key's class, with subtype per-key. The fixture gains a NEMAR-added description key (a per-key correction) and a deadKeys variant: a dead non-recording key named by N.0.0 refuses, a dead recording is left for the scrub, neither is copied.

Tested: test/repull-plan.test.ts, 24 pass.
Supplements for rules the fixture cannot vary: the three-way SourceDatasets set merge (null entries included) and the badge spellings badgeStrips accepts. The pins test now runs with every preflight check ok, so only the unpinned key keeps it from executable, and lineage is checked holding and not recordable from --from-tag.

Tested: test/repull-description.unit.test.ts (5), test/repull-plan.test.ts filtered (4).
plan.ts declared its own copies of .nemar/corrections.jsonl and nemar-s3; it now imports LEDGER_REPO_PATH and S3_REMOTE_NAME from the scrub tools that own them. No behavior change.

Tested: test/repull-plan.test.ts filtered to the ledger and copy tests.
Review of PR #1931, A1 and A2. The guard accepted attached forms (-ccore.hooksPath=x, -uevil). Each git subcommand now carries only a fixed list of options in the planner's own spelling, clone and ls-remote take only a GitHub or file:/// URL, fetch only origin, and aws only list-objects-v2 with four named options. readLocationLogsAt takes a git runner, so the planner passes the guard to it; for-each-ref, --batch-check and the unused lazyFetch option are gone.

Tested in the test commit of this round (repull-digest.unit.test.ts; location-logs-at.test.ts still 10 pass).
Review of PR #1931, A2 to A13. Pins and remote.log are read through the guard; ls-remote carries the clone's credentials; a refused or undelivered blob makes its path unchecked and refuses the plan (fetch-bound); annexed CHANGES keeps its ADR 0085 sentences on an unannex target, and unannex keys need a pin; a bucket listing needs the annex-uuid control; unknown sizes are reported as unknown and a scrubbed key needs a known equal size; only a badge for the catalog's concept DOI is explained, and a DatasetDOI that disagrees refuses; sources is recorded outside the digest; the scratch directory goes on SIGINT and SIGTERM; ledger and metadata parse errors are said; a malformed tag has its own code.

Tested in the test commit of this round.
Review of PR #1931, C. The help says which outcomes exit 1 and which exit 3, names the NEMAR_CONFIG_DIR default and what the plan writes (only its scratch directory and the plan file); --json with --counts is a usage error; --max-fetch-gb is parsed as a number of GB.

Tested in repull-plan-cli.test.ts.
Review of PR #1931, B. New fixture variants (privacy edits, near misses, annexed root metadata, every conflict and correction subtype, README.md, no README, the legacy badge, a stale badge, a corrupt ledger, a gitlink, dead and held keys, metadata-only tag B) and tests for each recognizer and its near miss, the ledger refusals, the fetch bound, unannex pins, the other-bucket pin filter, the location-log held branch, the preflight codes the remotes' state produces, the guard's attached forms, the bucket listing control, and the CLI's options, usage errors, xx mapping, 404 rows, missing token and SIGINT cleanup.

Tested: 84 pass across the four repull files.
Review of PR #1931, C. States exactly what the guard covers and what is outside it, what the plan writes, that Phase 6 recomputes preflight and executability, which outcomes exit 1 and 3, the ds mapping (closing the Phase 2 open item), the unchecked class, dead and unannex keys, and the participants.tsv refusal as left open. The index, AGENTS.md and the design record now say the plan is built and execution is not. Docs only.
Pins that a path the fetch bound left unread counts toward the ledger's unexplained total. Tested: the bound test passes.
After rebasing onto the epic head (Phase 3, dd5ebec): --to-tag and --from-tag take their shape from isOpenNeuroTag and compare with sameUpstreamTag (shared/openneuro-tag.ts), so v1.1.0 is 1.1.0 and a malformed tag is to-tag-malformed or from-tag-malformed; the nemar-s3 uuids come from uuidsNamedInRemoteLog, the #1320 import preflight's reading. No second copy of either rule.

Tested: the malformed-tag test, and the full repull suites after this commit.
The ADR index and AGENTS.md now say decision 10 is built in Phase 3 and the plan in Phase 5; the Phase 5 amendment names the tag rule it reuses. Docs only.
Pins that --from-tag v1.0.0 on an unrecorded mirror plans from 1.0.0. Tested: the malformed-tag test passes.
After rebasing onto Phase 4a (80cb119), whose amendment rules that upstream's creation order decides, not the number: to_tag defaults to OpenNeuro's latestSnapshot.tag (Phase 3's fetchOpenNeuroLatestTag), must be isSourceTag (Phase 4a; to-tag-unrecordable), and a tag OpenNeuro does not name latest is planned with to-tag unchecked (order-unverified), so the numeric not-newer check and the highest-tag default are gone. NEMAR_REPULL_OPENNEURO_URL points the query at a loopback stand-in for tests. The SIGINT and SIGTERM handler now kills the planner's live git children before removing the scratch directory, which a clone still writing could otherwise recreate.

Tested: 88 pass across the repull files; the SIGINT test three runs in a row.
ADR 0111's Phase 5 amendment says how plan chooses and checks to_tag under the Phase 4a reading, and names the OpenNeuro query among the reads outside the guard. Docs only.
Pins that NEMAR_REPULL_OPENNEURO_URL takes only a loopback http address and a NEMAR_REPULL_*_BASE only an absolute local path. Tested: 11 pass.
Round 2 review of PR #1931, finding 1. OpenNeuro's latest that is not numerically after from_tag is order-unverified (planned, never executable), not ok: it can be creation order (00006 before 1.0.0) or a step backwards, and the tags cannot tell which. The same tag stays nothing-to-pull. Also says what the 404 the version check reads means.

Tested in this round's test commit (toTagCheck cases and an entry-point plan).
Round 2 review of PR #1931, finding 2. A JSON parser's message quotes a token of the file (Unexpected identifier "Jane"), which reached the refusals, nemar_owned_edits, stdout and the digest, and varies between runtimes. The ledger and .nemar/metadata.json failures now carry the error's class (SyntaxError) and nothing else.

Tested in this round's test commit (a value-looking token is echoed nowhere in the plan).
Round 2 review of PR #1931, finding 3. sources is test-bases also when a library caller passes openNeuroGraphqlUrl, not only when the environment redirects a remote (planSources).

Tested in this round's test commit.
Round 2 review of PR #1931, finding 4. A partly unknown count reads N bytes known, plus M of unknown size; the orphan bound reads at most N bytes, or, with unknown sizes, adds no upper bound; the Markdown row no longer says upper bound beside at least.

Tested in this round's test commit.
Round 2 review of PR #1931, finding 5. bareDoi lives in edits.ts (trimmed, null for a missing value) and plan.ts and overlay.ts both use it; a missing concept DOI still strips no badge and leaves README.md unknown.

Tested: the repull suites.
Round 2 review of PR #1931, finding 6. An append-only Extended 2026-10-24 line under the 2026-10-23 amendment says what was settled that day, and the to_tag section says OpenNeuro's latest that is not after from_tag is order-unverified. Headings stay in date order.

Tested: the ADR index test.
Round 2 review of PR #1931, finding 7. from-tag.ts and preflight.ts no longer blame a dev worker for a 404 versions route, and the long exit-3 help bullet is wrapped and names an order-unverified to-tag.

Tested: typecheck and biome.
toTagCheck for a latest after, before, numerically equal and 00006-before-1.0.0 from_tag; the plan entry with an older latest; a parse failure that echoes no file token (the fixture writes a name into the broken files); planSources with the OpenNeuro option; bytesPhrase and orphanPhrase wording.

Tested: the four repull suites pass; each new test fails under a mutation of its production line.
targetFamily checked the concept DOI twice, and the second check, after bareDoi, could only run for a whitespace value plan.ts already normalizes away. One check on bareDoi's answer now decides no-concept-doi, before the README is read, as before.

Tested: the repull plan suite.
bareDoi drops doi: and a resolver and answers null for a missing or blank DOI, and a plan with no concept DOI refuses target-unknown but never concept-doi-disagrees.

Tested: both fail under a mutation of bareDoi's null branch.
@neuromechanist
neuromechanist force-pushed the feature/issue-1911-phase5b-repull-plan branch from 86de8f9 to 7602932 Compare October 24, 2026 15:11
@neuromechanist
neuromechanist merged commit 1aab760 into feature/issue-1046-epic-upstream-freshness Oct 24, 2026
18 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-1911-phase5b-repull-plan branch October 24, 2026 15:41

This branch was previously deployed

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