Repository navigation
Phase 7g: the Worker merge for automatic re-pulls - #1971
Merged
neuromechanist merged 32 commits intoOct 26, 2026
Merged
neuromechanist merged 32 commits into
neuromechanist merged 32 commits into
Conversation
The advance tick now takes an automatic record at gates_clear to its merge (upstream-repull-merge.ts): both switches, a bound of three merges per record, fresh machine-clean facts at the merge stage, the record's own claim (which counts the daily merge cap), an audit row written in the statement that decides the send, then one squash PUT at the screened sha with the gate's trailer message, recorded through the verified route. A 4xx keeps the claim and holds merge-refused; a 5xx, a timeout or a 2xx without merged keeps it and holds claim-held. The squash message moves to shared/repull-squash.ts so the gate and the Worker send one message. New hold words: merge-exhausted, merge-message, claim-refused. Tested: upstream-repull-worker-merge.test.ts (55), the advance suite updated for gates_clear rows and the log line, the trailer unit test against git, the no-mail scan, repull-merge-cli.test.ts (23).
A gates_clear record holding a claim is now resolved from GitHub on a later tick (reconcileWorkerClaim), whatever the switches say: a merge GitHub made at the claimed head is recorded; a merge whose answer was lost, or none sent, is sent again only under the same claim, while it is younger than 25 minutes, the switches are on, the facts are clean and fewer than three merges were sent; a refused merge's claim is released through the record's writer once five minutes old, and the record holds merge-refused; a closed pull request frees the claim by the age its answer allows. An administrator's claim is never sent under or released. Tested: upstream-repull-worker-merge.test.ts (66), the advance suite, the no-mail scan, the dispatch word list.
The advance tick's third rotation now also reads automatic records at merged and released (finishAfterMerge): once the merge's version row has its DOI (either spelling), it claims a finish dispatch through the dispatch record (no open cap, one live per dataset) and sends the central workflow's finish mode, at most three times a record, then holds finish-exhausted. It reads no switch, in exact production only, so turning the switches off never strands a minted DOI's lineage, lock and complete. GitHub's 404 or 422 spends an attempt, any other 4xx is dispatch-deferred and does not; a development build sends nothing. The cron and wiring comments now say what the tick does past the gates. Tested: upstream-repull-worker-merge.test.ts (75, the finish payload, the token, the bound, both switches off, the tick's cost), the advance, cron wiring and dev-safety suites, the no-mail scan.
nemar admin repull merge <id> --bids-failure-reason "<text>" (10 to 500 characters) merges a re-pull an administrator opened over a failed BIDS validation. The gate needs GitHub's unstable instead of clean and refuses blocked (a rule requires the check: a bypass) and clean before anything is written, never reuses a held claim, and sends the squash only while GitHub still says unstable. The claim carries the override; the Worker reads at the claimed head that BIDS validation completed with failure, version-check with success and the state is unstable, on an administrator's record, and writes the reason in its own repull_bids_override audit row in the claim's batch. A claim naming it with no reader is refused. Six new refusal words are listed. Tested: repull-merge-bids-override-cli.test.ts (11), upstream-repull-bids-override.test.ts (17), repull-merge-cli, admin-pr-reviews-repull, the merge-claim, route and resume suites, pr-review-approve, the dispatch word list.
The ADR 0093 entry now says an administrator merges by three paths only (pr-reviews approve --merge and y in next, which read GitHub's state and need clean, and repull merge, whose gate all three share for a re-pull and which reads the record, main, the review, the screen and clean, or unstable over a failed BIDS validation with a reason, never blocked), and that ADR 0111 narrows the merge for one class: a machine-clean automatic re-pull pull request, which the Worker merges when AUTO_REPULL_MERGE_ENABLED is on and approves nothing. Tested: the ADR index and docs-links unit tests.
Appends the Phase 7g amendment: the ruleset check the owner ran on 2026-10-26 (installation 131475246 of App 3679074 with contents and pull_requests write among the rest, repository selection all, and an empty organization ruleset list), the Worker's merge and its outcomes, the reconcile of a held claim, the finish run, the administrator's merge over a failed BIDS validation, the kill switch, the new words, the measured cost and what only production can check. Eleven annotations mark the earlier text this builds; ADR 0093's header names the narrowing and its 2026-10-23 amendment is annotated as built; the index entry no longer says the merge is unbuilt. Tested: the ADR index and docs-links unit tests.
The ADR 0111 entry said execution was not yet built; manual execution (6b to 6g) and the automatic path (Phase 7) are now in code. Doc only; no test covers this line.
The administrator's merge gate (checkRepullMerge, through repull merge and pr-reviews alike) and the Worker's reader of a merge over a failed BIDS validation now refuse a pull request whose head or base is not nemarDatasets/<dataset> itself, compared without case as the release pull request's own check does; a deleted fork, whose head names no repository, fails closed. fetchPullRequest reads both repositories. The Worker answers the existing pull-request-mismatch. Tested: a fork's and a deleted fork's head refused before any write or PUT through the ordinary gate (repull-merge-cli), the CLI override and the Worker's override, a base of another repository refused, and the same repository named in another case accepted; deleting either comparison fails its tests.
GitHub's answer to the Worker's merge is a refusal only for 405, 409 and 422 (MERGE_REFUSED_STATUSES). Every other answer that is not a 2xx saying merged: true, a 401, a 403 or a 429 among them, leaves the merge unknown: the claim is kept and the record holds claim-held. The module comment and the Phase 7g slice of ADR 0111 say so. Tested: 401, 403 and 429 keep the claim, write no merge-refused and are not released five minutes on; 405, 409 and 422 refuse, and five minutes on are released as refused with merge-refused. Widening the set to every 4xx fails the 401, 403 and 429 tests.
The Worker's merge rows, its answer rows, the claim owner's edge and the screen's dispatch count compared resource_id with CAST(? AS TEXT) over a bound number. They now bind String(id), as resource_id is written, so the comparison is text against text and the statement is independent of D1's binding type: a number D1 delivered as REAL would have cast to 5.0 and matched nothing. The record's own id = ? keeps its integer bind, and the merge's audit insert takes the text id as a separate parameter. Tested: the 7g merge, BIDS override and advance suites pass (222).
The open resume and the finish of a merged record each kept their own copy of the statuses that say GitHub refused a dispatch itself (404 and 422, `dispatch-refused`). The dispatch module now exports the one set and both import it, so the two cannot drift apart. Tested: the merge, advance and dispatch suites pass (323).
The advance tick's notDue counter described only stalled rows, but the finish of a merged row increments it too: when the version is not minted yet, and when the tick's sends stopped after a refusal. The comment now names both. Tested: comment only; typecheck passes.
A merge GitHub refused (405, 409 or 422) was counted nowhere and only moved the row's hold to merge-refused, so the tick logged it at info level. The tick now counts it (mergeRefused, merge_refused= on the log line) and a tick with one is logged at error level, as a lost answer is. ADR 0111's Phase 7g slice says so, and the 7f log line pin carries the new field. Tested: the merge and advance suites pass (201); a mutant that drops the error level and one that drops the count are each killed by the 405, 409 and 422 tests.
The merge module's step 6 and ADR 0111's Phase 7g slice named only cap-exhausted, cap-unreadable and claim-refused for the record's answer to the Worker's claim. Two more exist: a live head GitHub could not answer (the record's github-unreadable, a 502) holds pr-unreadable, and a record that moved while it was read (stale-status) is skipped for the next tick. Both now say so. Tested: comment and ADR only; the mapping's test comes with the merge tests that follow.
trailers.ts said the two trailer lines had one definition, shared with the Worker's merge. One formatter exists, repullTrailerLines, which the squash message, the trailer check and the N.0.1 patch commit use, but three sites still write the lines by hand: the re-pull commit's own message and the N.0.0 and N.0.1 pull request bodies. The comment now names them. Tested: comment only; typecheck passes.
Adds what the round-1 test review found unpinned in the Worker's merge: a record that moves before the merge's audit row sends nothing; a lost answer is not sent again once main, the review, BIDS validation or the screen is no longer clean; a GitHub that cannot answer for the live head at the claim holds pr-unreadable; a pull request GitHub cannot read keeps a held claim even when the release's own read would succeed; a held claim and a finish are skipped outside exact production and for an administrator's record, the finish before one statement; the finish bound holds at merged; the two bounds are pinned at three; and the rows past their gates rotate five a tick, a merged row with a higher id reached behind six held ones. The GitHub stand-in gains pullReadFailures, a number of pull request reads to fail before it answers again. The file's header no longer claims more than it shows. Tested: the worker-merge suite passes (97). Each of 13 mutants of the merge and the tick is killed by a test added here.
The merge over a failed BIDS validation was tested against a running, a passed and another App's validation and a failed version-check. It now also refuses, at the Worker's claim and through the CLI, a BIDS validation that timed out, was cancelled or was skipped, and a version-check still running, skipped or cancelled: only a validation completed with failure beside a version-check completed with success is taken. Both files' headers now say what they test, a fork's head included, and no longer claim more. Tested: the Worker suite (27) and the CLI suite (18) pass. A mutant that takes any unsuccessful validation as failed, and one that takes any unfailed version-check as passed, are each killed in both suites.
A source scan on the syntax tree, modeled on the re-pull's no-mail scan, over every file of the Worker and the import closure of the re-pull services: GitHub's merge endpoint appears once, as the URL of a PUT in sendSquashMerge; GraphQL's merge mutations appear nowhere; and neither the review endpoint, the APPROVE event nor GraphQL's review mutations appear at all, so no Worker code path approves (ADR 0093). Strings are folded from literals, templates and concatenations. Tested: 9 pass. Each rule is proven to fire on a planted violation: a second merge in another re-pull service, one elsewhere in the Worker built from pieces, the one merge made a POST or moved out of its function, GraphQL's merge, a review with APPROVE split in two, GraphQL's review, an approval outside the re-pull's code, and a new re-pull service picked up without being named.
The merge gate refuses a pull request whose head or base is not the dataset's own repository, but its message named only the head, so a pull request into another repository was refused with its own head named as the reason. The message now names both. Tested: repull-merge-cli passes (26), its new base test included.
The merge gate's fork check compares the head and the base, but only a fork's head and a deleted fork's were tested, so dropping the base comparison passed. The CLI's GitHub stand-in can now name another base repository, and the ordinary gate is tested to refuse a pull request into one before any claim or merge. Tested: repull-merge-cli passes (26). Dropping the head comparison fails the fork tests of the gate and of the override; dropping the base comparison fails the new test.
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR1971Version: 🤖 Updated on each push. |
readRecordedPullRequest checked the head and base refs of the record's pull request but not their repositories, so a fork's branch of the recorded name passed the claim's live read, and only the client's gate refused it. It now reads head.repo and base.repo and refuses unless both are nemarDatasets/<dataset>, compared without case, with the existing pull-request-mismatch; a deleted fork's head fails closed. The claim and the gates read it through liveHeadRefusal, which answers every mismatch other than an unread GitHub as head-moved, so a fork there is head-moved with a message naming both repositories; the verified routes and the Worker's reconcile see pull-request-mismatch, and a fork there keeps the record and its claim. No word list changes. The backend GitHub stand-in now names the dataset's own repository for head and base when a test does not, as GitHub always names both, so no test's fixture changes. Tested: backend re-pull suites pass (955), CLI claim and gate suites pass (461). A fork's, a deleted fork's and another base refuse the claim and the gates with nothing written and no PUT; a fork after the Worker's facts holds claim-refused with no PUT; a held claim reading a fork is kept. Dropping the comparison, either half of it, or its case folding each fails a new test.
The rule that a re-pull pull request's head and base are the dataset's own repository was kept by hand in five places: the machine-clean rule, the Worker's read of the recorded pull request, the BIDS override's reader, the CLI merge gate and the CLI's search for the open release pull request. isOwnDatasetRepo in shared/nemar-app.ts now holds it, exact against nemarDatasets/<dataset_id> and compared without case, and all five call it. Behavior is unchanged. Tested: the backend re-pull suites pass (955) and the machine-clean unit suite (57) with a new test of the predicate. A case-sensitive, a prefix and an always-own mutant of the predicate are each killed: in the unit suite, the claim and override suites, the CLI merge gate and the release pull request search.
The CLI's gates turn (gatesTurn in resume) checked the pull request's branches but not its repositories. A fork's pull request of the recorded branch then reached the Worker's gates edge, which refuses it as a moved head, so resume read it again on every turn until resume-looped, about 20 turns and 43 reads, without naming the fork. The turn now refuses at its first read, with the existing pr-foreign word recorded as the step's error and a message naming both repositories, through the shared own-repository predicate. Tested: in repull-gates-cli a fork's pull request at pr_open, its screen passed, is pr-foreign after at most two reads of the pull request, and the dataset's own repository spelled in another case reaches gates_clear. Dropping the check fails the fork test.
The lists of what a re-pull merge checks were kept by hand and none named the repository rule: AGENTS.md's summary of the gate under ADR 0093, nemar admin repull merge's help, and the property lists of the CLI merge suite and of the claim suite. Each now says the pull request must be from and into nemarDatasets/<dataset_id>, compared without case. ADR 0111's Phase 7g slice gains one sentence saying every merge gate and the claim refuse another head or base repository, and that the earlier amendments' lists do not repeat it; those lists are not edited. Tested: text only; typecheck and Biome pass on the touched files.
The merge module's comment on a claim the Worker holds, and the same branch in ADR 0111's Phase 7g slice, spoke of a merge whose answer was lost. Since only 405, 409 and 422 are refusals, a 401, 403 or 429 takes that branch too, so both now say "lost or did not say what became of it", where the claim is sent again, kept, or expired at 30 minutes. Only the Phase 7g slice of the ADR is edited. Tested: comment and ADR only; typecheck passes.
The two BIDS override suites spelled the word "cancelled" in their headers and test titles. Prose now says "canceled", in American English; GitHub's own conclusion value, "cancelled", stays in the code that builds each check run. Tested: the Worker override suite passes (27); titles and comments only.
The Worker's merge returns skipped, not claim-refused, when the record moves between the claim's read and its commit (stale-status), so the next tick reads it as it is; replacing that branch with if (false) left every test green. A revision bump just before the claim commits now shows the tick holds nothing, refuses nothing, writes no log line and sends nothing, and the next tick merges the record. Tested: worker-merge suite passes (100); the if (false) mutant of the stale-status branch fails the new test.
The statements that compare an audit row's resource_id bind the re-pull's id as text, so D1 never compares a REAL 5.0 with "5"; but SQLite under Bun coerces a bound number to the column's text, so reverting any of those binds to the number passed every test. Two guards now read the binds through interceptingD1: in the Worker's merge, every statement with resource_id = ?n is bound a string there, across a lost answer and the held claim's next tick (the merge's audit row, its merges and the claim's owner); in the advance tick, the screen's dispatch count is bound String(id). Tested: the worker-merge (101) and advance (122) suites pass. Reverting each of the four binds to a number fails its guard.
The Worker's read of the recorded pull request treats a head or base repository GitHub does not name, or names in another shape, as an unreadable answer, but no test covered it; without the base check a missing base.repo threw a TypeError instead of answering 502. Four answers (each repository missing, and malformed) now each refuse the claim and the gates with github-unreadable (502), one test per answer; the record of a merge refuses the same four; and in the tick each holds pr-unreadable before anything is claimed or sent. Tested: the claim (48) and worker-merge (105) suites pass. Deleting the head repository's shape check fails both head rows; deleting the base repository's fails both base rows.
The test of a held claim whose pull request turned into a fork's used an unmerged pull request, so it reached only the release half of its title. A pull request GitHub reports merged at the claimed head and branch, but from a fork, is now shown to keep the claim held: the Worker never records a fork's merge as the re-pull's. Tested: worker-merge suite passes (106). Dropping the head comparison of the claim's read fails the new test on its own.
Three assertions could not fail. The claim suite's fork test and the
override suite's refusals asserted that GitHub was sent no merge, but
the claim route never sends one: the fork test now asserts the words
its refusal names each repository by, for the claim and the gates, and
the override's refusals that no claim edge was written. The Worker's
merge test asserted refused: {} through toMatchObject, which in Bun
matches any object; it now asserts the maps with toEqual. The advance
suite's five matchers of the same kind (held, refused and reviewRefused
as {}) are made exact the same way, and all hold.
Tested: the claim (48), override (27), worker-merge (106) and advance
(122) suites pass.
The advance tick's notDue comment named merged rows only, but a released row counts too when the tick's sends stopped after a refusal; only a merged row waits for its version's DOI. The comment now names both statuses and which reason each can have. Tested: comment only; typecheck passes.
neuromechanist
merged commit Oct 26, 2026
ef834ad
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
Phase 7g of epic #1046, part of #1913 (which stays open until Phase 7 completes). It builds the Worker's merge of a machine-clean automatic re-pull pull request (ADR 0111, the 7g slice), the reconciliation of an unanswered Worker merge, the finish of an automatic re-pull after its merge, and an administrator's merge over a failed BIDS validation. The merge reuses 6f's gate in
src/lib/repull/merge.tsand does not re-implement it.The Worker reads fresh machine-clean facts at the merge stage and refuses on any unknown fact. The BIDS override is administrator-only, refuses
blocked, and never applies to an automatic row. A head or base repository other thannemarDatasets/<dataset_id>is refused at every merge gate, at the claim and at the gates turn.ADR 0093's merge is narrowed for the one automatic class in AGENTS.md, and the ADR 0111 entry there says execution is built. V2 (the App installation's permissions and the empty organization ruleset list, run by the owner on 2026-10-26) is recorded in the 7g slice.
Deviations from the plan (the code wins; each is a safer direction)
shaandmerge_method, because 6f reads the trailers back after the merge. The message builder moved toshared/repull-squash.ts, so the CLI and the Worker share one.mergeRepullPullRequestdoes not exist. The override goes through 6f'scheckRepullMergeandsendRepullMerge, with the reason carried inGateContext.bidsFailureReason.merged: true, is unknown: the claim is kept and the record holdsclaim-held, so a rate limit or a permission error is never recorded as a refusal.refusedonce it is five minutes old (6e's rule), and the record holdsmerge-refusedwithout being claimed again.claim-heldfor an administrator'sresume.repull_auto_mergeaudit row is written before the PUT, in the statement that enforces the three-merge bound. GitHub's answer goes in a separaterepull_auto_merge_answerrow.mergedas well asreleased.Review outcomes
Round 1 (a code and security lens, and a tests and comments lens) found no critical findings. Fixed: the administrator's override accepted a fork head; every 4xx was a permanent refusal; audit ids are bound as text; a refused merge logs at error level; the finish refusal set is declared once; test gaps for the fences, the bounds, the override states, the rotation, the stale-status skip and the unreadable repositories; comments that were false or inexact. Accepted with a reason: the tick log holds only refusal codes by design, so a fork at the claim reads
head-moved(the claim keeps the documented code for every non-502 mismatch, and the response names both repositories). Filed outside this PR: #1972 (the three commit writers that hand-format the trailer lines) and #1973 (older test headers that claim every property fails when its line changes).Round 2 (the last review, fix commits only) found no critical or important findings. Fixed: the Worker's claim did not compare repositories; the CLI gates turn did not compare them either, so a hand-edited fork record looped before refusing; five copies of the own-repository check are one predicate (
isOwnDatasetRepo); the gate lists in AGENTS.md, the ADR, the CLI help and the test headers name the repository rule; the lost-answer wording covers unknown answers; a reverted bind type, a skipped stale-status branch and unreadable repositories each now have a test that fails.Test plan
bun run typecheckclean (exit 0).backend/test/upstream-repull*.test.tsplus the 7g suites): 927 pass, 0 fail, 18 files.bash scripts/ci/unit-pure-files.sh | xargs bun test --parallel=4): 19,520 pass, 44 skip, 1 fail. The one failure iswebsite parityagainst the local sibling checkout ofnemarOrg/website, which lags on an older feature branch. WithNEMAR_WEBSITE_ACCOUNT_COPYpointed at GitHub's copy, it passes 9 of 9. CI's unit-pure shards 1 to 6 pass on this head.test/*repull*): 706 pass, 3 skip, 0 fail. One earlier run hit a Bun runtime crash in a spawned process under load (test/repull-patch-cli.test.ts); it passes alone (20 of 20) and on the final head.integration-dev(the live tier) is still pending and is not waited on. The epic-to-dev PR waits on CI.mergeable_state, whether GitHub squash-merges at the givenshawith our message, and whetherrun-pr-mergetags an App squash and mints its DOI); the BIDS override on a real repository (whether an unprotected mirror readsunstablerather thanblocked, and whether anunstablepull request merges); the finish run from a real runner once 7w deploys the workflow.