Skip to content

ci(review): review pull requests and post findings as an advisory comment - #182

Draft
dg-dayhaysoos wants to merge 3 commits into
chore/agent-review-baselinefrom
ci/review-workflow
Draft

dg-dayhaysoos wants to merge 3 commits into
chore/agent-review-baselinefrom
ci/review-workflow

Conversation

@dg-dayhaysoos

Copy link
Copy Markdown

Summary

Adds an automated review of pull requests. Two model passes read a PR against REVIEW.md, and the findings that hold up are posted as one advisory comment. It does not approve, block, label or set a status, and it is not a required check.

Stacked on #181, which adds REVIEW.md and AGENTS.md. Merge that first.

The workflow does nothing on this PR. It reads its rules, prompts and script from the base branch, and they are not there yet, so it skips with a notice. The first PR opened after this merges is the first one reviewed.

Changes

  • .github/workflows/review.yml, in two jobs:
    • review prepares the PR, runs a find pass and a verify pass with anthropics/claude-code-action, and keeps review/report.json as an artifact. Permissions: contents: read, pull-requests: read.
    • comment posts the confirmed findings as one comment and replaces it on a later run. Permissions: pull-requests: write. It runs no action, no checkout and no model.
  • scripts/review_pr.py (stdlib only): everything around the model. It writes the PR's files as data, checks the form of each finding and verdict, builds the report, and renders the comment.
  • .github/prompts/review-find.md, review-verify.md: the two passes' instructions. The second pass tries to disprove each finding of the first.
  • docs/contracts/review-*.schema.json: the shape of the model's answers and of the report.
  • tests/unit/test_review_pr.py: 102 tests, none of which calls a model. They hold the script and the workflow's safety properties.
  • tests/review/: four past changes to replay the reviewer on, three with a bug a later commit fixed, and how to run them.

For reviewers

  • Permissions. This adds a workflow with pull-requests: write, on the comment job only. The job that reads PR content and runs the model cannot write. Please check that split.
  • When it runs. On opened, ready_for_review and reopened, or by hand with a PR number. Never for a fork (the job holds the API key), and not for drafts, bots or release-please PRs. It does not run again on each push.
  • What is posted. Only findings the second pass confirmed, that are well formed, and that are about the change. Refuted, unclear and unchecked findings, and findings about code the PR did not touch, stay in the report.
  • The report is public. Anyone signed in to GitHub can download a run's artifact, and it can hold findings that were not posted.
  • No size limit. A PR of any size is reviewed. The report says how much of the change the first pass read, counted from its file reads, and marks a partial review as incomplete.
  • Cost. It uses the repository's existing ANTHROPIC_API_KEY secret and claude-fable-5-2; set the REVIEW_MODEL variable to use another model. Measured locally, first pass only: $4.20 for an 847-line change, $13.06 for a 6,180-line one. An earlier run of both passes on the 847-line change cost $6.74.
  • Rules come from the base branch, so a PR cannot rewrite the brief of its own review. review.yml itself is the exception: on pull_request, GitHub runs the workflow as the PR has it.

Test plan

  • make verify passes locally (macOS, Python 3.14), including the full test suite
  • Both passes run through the local claude CLI with the workflow's flags on a past change with a known bug: the bug was found as a blocker and confirmed
  • The posting step run against a stand-in for gh: it posts when there is no earlier comment, replaces one when there is, and refuses a PR number that is not a number
  • The workflow on GitHub. It has never run there, and cannot until it is on main
  • That the action's log has the format the read count expects. If it does not, the report says "not measured"; the review itself is unaffected

Risk

Low for the product: nothing in a shipped package changes.

For the repository: a new workflow that spends API credit on each PR from a branch of this repository, and that comments under the github-actions name. A wrong finding costs an author's time. A failure of the model does not fail the PR.

How to revert

Reverting this PR removes the reviewer. Comments it has posted stay on their PRs. Nothing here is released to users.

Related issues

Stacked on #181.

🤖 Generated with Claude Code

Nick DeJesus and others added 3 commits December 4, 2026 15:22
A new workflow reviews each pull request against REVIEW.md with two model
passes: one finds problems, the other, with a fresh context, tries to
disprove each finding. This first version only observes. It posts no
comment, review, label or status; what the passes return is kept in the
run's review/report.json artifact, to be compared with what people did
with the pull request before the reviewer is given a voice.

scripts/review_pr.py is everything around the model: it decides whether a
pull request is reviewed, writes what the agents read, checks the form of
what they return, and joins it into the report. The model's answers are
never trusted on their form. A finding that cites a rule REVIEW.md does
not define, or a file or line that is not in the pull request, is kept
with the fault named and does not count as standing.

What the workflow holds to, each with a test in tests/unit/test_review_pr.py:

- The rules, prompts and script are read from the base commit. The
  workflow file itself is the exception on a pull_request event.
- Nothing from the pull request is run. Its files are written from git
  objects as data, without symbolic links. The agents can read and search
  inside the workspace and have no shell, network or GitHub tool.
- The job has read permission only, and never runs for a fork.
- No expression is pasted into a shell command, and the API key reaches
  only the two model steps.
- A model failure does not fail the job. The check is not required.

tests/review/ records the past changes the reviewer was tried on, with the
bug each one introduced, and how to replay them.

Not exercised: the workflow itself. It needs to be on the base branch, with
REVIEW.md, before a run has anything to review with. The script, prompts,
schemas and model arguments were run together through the local CLI on one
replay case.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The reviewer skipped a pull request over 5,000 changed lines and gave each
pass 80 turns and 20 minutes. None of those numbers came from a measurement,
and 7 of the 359 changes on main are over 5,000 lines, the two largest
releases among them.

The limits are gone. In their place the report says what the first pass
read, counted from its Read calls and their results in the tool log and not
from what it says: changed lines seen, added lines read in their files under
pr/, the files it did not open or read only in part, and how many times its
context was replaced by a summary. The run summary shows the same and marks
a partial review as incomplete. The find prompt now asks for the whole diff
and every changed file.

Measured with the first pass on two changes (tests/review/cases.json):
847 lines, all read, 46 turns, $4.20; 6,180 lines, all read, 101 turns,
18 minutes, $13.06, with one compaction half way through. The old turn limit
would have ended the second run before it finished reading.

This changes tests on purpose. The test that a change over the limit is
skipped is replaced by one that a 20,000-line change is prepared, and the
test that a model step times out within 30 minutes now asks only that it has
a timeout, which is there to stop a hung run.

`findings` and `verdicts` take --log, so a replay reads the answer from the
same log the coverage comes from.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The reviewer ran in observe mode: it kept a report and posted nothing, so
nobody saw a review. It now comments.

A second job, `comment`, posts the findings the second pass confirmed as one
comment on the pull request, and replaces that comment when the review runs
again. The comment says it is advice and that a person decides. It does not
approve, request changes, label or set a status, and the workflow is still
not a required check.

The two halves of a review do not share a job. `review` reads the pull
request and runs the models with `contents: read` and `pull-requests: read`,
as before. `comment` has `pull-requests: write` and nothing else: no action,
no checkout, no secret, no model. It takes one string from `review` and
sends it as the body of a comment.

Not posted, and kept in the report: a finding that was refuted, unclear or
not checked, one with a made-up rule or line, and one about code the pull
request did not touch. Text from the model cannot mention a person or team
or open an HTML comment, each field is cut at 2,000 characters, and the
whole comment stays under GitHub's limit.

This adds `pull-requests: write` to a workflow, on the new job only.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

allowed_non_write_users detected

This PR adds or modifies allowed_non_write_users, which allows users without write access to trigger Claude Code Action workflows. This can introduce security risks.

If this is a new flow, please make sure you actually need allowed_non_write_users. If you are editing an existing workflow, double check that you are not adding new Claude permissions which might lead to a vulnerability.

See existing workflows in this repo for safe usage examples, or contact the AppSec team.

@dg-dayhaysoos

Copy link
Copy Markdown
Author

The allowed_non_write_users notice above is a false alarm for this PR.

The check looks for that text on any added line. The one match is in tests/unit/test_review_pr.py, in a test that asserts the review workflow never uses the setting:

assert "allowed_non_write_users" not in text and "allowed_bots" not in text

.github/workflows/review.yml contains neither allowed_non_write_users nor allowed_bots. Only people who can push a branch to this repository can trigger it, and it does not run for pull requests from forks.

This branch has not been deployed

No deployments
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