Repository navigation
ci(review): review pull requests and post findings as an advisory comment - #182
dg-dayhaysoos wants to merge 3 commits into
Conversation
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>
|
This PR adds or modifies If this is a new flow, please make sure you actually need See existing workflows in this repo for safe usage examples, or contact the AppSec team. |
|
The The check looks for that text on any added line. The one match is in assert "allowed_non_write_users" not in text and "allowed_bots" not in text
|
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.mdandAGENTS.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:reviewprepares the PR, runs a find pass and a verify pass withanthropics/claude-code-action, and keepsreview/report.jsonas an artifact. Permissions:contents: read,pull-requests: read.commentposts 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
pull-requests: write, on thecommentjob only. The job that reads PR content and runs the model cannot write. Please check that split.opened,ready_for_reviewandreopened, 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.ANTHROPIC_API_KEYsecret andclaude-fable-5-2; set theREVIEW_MODELvariable 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.review.ymlitself is the exception: onpull_request, GitHub runs the workflow as the PR has it.Test plan
make verifypasses locally (macOS, Python 3.14), including the full test suiteclaudeCLI with the workflow's flags on a past change with a known bug: the bug was found as a blocker and confirmedgh: it posts when there is no earlier comment, replaces one when there is, and refuses a PR number that is not a numbermainRisk
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-actionsname. 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