Repository navigation
Phase 7h: observability for automatic re-pulls - #1974
Merged
neuromechanist merged 25 commits intoOct 26, 2026
Merged
neuromechanist merged 25 commits into
neuromechanist merged 25 commits into
Conversation
The weekly import report gains an "Upstream re-pulls" section after the upstream freshness one. It arrives every week, quiet or not (ADR 0054), and counts the week's dispatches by kind, state and word, the open automatic re-pulls by hold word, claims to merge held over an hour, re-pulls that ended failed, and merges by who held the claim (the Worker, an administrator's tool, none). It shows the switches and caps in force and the scheduler's last ticks, names no dataset, and prints a word only when it is on its closed list and does not name anonymity. Attention follows ADR 0053 exactly: a switch on with the scheduler silent for 26 hours, an unreported or refused dispatch, a claim held over an hour, a failed re-pull, a bound reached, an unreadable cap. A switch that is off, a hold waiting on a gate and a run's refusal are quiet. A read that fails leaves the facts null and lists a failed part (ADR 0054). The shared attention rule adds the reasons, so the headline and `nemar admin import-weekly` cannot disagree; the command prints the same counts, and the log line gains repull_dispatched, repull_merged_worker and repull_unreported. Tested: a new suite through the report's entry point on real SQLite with the production writers' audit rows, the same statements on Miniflare's D1, the CLI against a canned report, and the no-mail scan with the new service as a root. Mutation checks recorded in the PR.
`GET /admin/repulls/dispatches?dataset=&status=&after=&limit=` lists the automatic path's dispatches newest first, as a keyset page of at most 50 rows (25 by default), registered before `/repulls/:id`. It selects its columns by name, so a live dispatch's one-shot nonce never leaves the Worker, and it names the dataset, which the weekly report never does. `GET /admin/repulls/switches` now also returns the scheduler's three stamps (never its cursor, a dataset id), null when the row is absent and a 500 naming migration 0111 when the table is. Tested: a new route suite on real SQLite (order, the cursor, the page bound at the route and in the service, the filters, malformed queries, the nonce, roles, no mail), the switches route suite, the route inventory, and the list and the scheduler's row on Miniflare's D1. Mutation checks recorded in the PR.
`nemar admin repull auto [--json]` shows the automatic re-pull as the Worker reads and records it: the switches and both daily caps (an unreadable cap says so and reads 0), the scheduler's two stamps, the open automatic re-pulls with the word each is held for and any claim to merge still held, and the 20 newest dispatches. It names datasets and ids, which the weekly report never does. It reads every page of open re-pulls and says when the list stopped before its end, shows an absent scheduler row as unknown rather than never recorded, makes only GET requests, and prints nothing when a read fails. The API client gains getRepullSwitches and listRepullDispatches. Tested: a new CLI suite through the real entry point against the real admin routes over real SQLite (text and --json, paging, truncation, unknown, a member's refusal, a failed read, GETs only), the command list and help text, and the API export surface. Mutation checks recorded in the PR.
Appends the Phase 7h slice, dated 2026-10-26: the weekly report's re-pull section (what it counts, how a merge is attributed by its claim, the words it prints, unknown never zero), what asks for attention under ADR 0053 and what does not, the administrator's list and command, the kill switch as the runbook will state it, and the closing sentence that the slices of Phase 7 are complete. Adds the header and Decision annotations and a new last item under Not yet verified, and updates the README index entry to name the 7a to 7h slices. Documentation only; the ADR index test passes.
Five suites each carried their own copy of the insert that seeds a row of upstream_repull_dispatches. They now share one in backend/test/helpers/repull-rows.ts: the statement, its binds for any driver, and a bun:sqlite seeder. The two Miniflare suites bind the same values, and a live dispatch's nonce carries one recognizable mark, so each suite that proves the nonce never leaves the Worker asserts on it. Tested: the five suites pass unchanged (71 tests), and the nonce assertions still fail when the list selects the whole row.
The merge count read every audit row of an edge into merged or patch_merged. The release's step errors (a tag or a version row not there yet) write an edge from merged to merged, through the same writer, so one Worker merge plus two release errors reported worker=3, and one merge outside NEMAR's tools plus one error reported unattributed=1, in a public report. The statement now counts an edge only when it starts somewhere other than where it ends, and its comment and the 7h slice of ADR 0111 say so. Tested: three regression tests drive the production writers (transitionRepull and recordRepullMerged): one merge with two release errors counts once, an outside merge with an error is not unattributed, and N.0.1's error adds nothing. Each fails on the old statement with the counts above.
The merge tests now go through the production writers (transitionRepull, recordRepullMerged, releaseMergeClaim) instead of hand-built audit rows. They pin the four counts with distinct numbers, so a swapped predicate moves a count; that whoever records a merge does not decide its claimant; a claim taken over; N.0.0 and N.0.1 on one record taking each its own latest earlier claim; and the inclusive start and exclusive end of both the merge and the failed windows. Tested: the section suite passes; 11 mutants (ORDER BY ASC, dropped earlier-claim bound, claimant from the recorder, three predicate swaps, the outside flag, four window edges) each fail it.
The weekly re-pull read sends five statements as one batch and took whatever answers came back. A batch with more or fewer answers than statements, or with an answer that did not report success, is now a read that failed, so the section is unknown with a failed part and never the counts that did arrive. A missing rows array already threw and now has a test of its own. The tests alter the batch answers of a real D1 (failure injection, no canned rows) and fail the batch at the batch step as well as at the prepare step, where only the prepare step was failed before. Tested: the section suite and the six suites that call the gather pass; 7 mutants (rows guard to an empty list, length clause dropped, success clause dropped, success tolerated when absent, a swallowed batch rejection, an unchecked batch, a one-sided length test) each fail it. ADR 0111's Phase 7h slice states the rule.
merge-refused, gates-refused and claim-refused are counted in the table of holds and ask for nothing, with both switches on and a fresh scheduler; one test each. A broader test seeds every hold word but the two bounds (resume-exhausted, finish-exhausted) and expects no reason, so a word added to the list later cannot start asking unnoticed. ADR 0111's Phase 7h slice now says so beside the gate holds. Tested: the section suite passes; 6 mutants (merge-refused, gates-refused, claim-refused, merge-exhausted and resume-refused each asking, and any hold beyond the two bounds asking) each fail it.
The weekly section's footer, the shared attention rule's comment and ADR 0111's Phase 7h slice said that "a bound reached" asks for attention. Only two bounds do (resume-exhausted and finish-exhausted); the merge bound, merge-exhausted, is a hold that is counted and does not ask. All three now name the two, and the footer adds that every other hold is counted in its table and does not ask. Tested: the section suite passes with a new pin on the footer's text; 2 mutants (the old wording back, the new clause dropped) fail it.
The second re-pulls line of nemar admin import-weekly printed three of the four merge counts and left out the merges whose claim is not in the audit log, so the line did not add up to the merges. It now prints merged_unattributed as well. The CLI fixtures now hold a different non-zero number for every count the two lines print (a routine week for the ones that do not ask, and a busy week with all fourteen), so a label moved onto another count is a different line. Tested: test/import-weekly-cli.test.ts passes; 7 mutants (the count dropped, and six labels moved onto another count) each fail it.
repull-switches.ts declared CapReading and RepullSwitchesReport, and shared/repull-observability.ts declared the same two shapes as RepullCapReading and RepullSwitchesReport for the wire. The service copies are deleted and the three importers (upstream-repull, upstream-repull-dispatch and the readers in repull-switches itself) take the shared names, so the Worker and the CLI read one declaration. No behavior change. Tested: bun run typecheck exit 0; Biome clean; the switch, dispatch, merge and no-mail suites pass.
Three gaps the review found in the weekly section's tests. An unreadable cap must read "unreadable, so it reads 0" and never "0 (the default)". A report whose re-pull field is absent (an older backend) must render unknown in the body and in each of the three log counts without throwing, and must raise the could-not-be-determined reason. A claim to merge on N.0.1's pull request is held to the same hour as N.0.0's: exactly an hour is not older, a second more is. Tested: the section suite passes; 7 mutants (the cap rendered as the default, the absent field treated as a value in the body and in each log count, the N.0.1 bound made inclusive, the N.0.1 half of the claims dropped) each fail it.
The help for nemar admin repull auto, and ADR 0111's Phase 7h slice, said that nothing is printed when a read fails. The command prints the failure line and no table, which its own test already pins, so the help now says "Only the failure is printed then, never a table" and the ADR says it prints the failure and no table. The help test pins the new wording and rejects the old. Tested: the command-text suite and the ADR index test pass; 2 mutants (the old wording back, a table said to follow) fail the pin.
The closed-list rule for a word (on its list, and not naming anonymity, else other) ran only in the gather, so a table rendered from facts that held an id where a word should be would print it, and the test that claimed otherwise rendered a fixture with no id in it. The rule moves to shared/repull-observability.ts as publicWord; the gather uses it, and the renderer now folds every word of every table and the scheduler's outcome through it and adds the counts that come to the same word, so the report on a public repository holds no identifier by either road. The id test now renders facts with ids of every shape in each place a word is printed, beside listed words and one that names anonymity, and pins the exact tables. publicWord has unit tests of its own, including that a digit does not withhold the four codes that hold one. Tested: typecheck exit 0; the section suite, the dispatch words suite and the ADR index test pass; 15 mutants (the renderer raw, unsummed, raw outcome and on the wrong list; publicWord without its list, without the anonymity rule, with a digit rule and with swapped lists; the gather on the wrong list) each fail them. ADR 0111 states the rule.
Two tests could not fail. The headline test compared weeklyHeadline(f).attention with weeklyAttention(f).attention, which is one value read twice. It now asserts the literal text: the Worker's reasons in the headline word for word and in their order, a quiet week adding none, and a week that is null or absent asking in words. The statement test matched dataset_id in the SQL text, which "dataset_id AS d" evades. It now runs each of the five statements over seeded rows and requires exactly the columns the gather reads. Tested: the section suite passes; 10 mutants (one reason, reversed reasons, null or absent not a reason, a headline of the first problem, and a dataset_id column added to each of the five statements) each fail it.
The headers of the weekly section test, the dispatch route test and the auto command test said each property has "a test that fails when its line is changed", which no header can promise; they now say "a test of its own". The section test's header also names what the suite now covers (facts that hold an id, a partial batch, the holds that do not ask). "Modelled" is "modeled" in the route test. Comments only. Tested: Biome clean; the three files are unchanged in behavior and the section suite still passes.
listRepullDispatches sends four filters (dataset, status, after, limit) and the command used only limit, so a client that dropped or misnamed any of the others passed every test. The client is now called in-process against the real routes over real SQLite, with six dispatches over two datasets and three states: one test each for dataset, status, after (strictly below the named id) and limit (with the cursor it returns continuing the page), one for the filters together, and one for none. The route and the client have no kind filter, so none is tested. Tested: test/admin-repull-auto-cli.test.ts passes; 6 mutants (each of the four filters removed from the client, the dataset sent under the wrong name, after sent as limit) each fail it.
Nothing checked that nemar admin repull auto keeps a key out of its output, though the brief requires it. The test stores an admin key, sets NEMAR_API_KEY, GH_TOKEN, GITHUB_TOKEN and AWS credentials in the CLI's environment, and puts secret-named sentinels in the Worker's bindings (the GitHub PAT, the Resend and callback keys, the encryption key), then runs the command as text and as --json and requires that neither stream holds any of them, the stored key's eight-character prefix, or a Bearer header. It also requires that something was printed, so an empty output is not a pass. Tested: test/admin-repull-auto-cli.test.ts passes; 5 mutants (GH_TOKEN printed after the table, NEMAR_API_KEY and AWS_SESSION_TOKEN in the JSON, the client logging its Authorization header to stderr, the Worker's bindings spread into the switches report) each fail it.
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR1974Version: 🤖 Updated on each push. |
A merge recorded as made outside NEMAR's tools has a claim edge in the log when the claim was released and the merge was then made by hand. Without the guard in the worker and administrator counts, the same merge was also the claimant's. Two tests (the Worker's released claim, an administrator's) record such a merge through the production writers and require one merge outside the tools and none under the claimant. The lost-claim test now rewrites the claim edge as an entry edge from pr_open instead of deleting it, so a claim edge that is not a self-edge is seen not to be a claim. Tested: the section suite passes; 3 mutants (the outside guard dropped from the worker count and from the administrator count, and the self-edge guard dropped from the claim edge) each fail it.
The weekly merges statement took the latest claim edge of either pull request before a merge, so an N.0.1 merge whose own claim edge was lost (an audit row that never landed) was counted as N.0.0's claimant's, and the merge count named a claim that was not its own. It now takes the claim edge of the pull request that merged: the gates_clear self-edge for a merge into merged, the patch_gates_clear one for a merge into patch_merged. An N.0.1 merge with no claim edge of its own is unattributed. The doc comment on the statement and ADR 0111's attribution sentence say the claim of the pull request that merged. Two tests (N.0.0 claimed by an administrator and by the Worker) lose N.0.1's claim edge and require unattributed; the D1 path gets the same rows, so Miniflare's D1 runs the CASE as well. Tested: the section and D1 suites pass; 2 mutants (the either-pull- request predicate back, and the CASE inverted) fail them.
The D1 path had no row for the release step's error on a merged record, so the from-is-not-to clause of the merges statement ran there over nothing it could exclude. The Miniflare test now holds a merged-to-merged edge on N.0.0's record and a patch_merged-to-patch_merged edge on N.0.1's, and still expects the same counts: neither is a merge. Tested: the D1 suite passes; 2 mutants (the clause dropped, and inverted so only self-edges count) each fail it.
The scheduler's last_tick_at and last_advance_at are text columns that check nothing about their content, and the report printed them as they were stored. A forged value (a dataset id, say) would have reached the public repository. A stamp is now printed only when it has the form SQLite's datetime() writes; any other value is said to be "a recorded run that could not be read", and with a switch on that is the existing reason that the scheduler's last run could not be read. The test stores six forged values (an id, an id with a time before or after it or on a second line, an ISO form) in both stamps, requires that neither appears in the report and that the sentence says so, and requires that a real stamp is still printed. ADR 0111's slice states the rule. Tested: the section suite passes; 4 mutants (printed raw, each anchor of the shape check dropped, the check inverted) each fail it.
The weekly section's footer, which says what asks for attention, left
out a dispatch that GitHub did not accept (dispatch_failed), which the
rule raises a reason for.
The footer now says "a dispatch nobody answered or that GitHub did not
accept"; the shared attention rule's comment, the weekly service's
header and ADR 0111's attention list say the same, in the words of the
reason itself ("not accepted by GitHub") rather than "refused", which
is also the word for a run's refusal, a state that does not ask.
Each case of the one-reason-at-a-time test now carries the footer's
words for its reason and requires the section to hold them, so a
reason the rule raises that the footer does not name fails its case.
Tested: the section suite passes; 5 mutants (the footer without the
dispatch clause, without the held claim, the failed re-pull, the
unreadable cap, and the scheduler) each fail it.
ADR 0111's Phase 7h slice said an answer "that holds no rows" is a failed read. The code throws on an answer with no rows array, and treats an empty array differently by read: on a grouped read (the dispatches, the holds) it is a true zero, and on a count, which always returns one row, it is a failed read. The ADR and the gather's comment now say that. The empty counts had no test, so the claim is backed: the claims, the merges and the failed counts each come back with an empty rows array and the section is unknown with the aggregate's own message. Tested: the section suite and the ADR index test pass; 2 mutants (the aggregate check removed, an empty merges answer read as zeros) fail it.
neuromechanist
merged commit Oct 26, 2026
611cf99
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 7h of epic #1046, part of #1913. It adds the re-pull counts to the weekly report, an admin dispatch list,
nemar admin repull auto, and the Phase 7 record in ADR 0111. Issue #1913 closes by hand after this merge.The weekly report counts the week's dispatches, holds, merges and failures from stored rows, in one D1 batch. A failed read is shown as unknown, never zero. Attention is raised only for the bounds the ADR names. Fault holds are counted, not alerted. The report names no dataset, and only fixed words print.
GET /repulls/dispatchesis keyset-paginated, at most 50 rows.nemar admin repull autois admin-only and prints the switches, the caps, the scheduler row, the open automatic rows and the recent dispatches.No migration, no cron, no mail.
Review outcomes
Round 1 (code and tests lenses): fixed a merge count that included release-error self-edges (reproduced: one merge plus two release errors reported three); a partial D1 batch now reads as unknown; the import-weekly CLI prints every merge count; the switch types are declared once; tests added for exclusive merge counts, claimants, window edges, fault holds, absent fields and the N.0.1 boundary; weak tests rewritten; the closed-list word rule is shared.
Round 2 (last, fix commits only): the claimant is the one for the pull request that merged; scheduler stamps print only as times; a dispatch GitHub did not accept is named in the footer; the D1 path runs the self-edge clause.
Accepted with a reason: an unreadable cap reads 0 under the fail-closed rule, and the text leads with "unreadable"; the SQL
json_extracton audit details, where a malformed row makes only this section unknown.Rejected with a reason: a
kindfilter on the dispatch list, because neither the route nor the client has one, and ADR 0111 specifies dataset, status, after and limit.Test plan
bun run typecheckclean (exit 0).website parityagainst the local sibling checkout; it passes 9 of 9 against GitHub's copy.