Repository navigation
Phase 7c: schedule automatic re-pull dispatches - #1954
Merged
neuromechanist merged 15 commits intoOct 25, 2026
Merged
neuromechanist merged 15 commits into
neuromechanist merged 15 commits into
Conversation
Add buildUpstreamRepullPayload, which checks every field (a release CLI version only, the signed token's shape, a finish names its re-pull) and throws before anything is sent, and triggerUpstreamRepullRun, which answers sent, refused (a 4xx) or unknown (a 5xx, a lost connection or the timeout) and never forwards GitHub's body. Tested: backend/test/upstream-repull-payload.test.ts against a loopback GitHub stand-in.
Move OPENNEURO_GRAPHQL_URL to services/openneuro-endpoint.ts, which imports nothing, so the staleness report's snapshot reader no longer loads discovery (discovery re-exports the constant unchanged). Pin the separation both ways with an import-closure scan that fires on a planted import. Tested: repull-discovery-separation, upstream-status-route and auto-import suites.
Add runRepullSchedulerCron: in exact production with the open switch on, it walks up to three pages of the staleness report from a stored cursor, takes stale_ready mirrors only, skips anonymous, unreconciled, open, live, content-refused and recently pulled ones, re-reads the dataset fences, and claims each dispatch through the dispatch record's capped claim. It waits for a completed administrator re-pull, refuses a non-release build, stops before a stale row the probes did not reach, and is blind (sends nothing, keeps the cursor) when OpenNeuro or the probe credential fails. The scheduler's outcome words are shared and shape-checked. Tested: upstream-repull-scheduler (SQLite, loopback OpenNeuro, raw mirror and GitHub stand-ins), its Miniflare D1 twin, and the no-mail and discovery-separation scans.
Call runRepullSchedulerCron from the production-only daily block, with one log line per tick (error level when it could not see or could not send). DEV_CRON_ALLOWLIST is unchanged. The wiring test declares the scheduler prod-only and now also pins every prod-only job out of the allowlist; the dev-safety test shows the scheduler and the dispatch watchdog return null with D1 untouched for any ENVIRONMENT but exactly production. Tested: cron-sweep-wiring and cron-dev-safety suites.
A mirror the staleness report could not compare is passed by, so one that always fails cannot hold the cursor; the tick now counts those and logs at error level when it passed any, so partial blindness is seen. Tested: upstream-repull-scheduler suite (a per-dataset OpenNeuro read that is no verdict).
Append the 7c slice: candidates from stale_ready only and the exclusions, the 30-day reading, the open cap claimed at dispatch (a 4xx frees the unit, a 5xx or a lost answer keeps it), production only with DEV_CRON_ALLOWLIST unchanged, gate G4 and the release-build rule in code, the rotation and the probe-budget stop, what the dispatch carries, discovery untouched, and what only production can show. Tested: adr-index suite.
triggerUpstreamRepullRun now logs a send that got no answer by its error's class (errorClassName: a plain identifier, else Error), never its message, so a failure on this side can be told from a timeout without echoing a URL, a path or the token. Tested: upstream-repull-payload suite (a TypeError whose message holds the token, and a timeout).
The scheduler opened after any one administrator re-pull of any on mirror. It now waits until both re-pulls the design record's gate G4 names (on003645 and on004362, REPULL_G4_DATASETS) were run by an administrator to complete with their tags; one of them alone, two runs of one, an automatic or unfinished run, or another mirror's do not count. Tested: upstream-repull-scheduler and its D1 suite.
- blind only when OpenNeuro fails a batch; a page whose rows are all unchecked is passed by, so one mirror cannot wedge the rotation - every probe unverified is blind and holds the cursor, two ticks at most per place in 30 days (a mirror whose OpenNeuro repository is gone) - a 401, 403, 404, 429 or second 4xx in one tick stops before the mirror and stores the new outcome send-refused - a candidate whose reads throw holds the tick twice (audit rows), then is passed by as candidate-error - the result and log line carry probe, candidate and refusal counts and fixed error words, never a message; the dispatch uses the probes' credential directly Tested: scheduler suite (67) and its D1 suite, including the claim's own stop words at tick level, the probe budget across pages and a measured 79-call tick.
A workflow that answers 204 and never runs leaves each dispatch unreported, so the scheduler would send the same mirror again on every rotation. A dataset whose last three dispatches all ended unreported is now skipped as unreported-streak. Tested: scheduler suite (the streak, two in a row, a streak broken by a later report) and its D1 suite.
markDispatchSendFailed's doc said only a refusal ends a dispatch this way; issued() and the scheduler's payload-build guard call it too. The doc now names all three and says a lost answer never ends here. Tested: comment only (typecheck).
The proof's doc and REPULL_G4_DATASETS now say what the design record's G4 is (two re-pulls by hand, the DOI with IsDerivedFrom, the previous version serving) and which half the database shows. Tested: comment only (typecheck).
Move the 7c record under the Phase 7 amendment as its own slice, beside 7a and 7b, and annotate the header. It now records gate G4 as both named re-pulls, defines a refused dispatch as a 4xx (the 7b slice only said a refused dispatch frees its unit), and adds send-refused, the three blind cases, the bounded holds, the unreported streak, the measured tick cost and the accepted CLI-version window between deploy and npm publish. Tested: adr-index suite.
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR1954Version: 🤖 Updated on each push. |
The probe hold read its count and wrote its audit row after the scan had moved the cursor, so a failed write stamped the moved cursor and passed the unverified mirrors by. The cursor is now held first and restored only when the hold passes on. A mirror skipped for unreported-streak raises the tick's log line to warn, and the streak's doc says nothing clears it. Tested: scheduler suite (the audit insert failing holds the cursor; the warn level) and the D1 suite (a probe hold counted at its cursor only).
The 7c slice now says the streak is never cleared, the mirror stays on the administrator's path (re-pulled by hand with repull plan and execute), and the skip raises the tick's log line to warn. Tested: adr-index suite.
neuromechanist
merged commit Oct 25, 2026
6325f68
into
feature/issue-1046-epic-upstream-freshness
20 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
Builds the scheduled path for automatic re-pulls (ADR 0111, dated 2026-10-25 for this slice): a production-only tick selects candidate mirrors whose upstream has a newer snapshot, probes each one against the production rules, claims a dispatch under the open cap through the 7b record, and sends the re-pull to the central workflow with a dispatch token. Everything is gated by
AUTO_REPULL_ENABLEDexactly"1"andENVIRONMENTexactlyproduction; the switches are still absent from every configuration (7a), so nothing dispatches on merge. A non-production environment makes no GitHub call at all. The tick's own outcomes are a closed list of words, the candidate cursor stops at the first ineligible row the probe budget did not reach, and a 5xx from GitHub keeps the unit (a lost answer) while only a 4xx frees it. No mail from any new route.Phase 7c of epic #1046, part of #1913 (which stays open until Phase 7 completes). It builds on 7a (switches and caps) and 7b (the dispatch record and the watchdog, already wired to the production daily block). The central workflow that runs the dispatch is Phase 7d, so nothing can run in production until 7d and 7w land.
What is in it
backend/src/services/github/dispatch.ts: the payload builder andtriggerUpstreamRepullRun(a 9-key payload;repull_idis absent on a first dispatch).backend/src/services/upstream-repull-scheduler.ts(new): candidate selection, the probes, the cursor, the claim and dispatch, andrunRepullSchedulerCron(the production-only entry point).backend/src/services/openneuro-endpoint.ts(new leaf): OpenNeuro's endpoint, split from discovery so the scheduler does not import discovery.backend/src/index.ts: the production-only daily block;backend/test/cron-sweep-wiring.test.tsandbackend/test/cron-dev-safety.test.tspin the call site and the allowlist.upstream-repull-payload.test.ts,upstream-repull-scheduler.test.ts(SQLite), a Miniflare D1 suite that runs one whole tick,repull-discovery-separation.test.ts, and the no-mail scan.Test plan
bun teston the implementer's run: 20671 pass, 242 skip, 4 fail. Three are 5 second timeouts intest/git-annex-remote.test.tsunder machine load (that file alone passes 53 of 53); one group is the website parity test against a 13 day old sibling checkout, which this branch does not touch.OpenNeuroDatasetsraw files (if not, no mirror is everstale_ready); that a 5xx can follow a queued event (assumed in the safe direction); that the workflow takes the nine keys and masks the token; thatpackage.jsonon main is a release version, so a dev build cannot dispatch.