Repository navigation
Phase 2: record the upstream snapshot per version - #1920
Merged
neuromechanist merged 18 commits intoOct 24, 2026
Merged
neuromechanist merged 18 commits into
neuromechanist merged 18 commits into
Conversation
Migration 0100 adds source_version and source_version_basis with a CHECK that keeps never-examined, unknown and known-tag apart. Tested on real SQLite, including the NULL-safe CHECK terms; datasets is untouched (budget test still 84).
shared/source-snapshot.ts: sourceSnapshotOf, isOwnSourceEntry, openNeuroSourceId, compareSourceTags, mirroredTagOf. Reads only the dataset's own SourceDatasets entry; any disagreement is unknown. Unit tested (36 cases); each rule mutated and caught.
One INSERT_DATASET_VERSION_SQL for all five dataset_versions insert sites. The manifest-ready callback and admin manifest regeneration read the tagged dataset_description.json (bounded, never throws); the inline sites use the description they hold. An absent file or failed read stays NULL/NULL. Tested through the real worker and admin route plus a source scan; mutations caught.
POST /admin/datasets/upstream-backfill examines never-examined on###### version rows in keyset pages (default 25, max 50), dry run by default. A fetch error writes nothing, a 404 is unknown only past one hour, an all-absent batch is a suspect credential, and the write never overwrites. 23 route tests on real SQLite; mutations caught. Route inventory pin updated.
Loops POST /admin/datasets/upstream-backfill over next_cursor (250 ms pause, --max-batches), dry run unless --execute, reads the 502 body so the resume cursor is printed, exits 1 on any error or unfinished pass. Tested through the real CLI against a local server; mutations caught. API export pin updated.
GET /datasets/:id/versions rows gain source_version and source_version_basis (always present; nulls mean never examined). The route is outside the OpenAPI document by design, so the CLI VersionInfo type is the contract. Tested through the real route; mutation caught.
Dated append-only amendment to ADR 0111: the insert-site table (A and B live, C and D dev-only, E unreachable) corrects the callback-already-reads claim; the entry-level Version reading, the meaning of doi, and the insert-versus-backfill rule for an absent file. Design note section 4 updated to match. Docs only; the ADR index test passes.
The email epic (#1893) holds 0100_broadcast_queue on its pushed branch; this takes 0101 so the two never share a number. Renames the file and updates the references in code, tests and docs; the migration test, column budget test and route tests pass.
The test compared the schema after ALL migrations with the schema before 0098, so any later column on dataset_versions (0101 adds two) failed it. It now builds the after-schema through 0098 only. Test passes (30).
INSERT_DATASET_VERSION_SQL uses ON CONFLICT (dataset_id, version) DO NOTHING instead of INSERT OR IGNORE, so a snapshot pair the CHECK refuses fails the insert (callback 500, job stays dispatched) while a replayed version stays a silent no-op. Tested on real SQLite and through the callback; reverting to OR IGNORE fails both new tests.
Normalize the ref with toVersionTag (no vv1.0.0), cap the body at 1 MiB (over-cap is a read error), strip a byte order mark, warn when an insert-time read is absent, and document the 5 s worst-case latency. Removes the unused readMirroredTag and readSourceVersionRows. New tests: stalled App token mint is cut off at the deadline, the legacy handler (site D) through its route, cap boundary with and without a declared length. Mutations caught: ref, deadline race, cap (stream and exact), BOM, site D bind, absent warning.
An absent description becomes unknown (final) only when a control read of the same repository at main succeeds with the same credential; otherwise the row is not_examined and retried. The suspect-credential guard no longer depends on batch size or on other errors. Only N.N.N versions are candidates. A write result without a change count is an error, and execute= is parsed strictly (400). Tests: lone and mixed batches, shared control read, keyset tie-break inside one dataset, v-prefixed and non-semver rows; 9 mutations caught.
nemar admin upstream-backfill says a recorded unknown is final, and a finished pass with rows not examined prints one line to rerun without --after (an unfinished pass prints the resume cursor instead). Tested through the real CLI; three mutations caught.
Migration comments: TRUE-or-FALSE-never-NULL wording, the full unknown definition, and the cross-column CHECK marked unverified on D1. ADR 0111 amendment: one correction and three readings, names the decision 4 sentence it corrects, control read and N.N.N rules, ON CONFLICT insert; README entry notes decision 4 is built. Design note: dated migration wording.
4 of 5 tasks
In the full Bun process an earlier file leaves the GitHub rate-limit bucket drained, which made the legacy-handler description read fail fast and the site D tests see NULL/NULL. The tests now reset the rate-limit state and the installation-token cache before each test; the file passes alone (38) and the full-suite check follows.
In a full Bun process an earlier file installs a permanent mock.module of services/github whose getTreeAtRef returns an empty tree, so the legacy version-DOI handler (site D) read NULL/NULL and the tests failed in the full run only. The four assertions now live in source-snapshot-legacy-handler.test.ts and run in a child process via a wrapper test; the stand-in is shared through helpers/source-snapshot-standin.ts. Mutating the site D bind fails the wrapper.
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR1920Version: 🤖 Updated on each push. |
origin/dev holds 0100 and 0101 (email epic) and its branches reach 0103. Renames the file and updates the references in code, tests, the ADR 0111 amendment and the design note. Migration, column budget and route tests pass; no duplicate migration prefixes.
errors[] carries kind: transient (a rerun fixes it) or needs_admin (absent at the tag and at main, which a rerun never fixes). The CLI states the two causes separately and marks needs-admin rows; the ADR amendment says the same. Also rewraps the route header comment. Route and CLI tests pass; the cause mutation is caught.
neuromechanist
merged commit Oct 24, 2026
535dd84
into
feature/issue-1046-epic-upstream-freshness
14 checks passed
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 2 of epic #1046 (ADR 0111): record which upstream snapshot each NEMAR version mirrors.
Adds
dataset_versions.source_versionandsource_version_basis(doi, lineage, unknown; NULL means never examined) in migration 0104, a shared pure parser (shared/source-snapshot.ts), a fail-open recorder at all fivedataset_versionsinsert sites, the dry-run-firstPOST /admin/datasets/upstream-backfillroute withnemar admin upstream-backfill, and the two fields onGET /datasets/:id/versionsrows. ADR 0111 gets a dated append-only amendment (the "central flow already reads the description" premise was wrong; the callback now fetches it with a 4 s timeout and fails open) and the design note is updated.The migration is numbered 0104 because
origin/devholds 0100 and 0101 and open branches reach 0103. Re-check before the epic merges. A cross-column CHECK insideADD COLUMNwas verified on SQLite only, not on D1. Nothing was deployed or run against production or dev data.Test plan
bun run typecheckandbun run lintclean on touched filesbun test: 18738 pass, 231 skip, 2 fail (one fixed in c4df1d1;test/account-copy-parity.test.tswebsite parity drift, being checked against the epic base)Closes #1908
Part of epic #1046