Skip to content

feat: nemar admin pr-reviews start - #1706

Merged
neuromechanist merged 3 commits into
devfrom
feature/pr-review-start
Oct 10, 2026
Merged

neuromechanist merged 3 commits into
devfrom
feature/pr-review-start

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

What this is

The automated review of dataset pull requests reacts to events. A pull request that was open before the review was switched on produced none, so it would sit unreviewed until its author pushed again. nemar admin pr-reviews start gives an administrator a way to review those, one by name or all at once, and to start again a commit whose review ended without a verdict. It is the follow-up promised in ADR 0092 ("a re-run command belongs with the admin follow-up").

How it works

POST /admin/pr-reviews/:dataset/:pr/start reads the pull request from GitHub with the datasets token (nothing about it comes from the caller), shapes it as the pull_request delivery it would have been, and hands it to the one gate every delivery goes through. So the flag, the "public, named, first-published" test, the per-commit dedupe, the contributor pause and the platform's daily pool all apply. Two things differ, both the administrator's choice made by name:

  • the per-contributor hourly and daily allowances do not hold the review back;
  • a commit whose review was declined, errored, never reported, or was handed to GitHub more than 30 minutes ago and never answered is started again. A new delivery of the same commit still restarts nothing but a dispatch GitHub did not run.

start --all lists the open pull requests with no review of their current commit (not_reviewed and could_not_decide), leaves drafts out, asks before spending (each one is a model call), starts them one at a time, and stops with exit 1 when the daily pool is spent. --dry-run lists and starts nothing. --json is one document.

What the review of this change changed

Four reviewers read it (code review, silent failures, comment accuracy, test mutation); every finding below was checked and has a test that fails without the fix.

  • The pool counted rows, not model calls. A restart reuses the row, so a review restarted three times cost three calls and counted once. Migration 0095_pr_review_attempts.sql adds pr_reviews.attempts (1 for every existing row), the pool sums it, and a restart of an attempt that had already spent a call adds one when it is handed to GitHub. A decline, a stale head and a dispatch GitHub never ran spent none.
  • A restart is ranked as the newest row. The cap queries use id <= ?, so an old row's id would have counted it ahead of every later row.
  • A restart is held to the pause and the pool, and the redelivery of a failed dispatch goes through the same restart.
  • An overdue dispatched row is restartable. The queue reports it as could_not_decide (the production watchdog would close it as unreported, and dev has no watchdog), so --all listed it and then start refused it as a duplicate.
  • Two starts at once hand a commit over once: the reset is guarded on the row's state and detail, and a test runs two at the same time.
  • The dataset is checked for reviewability before GitHub is read, so a dataset that cannot be reviewed neither costs a read nor echoes a pull request author. GitHub's errors map to words (404, rate limit, refused, unavailable, unreadable). The audit row is written only for a start and never turns a started review into an error.
  • The CLI marks a pull request GitHub does not have as a reported exit (no "attach a debug log" nudge), refuses --dry-run on a single start, and exits 1 when GitHub refused a dispatch.

Tests

Real SQLite behind the real admin router and auth middleware, and the real CLI binary; GitHub is a Bun.serve() stand-in. After the review, about 100 one-line mutants were run against the two new suites; the survivors that mattered (a redelivery restarting a decline, a restart keeping claimed_at, --dry-run ignored with --yes, a refused dispatch not being a fault, the concurrency guard, the daily allowance, the tally-based pause, route validation) now have tests, and I re-ran the mutants against them: all are killed. The documentation (ADR 0092 and 0093 amendments, CHANGELOG) is written to match.

Not in this change

  • Turning the review on in production. The flag lives in backend/wrangler-sccn.toml, so that is a release, after the dev trial has passed.
  • run-pr-review.yml is not yet in nemarDatasets/.github; this session cannot write there.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XpB5Wz7WvF2AZNfqYZLoRR


Generated by Claude Code

The Worker reviews on events, and a pull request that was open before the review was switched on produced none. POST /admin/pr-reviews/:dataset/:pr/start reads the pull request from GitHub itself, shapes it as the delivery it would have been and runs it through the one gate, so the flag, the dedupe, the pause and the platform pool apply. An administrator's start lifts the per-contributor allowances for that review and restarts a commit whose review ended declined, errored or never reported. A redelivery of a failed dispatch is now held to the pause and the allowances too (ranked as the newest row), which closes the gap recorded in ADR 0092.
Review a pull request that was already open when the review was switched on, one by name or all of them (--all, --dry-run, --yes). It lists the open pull requests with no review of their current commit, leaves drafts out, lists a paused contributor's apart, asks before spending, and starts them one at a time, stopping when the daily pool is spent. ADR 0092 and 0093 record it.
@github-actions

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR1706

Version: 0.10.16-PR1706.bb0bc82
Commit: bb0bc82


🤖 Updated on each push.

Copy link
Copy Markdown
Contributor Author

Review record

Four reviewers read this change before it was opened (code review, silent failures, comment accuracy, test mutation). Their findings were checked against the code. What each led to:

Fixed, with a test that fails without the fix

Finding Fix
The daily pool counted rows, so a restart of a review that had already cost a model call was free Migration 0095 adds pr_reviews.attempts; the pool sums it; a restart adds one when handed to GitHub. Mutations of the increment and of extraCalls are killed.
A restarted row kept its old id, so the id <= ? cap queries counted it ahead of every later row Ranked as the newest row for the cap decision
--all listed an old dispatched row that start then refused as a duplicate (dev has no watchdog) A dispatched row older than PR_REVIEW_DEADLINE_MINUTES is restartable
Two starts at once could hand a commit over twice The reset is guarded on state and detail and checked for one changed row; a test runs two at once (service level; over HTTP they serialize on the GitHub read)
A dataset that cannot be reviewed still cost a GitHub read and echoed the pull request author Reviewability is checked first
GitHub errors collapsed into one word 404, rate limit, refused, unavailable and unreadable each have a word
An audit row could turn a started review into an error Written only for a start, best effort
A pull request GitHub does not have ended with "attach a debug log"; --dry-run on a single start was accepted; a refused dispatch exited 0 Reported exit; refused; fault exit (text, JSON and --all)
Comments and ADRs said things the code did not do (--all "lists a paused contributor apart", "re-run not available", the route header saying nothing comments) Rewritten to match; one literal \n in ADR 0093 removed

Test-mutation review. About 100 one-line mutants against the two new suites; 41 and 18 killed at first. The ones that survived and mattered now have tests, and I re-ran those mutants: a redelivery restarting a decline or an unreported review, a restart keeping claimed_at, published_at, publish_attempts or decided_at, --dry-run ignored with --yes, the single-start --dry-run refusal removed, dispatch_failed dropped from the fault set, a break after a failure in --all, the concurrency guard removed. All are killed. The stand-in gained a dispatchStatus knob so a refused dispatch can be tested.

Not changed, and why

  • The intake takes the dataset and number from GitHub's pull request body, not the URL, and does not cross-check them. GitHub would have to contradict itself; hardening, not a path I could trace to a failure.
  • The markDispatchFailed paths on a thrown database error are covered by one injected-fault test, not by a mutant per branch.
  • The JSON shapes of the empty and truncated --all runs, and the count wording of the summary line, are pinned loosely.
  • Nothing here turns the review on in production, and run-pr-review.yml is not yet in nemarDatasets/.github.

Verification on this head: typecheck and Biome clean on the changed files; bun run migrations:d1-check applies all 97 migrations on real D1 and the catalog matches bun:sqlite; backend pr-review-start, pr-review-flow and pr-review-queue 270 pass; CLI start and admin-pr-reviews suites, the admin route inventory, both export-surface pins, the ADR index and the changelog format 178 pass.


Generated by Claude Code

@neuromechanist
neuromechanist merged commit 39193d7 into dev Oct 10, 2026
14 checks passed
@neuromechanist
neuromechanist deleted the feature/pr-review-start branch October 10, 2026 20:05
@neuromechanist neuromechanist mentioned this pull request Oct 10, 2026
8 of 9 tasks

This branch was previously deployed

1 inactive deployment
npm — bb0bc82e Deployed Oct 10, 2026 by neuromechanist via publish #3347
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants