Repository navigation
Phase 7b: the automatic re-pull dispatch record - #1950
Merged
neuromechanist merged 10 commits intoOct 25, 2026
Merged
neuromechanist merged 10 commits into
neuromechanist merged 10 commits into
Conversation
Migration 0109: upstream_repull_dispatches (one row per dispatch of the automatic re-pull, on datasets only, a nonce held exactly while live, one live dispatch per dataset), the scheduler's one row, and hold_reason/hold_since on upstream_repulls (automatic rows only, set together). The shared words for kinds, states, codes, hold reasons, the planner pin and the copy bound. The dataset cascade deletes the dispatches before the re-pull rows. Tested: every CHECK and index on bun:sqlite and Miniflare D1; the cascade against a loopback GitHub stand-in.
A callback token kind of its own for the automatic re-pull's run: HMAC-SHA256 with the shared callback secret over a domain line, the dispatch id, its dataset and its one-shot nonce; a field with a line break is refused by the signer and fails the verifier. Re-exported from the services/github barrel; the surface pin gains the three names. Tested: round trip, every field bound, and domain separation in both directions against all eight other token kinds.
The dispatch service: claimOpenDispatch (exact production and the open switch; one unit of REPULL_DAILY_OPEN_CAP counted in the claim's own statement; a first dispatch needs no open re-pull, a resume an automatic row that stalled before pr_open), claimFinishDispatch (exact production only, no cap), markDispatchSendFailed, the check an automatic create makes of its dispatch, and the watchdog that ends a dispatch silent for 8 hours as unreported. POST /webhooks/repull-state stores a run's report: started once, then opened, finished, refused or failed, a compare-and-set on the nonce, one answer for every token refusal, codes from the closed list. No mail; the no-mail scan gains both roots. Tested: real SQLite through the webhooks router, the statements on Miniflare D1, the Resend capture empty, each guard mutated.
POST /admin/repulls takes dispatch_id and dispatch_token, both or neither; origin is in no request. A create with a live dispatch whose token the Worker signed records origin automatic, after exact production, the open switch and an on dataset; the dispatch must name the dataset, ds and both tags; the plan must be planner 2 with unexplained, conflicts and corrections stated and 0, and a stated copy of at most 1 TiB. The insert links the dispatch by the row's key. An open record is returned only to a caller of its own origin, and a dispatch that names its record takes only that one. Tested: the route with real SQLite, each refusal with nothing written; a scan that every literal refusal word is a dispatch code.
The 7b slice of the Phase 7 amendment: the dispatch record and its states, production only, the open cap counted at the claim, the dispatch token and the report callback with its closed code list, the watchdog, origin automatic only through a Worker-signed dispatch with the planner pin and the zero-unexplained check, and the same-origin reading of "the same plan is the same record". Not tested (prose).
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR1950Version: 🤖 Updated on each push. |
The automatic create checks the token before it says anything about a dispatch, so an unknown, ended or wrong-token dispatch is one 401. The link is guarded by liveness and rolls the create back. A claim that cannot be handed out is ended, an odd tag and an unreadable cap are their own refusals, the claim audit is built in SQL, and the watchdog throws on an absent count. Comments match the code. Tested with the backend dispatch, route and D1 suites.
Covers the token oracle, the callback without switches, the unconfigured refusals, the stale-dispatch race, resume tags, closed rows after pr_open, the stranded claim, the link guard, the watchdog bound and count, the cap's kept units, run URLs and the Miniflare D1 cap and live races.
States the single token answer, token masking, the cap's scope and deletion, the guarded link and the stranded-claim end.
The watchdog is called from the production-only daily block, is declared prod-only in the sweep wiring test, and ADR 0111 records that its wiring lands in 7b. Tested with the cron wiring suites.
When the claim insert reports no id the dispatch is ended by its nonce, a failed cleanup logs both errors and throws the original, and the ADR says a racing create's loser gets the token 401. Tested with fault injection on the real engine.
neuromechanist
merged commit Oct 25, 2026
974f7c2
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 record the automatic re-pull path keeps of each dispatch the Worker sends, each run's report back, and the one way an automatic re-pull is recorded (ADR 0111, dated 2026-10-25). Migration 0109 adds
upstream_repull_dispatches, a dispatch token kind signed with the callback secret, the report callbackPOST /webhooks/repull-state, the automatic create inupstream-repull.ts, a watchdog that ends a dispatch the run never reported, and the delete cascade. Nothing here sends a dispatch, schedules anything or merges; those are later slices, so this slice is inert until they land. No mail from any new route or callback.Phase 7b of epic #1046, part of #1913 (which stays open until Phase 7 completes). It builds on 7a (the switches and caps, merged as aa7234d) and on the merged 6a record.
What is in it
backend/src/db/migrations/0109_upstream_repull_automatic.sql: the dispatch table, the scheduler row, andhold_reasonandhold_sinceonupstream_repulls(automatic rows only).backend/src/services/upstream-repull-dispatch.ts(new),backend/src/services/github/callback-tokens.ts(the dispatch token kind),backend/src/routes/callbacks/repull-state.ts(new),backend/src/routes/webhooks/index.ts,backend/src/services/upstream-repull.ts(the automatic create),backend/src/services/deletion.ts(the cascade),backend/src/services/github.ts.upstream-repull-dispatch.test.ts,upstream-repull-dispatches-migration.test.ts(Miniflare D1),repull-dispatch-token.test.ts,repull-dispatch-words.unit.test.ts, extendedupstream-repulls-route.test.ts, the no-mail scan, and the export and webhook route inventory pins.Test plan
bun testrun by CI on this head (the lead runs it through the Tests workflow).repository_dispatchacceptance and its response shape (7c and 7d), and the watchdog against real queue timing.