Skip to content

Add --concurrency to nemar admin pr-reviews start - #1929

Merged
neuromechanist merged 7 commits into
devfrom
feature/pr-review-start-pace
Oct 24, 2026
Merged

neuromechanist merged 7 commits into
devfrom
feature/pr-review-start-pace

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1926.

nemar admin pr-reviews start --all [--redo] --concurrency <n> keeps at most n of the reviews the run started in progress at once. A bulk start began every review together, and each review reserves its whole output budget (128,000 tokens) against the workspace's output-tokens-per-minute limit when its request begins (ADR 0107, Consequences), so about a hundred starts asked for a hundred budgets at once and queued a hundred jobs in one repository. It is a sliding window, not fixed batches: the next review starts as each one reports, so one slow review (a truncating one runs up to half an hour) does not hold up the other slots.

How it works, CLI only (no Worker, migration, workflow or wrangler change): while the window is full the command waits 30 seconds and reads the admin list with verdict=in_progress (one request that answers for every pull request); a started review counts as running while it is in that list. Leaving the list is not proof of finishing (a pull request that is closed or merged, or that GitHub's search leaves out for a moment, drops out while its job runs), so a review that left it is confirmed finished by a read of its stored review before its slot is freed, and no slot is held for more than 100 minutes (the Worker calls a review overdue after 90). A start that failed with a connection error or a 5xx may have reached the Worker, so it takes a slot until the queue shows otherwise. An incomplete list or a failed request cannot tell what finished, so it is never taken as finished: the window stays full, each such read prints a dim line, and ten in a row (about five minutes) stop the run. A start that is declined (a blocked contributor, an exempt author, review_running) takes no slot. Only the reviews this run started are counted, not the ones contributors' pushes started. The administrator picks n from the workspace's limit (n x 128,000 must fit it); the CLI does not read or guess that limit.

Ctrl-C ends any --all run, paced or not: it stops after the request in flight, lists the pull requests never started (as nemar admin pr-reviews start <dataset> <pr> --redo commands for a redo, because a rerun of --all --redo would redo the finished ones again) and any start that failed, and exits 130; a second Ctrl-C leaves at once, and one keypress delivered twice counts once. The same list is printed when the reads fail (exit 1). Reviews already started keep running. --dry-run shows the plan, --json carries concurrency, stopped_by and not_started, the confirmation question says "At most N run at once", and above ten starts at once without the flag the list ends with a hint. The unpaced run now goes through the same scheduler with no limit, so Ctrl-C ends it gracefully too. NEMAR_PR_REVIEWS_POLL_MS (default 30000) is read by the command so tests do not wait 30 seconds.

Tests: test/pr-review-pace.unit.test.ts runs the scheduler on a simulated pool of jobs with a virtual clock and checks the limit at every start (a sliding window, declined answers take no slot, a throwing start is recorded, unreadable reads never count as finished and three in a row stop the run, Ctrl-C in a wait and in a start, stopAfter); test/admin-pr-reviews-start-cli.test.ts drives the real CLI against the real router while the test plays the jobs finishing and samples the number of reviews in progress (never above the limit, and the limit is reached), a paced redo, the SIGINT paths (with and without --redo), a front that fails the list read, a list GitHub cut short, the argument checks before the API is asked, the dry run, the JSON, the hint at 10 and 11, and the help. Eleven mutations (six of the scheduler, five of the wiring) were each turned red by a named test; one survivor, an incomplete list taken as complete, got its own test. Not in this PR: the runbook for the whole pr-reviews command group goes to nemarOrg/docs, and nothing deploys until the next release (this ships with --redo).

runPaced keeps at most n of the reviews a run started in progress, starting the next as each leaves in_progress. A read that cannot tell is never taken as finished, and three in a row stop the run. Ctrl-C ends a wait at once and reports what was never tried. Tested on a simulated pool with a virtual clock, with six mutations.
start --all [--redo] --concurrency n keeps at most n of the reviews the run started in progress, reading the admin list every 30 seconds while it waits. Ctrl-C and three unreadable lists in a row stop the run and list what was never started (as commands for a redo). The unpaced run goes through the same scheduler with no limit. Hint above ten starts at once, plan in --dry-run, concurrency and not_started in the JSON. Tested through the real CLI against the real router with jobs finishing during the run, and with five mutations.
Amendment for start --all --concurrency and the pointer from ADR 0107's note on the output-tokens-per-minute limit. Docs only.
Review fixes for the scheduler: a review that leaves the in-progress list is confirmed finished before its slot is freed (a closed pull request or a lagging search also drops out), a start that may have reached the Worker takes a slot, a slot is held at most 100 minutes, a read in flight no longer holds Ctrl-C, and Ctrl-C during the last unreadable read ends as interrupted. Tests with four more mutations.
A second Ctrl-C leaves at once and the first says so, one keypress delivered twice counts once, ten unreadable reads (about five minutes) stop the run with a dim line for each, a failed start is listed to be checked, the redo continuation says to run the commands by name, and no markReportedExit before exit 130. Tests for a closed pull request, a hanging list read, a hanging start (paced and unpaced), the unreadable branch and the 128,000 figure.
The overdue time is 90 minutes, not 60; leaving the list is confirmed; the unpaced run's Ctrl-C and JSON change are named; ten unreadable reads; the second amendment is named in ADR 0107. Docs only.
@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review round 1 (Sonnet): no Critical findings; the invariant (never more than n of this run's reviews in progress) held in every scenario the reviewer built. Everything is resolved in 1d0ae24, a1625aa and 47bf94e, pushed once.

Fixed: (I1) Ctrl-C was dead during a hanging read and a second Ctrl-C did nothing: the read and the confirmation are now raced against the abort, Ctrl-C during the read that would have been the last unreadable one ends as interrupted, the first Ctrl-C prints that it stops after the request in flight and the second leaves at once (one keypress delivered twice within half a second counts once, which a test found); (I2) the overdue time is 90 minutes (60 plus 30 of grace), not 60, in the ADR and here; (I3) the ADR and the help said nothing changes without the flag, while every --all run now ends on Ctrl-C and its JSON can carry stopped_by and not_started; (S4) absence from the in-progress list counted as finished although a closed pull request or a lagging search drops out of it with the job still running: a departed review is confirmed by a read of its stored review before its slot is freed, a read that fails keeps the slot, and a slot is freed after 100 minutes whatever happens so no wait is without end; (S5) a start that threw takes a slot when it may have reached the Worker (a connection error or a 5xx); (S6) three unreadable reads were about 90 seconds of tolerance, now ten (about five minutes), each prints a dim line, and the message says "completely"; (S7) the interrupted redo list now names the failed starts to check and says to run the commands by name; (S8) tests for the skipped.unreadable branch, a read that never answers, a start that never answers (paced and unpaced, second Ctrl-C), a closed pull request, and abort during a confirmation; (S9) the job-playing timers are stopped in afterEach and the Ctrl-C tests no longer assert before they kill; (S10) the ADR 0107 pointer names the second amendment, a test pins the 128,000 in the help to REVIEW_MAX_TOKENS, the poll knob takes at least 10 ms, the redundant markReportedExit before exit 130 is gone, and the JSON carries an empty not_started when the limit is set and nothing starts.

The uncommitted edit the reviewer saw in pr-review-pace.ts (recording the result outside the try) is committed. Eight more mutations (hold limit, ambiguous start, abortable read, confirmation, unreadable branch, the limit of ten, the second Ctrl-C, no confirmation) are each turned red by a named test.

Round 2 (delta only) is next, then merge when CI is green.

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR1929

Version: 0.10.24-PR1929.a454225
Commit: a454225


🤖 Updated on each push.

Round 2 fixes: a start whose connection or response failed (status 0) may have begun the review and takes a slot; the confirmation names the commit the run started so an unreadable GitHub or a moved head no longer reads as finished; both reads are bounded at two minutes; a second Ctrl-C says which start was in flight. The tests observe the front instead of sleeping, kill every child they launch, and cover the dropped response, the unbounded read and the moved head. ADR 0093 follows.
@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review round 2 (Sonnet, delta only): no Critical findings and two Important ones that let more than n reviews run, both real and reproduced, both fixed in the latest commit and pushed once; no third round.

Fixed: (Important 1) a start that died on the connection or whose response could not be read is an ApiError with status 0, which the classifier took for a definite refusal, so the slot stayed free and a second review started: only a 4xx now counts as a refusal, and a test cuts the response after the Worker began the review and checks the slot is held; (Important 2) the confirmation read the pull request's current head and not the commit the run started, so an unreadable GitHub or a head that moved on read as "not reviewed" and freed the slot: it now names the commit, and the tests cover a closed pull request, an unreadable GitHub and a head that moved to a commit whose own review had finished (the last one is what makes the named commit matter; a mutation without it fails); (Suggestions) a second Ctrl-C says which start was in flight; both reads are bounded at two minutes (NEMAR_PR_REVIEWS_READ_TIMEOUT_MS for tests) and a read that never answers counts as unreadable; the tests wait for the front's hit instead of sleeping and every child is killed in afterEach; ADR 0093 follows.

Not changed, by design: the 500 ms debounce also swallows a deliberate second Ctrl-C pressed within half a second of the first (acceptable: a second press after reading the message takes longer).

@neuromechanist
neuromechanist merged commit 377e67d into dev Oct 24, 2026
14 checks passed
@neuromechanist
neuromechanist deleted the feature/pr-review-start-pace branch October 24, 2026 10:29

This branch was previously deployed

1 inactive deployment
npm — a4542251 Deployed Oct 24, 2026 by neuromechanist via publish #3869
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.

1 participant