Skip to content

Phase 4a: upstream staleness route - #1932

Merged
neuromechanist merged 7 commits into
feature/issue-1046-epic-upstream-freshnessfrom
feature/issue-1910-phase4a-upstream-status
Oct 24, 2026
Merged

neuromechanist merged 7 commits into
feature/issue-1046-epic-upstream-freshnessfrom
feature/issue-1910-phase4a-upstream-status

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds GET /admin/upstream-status, a read-only, keyset-paged admin route that reports which NEMAR mirrors of OpenNeuro datasets are behind OpenNeuro's latest snapshot (ADR 0111). It reads the recorded upstream tag from dataset_versions.source_version, asks OpenNeuro for the dataset's snapshots in batches of 50, probes the GitHub mirror at the latest tag, and classifies each dataset: current, stale_ready, mirror_lag, stale_unverified, anomaly, unknown, not_examined, unpublished, in_progress, parked or unchecked. A failed or partial read is never reported as current or as a definite claim about upstream. The report itself writes nothing to D1 and files nothing; authentication still stamps tokens.last_used_at. counts is per page, so aggregation is the caller's (4b).

Phase 4a of epic #1046 (4b adds the CLI, the weekly-report section and the mirror flag; 4c adds --measure).

What is in it

  • shared/upstream-staleness.ts: the pure diffStaleMirrors classifier and the wire types; isSourceTag in shared/source-snapshot.ts. Tag order is OpenNeuro's creation order, not numeric order (ds000001 has 00006 before 1.0.0).
  • backend/src/services/openneuro-snapshots.ts: batched GraphQL reader (50 aliases, sequential, 20 s timeout, ids never in the query text; partial responses and foreign error messages are error reads).
  • backend/src/services/upstream-status.ts and backend/src/routes/admin/upstream-status.ts: the page, the GitHub mirror probe (raw read at the tag plus a control read at HEAD, both requiring a JSON object body), the probe budget, excluded_unmanaged; route inventory pin 155 to 156.
  • ADR 0111 amendment dated 2026-10-24 and a design-note update.
  • Tests: classifier unit tests over recorded real OpenNeuro responses, reader tests against an HTTP stand-in, route tests (including an SQL recording that asserts every statement is a SELECT apart from the token stamp, and the 403 through the real admin mount), and a Miniflare D1 run of every new statement.

Review

Round 1 (four Sonnet reviewers) and the delta round are done; every finding is fixed or answered in the commits.

Test plan

  • Targeted suites: the four new test files, route inventory pin, column budget and the Phase 3 import tests pass after the rebase onto the epic head
  • bun run typecheck, Biome clean; datasets column budget still 84
  • CI green on the final head
  • Whether the NEMAR installation token can read OpenNeuroDatasets raw files is not testable locally; if refused, every probe reads stale_unverified with the reason (recorded in the amendment under "Not yet verified")

Part of epic #1046.

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

Version: 0.10.24-PR1932.cd6ab47
Commit: cd6ab47


🤖 Updated on each push.

Pure classifyMirror and diffStaleMirrors in shared/upstream-staleness.ts:
eleven states, eight anomaly kinds, verdict by upstream creation order
(not tag number), plus isSourceTag. Recorded OpenNeuro fixtures included.
Tested with the recorded responses.
Batched GraphQL reader for the staleness report: 50 datasets per request,
ids only as variables, per-alias deleted/absent, any failure an error
read (never a verdict). Exports OPENNEURO_GRAPHQL_URL and adds an
override binding. Tested against a stand-in serving the recorded response.
Read-only, keyset-paged report of OpenNeuro mirrors behind upstream:
batched snapshot read, GitHub mirror probe with a HEAD control read
(rawContentUrl gains an org parameter), pinned in the route inventory.
Tested on real SQLite, a recorded-response OpenNeuro stand-in, and
Miniflare D1.
Dated amendment: population, state precedence, creation order over tag
number, the control-read proof of mirror lag, no cron. Points the design
note's staleness predicate at it. Docs only, not tested.
Reader: a partial response, a null latest beside a non-empty list and a
foreign 'does not exist' are error reads. Classifier: a latest older than
a list entry is an anomaly; unknown rows name the OpenNeuro failure.
Service: 502 only when rows needing a verdict ended unchecked, excluded
unmanaged on rows counted, probe 200 needs a JSON object body, no claimed
probes when the token cannot be minted. Route: strict limit, dataset with
after is 400, D1 failures labeled apart from defects. Tested with
mutations on real SQLite, recorded responses and Miniflare D1.
Amendment now states the status codes, per-page counts, unmanaged rows,
the latest-versus-list anomaly, the same-tag re-creation limit, the CDN
404 cache, the HEAD control read, and what the next part will do. The
token caveat moves to Not yet verified. Fixes the design note predicate
and the raw-read comments. Docs only, not tested.
An unparsable (not null) latest date skipped the list check and let a
recorded==latest row read current beside a later snapshot. The list
entry's date is tried next; if neither reads the row is
upstream_dates_unreadable. ADR wording for upstream_older and the
unknown-row note, probe doc block moved back. Tested with mutations.
@neuromechanist
neuromechanist force-pushed the feature/issue-1910-phase4a-upstream-status branch from 429a416 to cd6ab47 Compare October 24, 2026 12:49
@neuromechanist
neuromechanist merged commit 80cb119 into feature/issue-1046-epic-upstream-freshness Oct 24, 2026
14 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-1910-phase4a-upstream-status branch October 24, 2026 13:19

This branch was previously deployed

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