Skip to content

feat: automated review of dataset pull requests (ADR 0092) - #1682

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

neuromechanist merged 10 commits into
devfrom
feature/pr-review

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

What this does

A pull request to main of a dataset repository in nemarDatasets is reviewed automatically by Claude Haiku 5.5 (high effort). The result is a green or red NEMAR PR Review check plus one pull-request comment that says what changed and what the reviewer found. A human still approves and merges.

The review asks three questions:

  1. Is anything lost or broken?
  2. Does the revision advance (version, CHANGES, honest description)?
  3. Is the dataset materially better?

Decision record: .context/decisions/0092-dataset-pull-requests-get-a-derived-verdict-from-a-worker-gated-model-review.md (status: proposed).

How it works

  • The NEMAR GitHub App delivers every pull_request event to the Worker, forks included. The Worker is the gate: it dedupes per commit, applies the contributor tally and rate caps, records the attempt in pr_reviews, and dispatches one central workflow, run-pr-review.yml in nemarDatasets/.github.
  • The workflow claims the review first. The dispatch carries a one-shot token; the Worker accepts it once and refuses a commit that is no longer the pull request's latest. A forged, replayed or stale dispatch stops there, before anything is installed, minted or sent to a model, so the Worker's spend caps are binding.
  • The workflow runs in nemarDatasets, the only place the Anthropic identity (workload identity federation) is minted. It reads the change as git data with init and fetch, never a checkout, so nothing from a pull request can run. A fork is read through refs/pull/N/head on the base repository.
  • The model has no tools. It answers the three questions and returns findings from a closed list. It cannot write the evidence, the version, or a verdict.
  • The Worker validates the report against a closed vocabulary, derives the verdict from the report and from git facts, and publishes the check and the comment. A watchdog marks a review that never reports as needing a person, and publishes again a result that did not reach GitHub.
  • No workflow is added to any dataset repository, so there is no rollout to ~785 repos (ADR 0020).

Behaviour the maintainer asked for

  • Runs automatically when the PR base is main; drafts and bot authors are skipped.
  • Forks from third-party accounts are reviewed the same way.
  • Real pass and fail: pass is a green check, fail is a red check. Anything that is not a clear pass (uncertain, not reviewed, errored, never reported) is action_required, which GitHub does not count as passing for a required check. neutral is deliberately unused because it does count.
  • Contributor tally: reviews pause for a contributor with more than 5 rejected pull requests AND more than 10 percent of their decided pull requests rejected (the later of the two thresholds). A pull request counts once, by its latest decided review, so fixing it clears it. pr_review_overrides lets a maintainer allow or block a contributor outright.
  • Caps: a stranger gets 3 reviews an hour and 6 a day, a collaborator 20 an hour and 100 a day, and the platform 400 a day. They are ranked after the insert, so concurrent deliveries cannot slip under them.
  • Every change is accounted for: exact per-area counts, version and subject change, how much content was read, and a file list. The Worker refuses a report whose areas do not add up to its file total.

Safeguards worth reviewing

  • The verdict is derived (verdictOf), and facts overrule the model: no changed file cannot be an improvement, an unchanged version cannot advance the revision, a truncated list cannot certify that nothing was lost, any removed file needs a person, and a steering attempt fails the review. The parser also makes a report agree with itself in the safe direction: a finding that names a steering attempt sets the flag, and a criterion passed while a blocker is filed against it becomes unknown.
  • Untrusted text sits in a per-run, nonce-fenced block; free text in the report is reduced to plain words (no links, mentions, HTML, emphasis), and only the start of a long note is ever processed.
  • The callback token is masked by the first step, before anything can print it (this repository's logs are public), and is never in job-level env. A job that fails after the claim reports through a dependency-free curl step.
  • The workflow's payload fields reach the shell only through env, are validated, and are cross-checked against GitHub's own record of the PR (open, targets main, still at head_sha).
  • The model step has the federated identity and the one-shot callback token in its environment and no GitHub credential in it. The read-only GitHub token (one repository, contents and pull requests) is passed to the two steps that read the repository; the fetch step also leaves it in the clone's git config, because the clone is blob-less and the model step's git reads fetch blobs lazily. This is stated in the workflow header and the ADR.
  • The callback token is domain-separated from the pre-screen and identifier-screen tokens.
  • The review is off unless PR_REVIEW_ENABLED is exactly 1. The watchdog is production-only and ignores the flag, so switching the review off never strands a check that is already running.

Review

The change went through two rounds of the pr-review-toolkit (code review, silent-failure audit, test-coverage review with mutation testing, type design, comment accuracy, simplification). The findings and what was done with each are in the review comment below.

Verification

  • bun run typecheck and Biome on the changed files are clean.
  • Tests are all real: real git repositories, real SQLite migrations, real HMAC, the workflow's bash steps run for real, the real Anthropic SDK against an HTTP stand-in, and a stand-in for api.github.com. No mocks. They cover the contract, the evidence reader and job script including main() end to end, the workflow's structure and shell steps, and the Worker flow through the real routes with fault injection.
  • Mutation testing in the dangerous direction was run on the contract, the Worker and the workflow, and the survivors from the independent coverage review were closed.
  • The full backend suite on this branch and on a clean checkout of the base commit fail the same tests (six manifest-canary tests; a large-manifest memory test is flaky on both). The root suite fails the same 248 annex and fleet tests on this branch and on a clean base, because git-annex is not installed in this sandbox; none touch this change.

Not verified

  • The live call to the model and the real workload identity exchange were not run (no federated identity in the build environment). The request the job sends (model, effort, schema, no tools) and the reading of each stop reason are tested against the real SDK and a local stand-in.
  • run-pr-review.yml has not run on GitHub. Its shell steps are executed in tests, but GitHub's behaviour is not: for example, whether Actions masks the token in step headers as designed, whether the App can create a check against a fork's head commit (the existing BIDS check does the same), and how long a GitHub OIDC token lives against a long review.

Before it is switched on (also in the ADR)

  1. Subscribe the NEMAR App to Pull request events and grant Pull requests: write (needed only for the comment; the check works without it).
  2. Set four organization variables on nemarDatasets: ANTHROPIC_FEDERATION_RULE_ID, ANTHROPIC_ORGANIZATION_ID, ANTHROPIC_SERVICE_ACCOUNT_ID, ANTHROPIC_WORKSPACE_ID. Check the federation rule accepts only repo:nemarDatasets/.github:ref:refs/heads/main for this workflow.
  3. Deploy run-pr-review.yml to nemarDatasets/.github/.github/workflows/, then add it to the unit-pure sparse checkout with NEMAR_PR_REVIEW_WORKFLOW_LIVE so the parity test stops skipping.
  4. After this reaches production, set PR_REVIEW_ENABLED=1 on the production Worker.

Follow-ups

  • nemar admin command to list and manage all pending pull requests in one place, and to allow or block a contributor (a separate session owns this).
  • Making the check required is a separate decision, to be made once the false-fail rate is known.
  • A review that errored for a setup reason is not repeated for the same commit; a new push re-runs it.
  • Ordering "latest commit" by the payload's updated_at, so a manually redelivered older commit cannot supersede a newer one (accepted risk in the ADR).
  • Descriptive docs for docs.nemar.org (private repo).

Generated by Claude Code

claude added 7 commits October 8, 2026 21:35
Closed-vocabulary report, derived verdict, check words and the contributor tally rule (ADR 0092).
The Worker takes the App's pull_request delivery, applies the contributor tally and rate caps, dispatches the central workflow, and publishes the derived verdict as a check and one comment. Off unless PR_REVIEW_ENABLED is 1 (ADR 0092).
Reads the change as git data, asks Haiku 5.5 at high effort through workload identity federation, and posts a closed-vocabulary report (ADR 0092).
@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR1682

Version: 0.10.16-PR1682.09d38db
Commit: 09d38db


🤖 Updated on each push.

Copy link
Copy Markdown
Contributor Author

Review record (pr-review-toolkit, two rounds)

Six reviewers ran on the full diff: code review, silent-failure audit, test coverage (with mutation testing on copies of the repo), type design, comment accuracy, and simplification. The first round's findings were fixed in the earlier commits on this branch; this record covers the second round, which ran on the result. Each fix has a test, and the important ones were mutation-checked (the test fails when the code is changed in the dangerous direction).

Round two: what was found and what was done

Fixed, security and correctness

Finding Resolution
A report with steering: false and a steering_attempt finding, all criteria pass, derived pass (fail-open on the injection case) The parser sets steering when any finding names a steering attempt; stored reports re-parse to the same value
A blocker finding against a criterion the model also passed derived pass The criterion becomes unknown, so the review needs a person
A failure after the row insert (for example a D1 error in the cap check) left a dispatched row with a live nonce; a redelivery answered duplicate and the watchdog later said "did not finish" Any throw after the insert marks the row errored/dispatch_failed (best effort) and rethrows; handleRepeat already retries that state
A redispatched row kept its old created_at, so the watchdog could call a running review late and the cap windows were wrong The redispatch restarts the clock
The claim step ended green on any non-200, including a 5xx or an unreachable Worker, hiding a review that was waiting Only 401 and 409 end green; anything else is tried three times and then fails the job loudly
The error reporter hid its own failures (`
A job could report the Worker's own dispatch_failed word, which is refunded from the caps and retried The callback maps it to workflow_failed
Concurrency group omitted the environment, so dev and production reviews with the same small id could collide The group is environment plus review id
Exhausted publish retries left a check in_progress with no log The watchdog logs the review and pull request when the last attempt fails, and counts abandoned
report_invalid lost its cause The parser's fixed word is logged with the review id; a stored report that no longer parses is logged, and non-parser errors are no longer swallowed
Removing 200 derivatives and 50 unclassified files could ride on a model's pass Any removed file in any area needs a person
sanitizeNote was quadratic (80k repetitions of [ took 30 s) Input is cut to 8 times the limit before the work begins; lone surrogates from the cut are removed
Evidence fallbacks produced plausible values (commits: [], subjects: null on a failed read) They throw an EvidenceError; its codes are a closed list because the word is printed in a public log
The model step was described as holding no GitHub credential, but the fetch token sits in the clone's git config for lazy blob reads The workflow header, the script header and the ADR now say exactly that; the token is read-only, one repository, an hour at most

Fixed, structure

  • Migration CHECKs now tie detail to state (a declined row holds a decline word, an errored row a run-error word) and require a stored report exactly when the review reported. The "paused" fallback in outcomeOfRow can no longer publish the wrong sentence.
  • isOneOf replaces about ten hand-rolled membership tests and their casts; CallbackOutcome replaces an unreachable 400 branch; PublishResult.comment (write-only) became a boolean; ReviewArgs lost three unread fields; SEMVER and SHA40 are defined once; the unused fail subcommand was removed.
  • About twenty comments were corrected after checking each claim against the code (stale "first act", "marks the row started", the cron-wiring comment about the flag, the webhook docblock, the test titles that carried a PR number or history).

Tests added for what the coverage review showed was unpinned

  • The workflow's fetch step now runs for real against a local git remote; the Review step's arguments are pinned one by one; core.setSecret is pinned as an unconditional statement.
  • main() runs end to end: real git, the real SDK against an HTTP stand-in for the Messages API (request shape, effort, schema, no tools, each stop reason), and a stand-in Worker for the callback. This replaced the injected model function, which was a mock.
  • Stored verdict is the derived one; six concurrent deliveries of one commit dispatch once; kill switch accepts only the word 1; watchdog deadline and settle-time boundaries; exact cap edges (5 of 6 and 6 of 6, 99 of 100, 399 of 400); each of stale_head and dispatch_failed excluded from the allowance separately; the decline message is per pull request; no token, key or secret in the Worker's logs on the mismatch, claim, result and failed-dispatch paths; the reverse direction of token domain separation; hostile severity, nested unknown keys and out-of-range counts in the parser; patch-level version comparison; the check table shows what facts left of an answer; renames are a removal plus an addition; the model-file boundary and the findings cap.

Found and accepted (also in the ADR)

  • A manually redelivered older commit becomes the latest and the newer one's claim is refused; both end as "push again". Fails safe, wastes one review. Ordering by updated_at is a follow-up.
  • A retried check-run create can leave an orphan in-progress check; a repeat decline for a new commit is suppressed without its own check; a claim whose answer was lost is refused on retry. All end as "needs a person" or no check, never a pass, and matter only once the check is required.
  • A new sidecar can override an inherited one under BIDS inheritance and does not mark the evidence incomplete.
  • id-token: write exposes the OIDC request variables to every step of the job, including bun install; the federation rule's conditions (this repository, this workflow, main) bound that.
  • Not done, judged not worth their code: a discriminated PrReviewResponse.reason, nested-ternary-to-record rewrites, and splitting publishOutcome.

Verification

Typecheck and Biome are clean on the changed files. The affected suites pass (contract, evidence and script, workflow, route inventory, ADR index, Worker flow, cron wiring). The full backend suite fails only the six manifest-canary tests that fail identically on a clean dev. The root suite fails the same 248 annex and fleet tests on this branch and on a clean dev (git-annex is not installed in this sandbox); the only differences between the two runs were a large-manifest memory test that is flaky on dev and a timing-budget test that passes alone.

Not verified

The live model call, the real workload identity exchange, and a real GitHub Actions run of run-pr-review.yml. Everything around them is tested; they need the staging steps in the description.


Generated by Claude Code

@neuromechanist
neuromechanist merged commit b92b106 into dev Oct 9, 2026
14 checks passed
@neuromechanist
neuromechanist deleted the feature/pr-review branch October 9, 2026 01:47

This branch was previously deployed

1 inactive deployment
npm — 09d38db2 Deployed Oct 9, 2026 by neuromechanist via publish #3258
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