Repository navigation
[ci] The @claude review draws one image of the change - #6239
felipemello1 wants to merge 6 commits into
Conversation
…w only on a major change
… before installing the renderer
|
Reply from claude: @claude review |
|
Claude finished @felipemello1's task in 4m 39s —— View job Verdict: Needs discussion -- review |
There was a problem hiding this comment.
Verdict: Needs discussion -- the review bot would upload to pytorch/test-infra's public bucket from inside Claude's step, using a bucket, prefix and setup hack that torchtitan hardcodes. Test-infra hasn't agreed yet, and maintainers need to decide whether the extra review time is worth it.
What this PR does. The first @claude review of a PR, and any later one after a major change, adds a PNG of the change under "What this PR does". Claude writes an HTML page. A root-owned copy of render_html.py from the default branch renders it with headless Chrome: no network, no file access, a CSP added to the page. A fresh sub-agent checks the image against the diff. --upload renders the page again, checks that the result is pixel-equal to the PNG Claude checked, and copies it to s3://ossci-raw-job-status/review-logs/claude-code/<repo>/<pr>/images/. A new pr-image skill holds the drawing rules, plus a local mode for drawing PR-description images.
Example.
@claude review on a PR, first review
main: review = verdict + "What this PR does" (text) + Example (text)
this PR: Step 4b: Claude writes pr_image/lanes.html
python3 -I /tmp/pr-image/render_html.py pr_image/lanes.html -> lanes.png, lanes_900px.png
Step 5: a sub-agent checks lanes_900px.png against the diff
python3 -I /tmp/pr-image/render_html.py pr_image/lanes.html --upload -> https://ossci-raw-job-status.s3.amazonaws.com/
review-logs/claude-code/pytorch/torchtitan/<pr>/images/<run>_<attempt>_lanes.png
review body gains  and <!-- pr-image drawn at <sha> -->
next review, image's main claim still true -> no image, no line
Must fix
- PR description: "Summary (human-written)" is empty. Per CLAUDE.md, the author writes it: what problem reviewers have today, and why an image is worth a 2x longer review.
.claude/skills/pr-image/SKILL.md:46-- in local mode, the agent edits the PR body without approval (also §5 andreferences/facts.md:27). This conflicts with CLAUDE.md's rule that agents edit PRs only after the user approves the exact content.
Should consider
.claude/skills/pr-image/scripts/render_html.py:66-- bucket and prefix copy test-infra'sexecution_log_s3_prefixwith nothing tying them together..github/workflows/claude-code.yml:33-- the system Python plusapt-get install python3-pilmight replacepython-versionand thechown -R(unverified).- Scope: the local mode (SKETCHES.md, six sketches, matplotlib and graphviz, editing the PR body) is a second feature. Nothing in the repo calls it, and the title is about the review bot. Splitting it out would shrink this PR to the Actions path.
Questions
- Ownership (for maintainers and test-infra): should the renderer and uploader be an opt-in input on test-infra's
_claude-code.yml, installed root-owned in its own setup step? That would remove the upload half ofrender_html.py, the hardcoded bucket and prefix, and thesetup_script/chownlines from torchtitan. Test-infra would own the security of a channel that writes to their bucket, and other repos would get it too. The "URL needed before the review posts" argument rules out a post-step, but not a tool test-infra installs before Claude runs. - Cost: the dry runs took 3.3-6.6 min per review, against a 2.75 min median today, plus a sub-agent on every drawn image. Is there evidence that images help reviewers decide? The 33-vs-32 result compares picks among drawings, not image vs no image.
- Does the
review-logs/prefix have a lifecycle rule? If images expire, old reviews show broken images.
Details
- Checked against test-infra
_claude-code.yml(#7810, #8381, #9498).python-versionandsetup_scriptare real inputs. Step order is checkout (default branch) -> setup-python -> setup_script -> AWS OIDC -> Claude, so the renderer is copied from the default branch before the action checks out the PR. The AWS credentials are already in Claude's env. The later steps (usage metrics, execution log) use only bash, jq andaws, so thechown -Rof the Python prefix doesn't break them. The runner isubuntu-latest, which is ephemeral. render_html.py: the name check, symlink resolution, unlink before write, the--uploadcwd check, the re-render compare, the env with only PATH and an empty HOME for Chrome andaws, and the 120 KiB argv cap all look right. No line-level bugs found.pr-reviewStep 4b/5/6 changes are consistent with the existing Output Format and with "What was asked".
Not verified: Chrome, fonts, sudo and Pillow 13.0.0 on the runner, and the apt alternative. This run used the default branch's pr-review, so it couldn't exercise Step 4b.
| ## 2. Pick the form before drawing | ||
|
|
There was a problem hiding this comment.
The local mode tells the agent to edit the PR body on its own. This line says "Locally, fix the body in the same change (§5)". §5 (lines 153-155) adds "Body edits start from the live body" and has the agent update the "drawn at" sha after a push. references/facts.md:27 says "fix the body in the same change". .claude/CLAUDE.md (PR Expectations 2) says: "Agents don't open, edit, or comment on GitHub issues and PRs unless the user approved the exact content."
As written, a local /pr-image run would rewrite part of the description without showing it to the author first. Fix: in all three places, have the agent propose the exact body edit and apply it only after the person approves that text.
There was a problem hiding this comment.
Reply from claude: Fixed in 30476cb. The skill never edits the PR body now. The image goes only in Claude's own message: this review on GitHub, the reply in a local session. A body line the code contradicts, or a probe that disagrees with the body, is named in that message instead (§1, §5, references/facts.md).
| # Linux caps one command-line argument at 128 KiB, and Chrome gets the page as one. | ||
| MAX_PAGE_URL_BYTES = 120 * 1024 | ||
|
|
||
| BUCKET = "ossci-raw-job-status" |
There was a problem hiding this comment.
The bucket here and the review-logs/claude-code/ prefix at line 228 copy values that test-infra's _claude-code.yml owns. The bucket is hardcoded in its "Upload Claude execution log" step. The prefix is its execution_log_s3_prefix input, default review-logs/claude-code. If test-infra moves the prefix or changes the role's write policy, image uploads fail or land somewhere else, with nothing in torchtitan to show why.
This is the code-level side of the ownership question in the review body. If test-infra owns the upload, it can be one opt-in input on their reusable workflow, and these constants and the upload half of this script leave torchtitan. If it stays here, add a comment naming the test-infra input these values must match.
There was a problem hiding this comment.
Reply from claude: Added a PREFIX constant next to BUCKET, with a comment that names test-infra's execution_log_s3_prefix input they must match (2d5fa29). Whether test-infra should own the upload is their call: it goes in the note we send them before this leaves draft.
| python-version: "3.12" | ||
| setup_script: >- | ||
| ( python -m pip install pillow==13.0.0 && | ||
| sudo chown -R root:root "$(python -c 'import sys; print(sys.prefix)')" && | ||
| sudo install -D -o root -g root -m 0644 | ||
| .claude/skills/pr-image/scripts/render_html.py /tmp/pr-image/render_html.py ) || | ||
| echo "pr-image setup failed; reviews post without images" |
There was a problem hiding this comment.
Unverified alternative. The python-version input and chown -R of the whole setup-python prefix exist only to get a root-owned Python that has Pillow. The runner's system /usr/bin/python3 is already root-owned (3.14 on ubuntu-latest, per pytorch/test-infra#9498). -I already ignores ~/.local. So sudo apt-get install -y python3-pil plus the sudo install line might give the same guarantee. It would remove the python-version input, the chown -R and its ordering comment, and the switch of every @claude job to 3.12.
The cost is a distro-pinned Pillow instead of ==13.0.0, and maybe an apt-get update. Worth a try on the runner, if it is cheaper than the current setup.
There was a problem hiding this comment.
Reply from claude: Keeping python-version. ubuntu-latest moved to Ubuntu 26.04 (this run's job log: image ubuntu-26.04), and its system Python went from 3.12 to 3.14. That move is why test-infra added python-version. Pinning the Python keeps pillow==13.0.0 on a known wheel the next time the image moves. The chown -R is the cost of that pin.
…aphs, draw 2 - pr-review: Step 6 writes the review, Step 7 loads pr-image and draws, Step 8 posts. No sub-agent check of the image. - pr-image: never edit the PR body; the image goes in Claude's own message. Sketches are paragraphs of up to 6 lines; draw the top 2 and pick one. - render_html.py: PREFIX constant, and a comment naming the test-infra input it must match.
… two pages The 5298 dry run on the previous commit wrote review_body.md after the upload, read pr-image before Step 7, and drew one page.
Summary (human-written)
Agent details
TLDR: On the first
@claude reviewof a PR, the review shows one image of the change under "What this PR does". A later review draws a new one only after a major change: when the old image's main claim is false, or the PR's main change moved. After writing the review text, Claude draws it as HTML with the newpr-imageskill: 6 text sketches, the top 2 drawn, one picked. A script renders it with headless Chrome and uploads the PNG to the public S3 prefix where the workflow already writes its run logs.Problem
ghcommands, git commits and Claude Code's read-only commands: nothing renders or uploads. GitHub has no documented API to attach a file to a comment, and it stripsdata:image URLs and inline<svg>from comments.Solution
.claude/skills/pr-image/: how to pick a form, draw it as HTML and check each label against the diff. It never edits the PR body: the image goes only in Claude's own message.render_html.pyrenders the page to a 1800 px PNG. With--upload, it renders again, refuses unless the result is pixel-equal to the PNG Claude looked at, and uploads it underreview-logs/claude-code/<repo>/<pr>/images/.pr-review: Step 6 writes the review text toreview_body.mdfirst, so drawing never shapes it. Step 7 decides when to draw, loadspr-imageonly then, uploads the pick and addsand<!-- pr-image drawn at <sha> -->. Step 8 posts.claude-code.yml:python-version: "3.12"and asetup_scriptthat installs Pillow and copiesrender_html.pyto/tmp/pr-image/. One new allow rule:Bash(python3 -I /tmp/pr-image/render_html.py:*).Security
setup_scriptinstalls it root-owned before the action checks out the PR, and chowns setup-python's Python to root. So no file edit can change them, even through a symlink a PR adds.data:URL, sofile://iframes and images stay blank.data:images and fonts.PATHand an emptyHOME..htmlfile, and both output PNGs are deleted before they are written.awswith an emptyHOME, so no~/.aws/cli/aliascan turns3 cpinto another command.setup_scriptcan't fail the job: without the renderer, reviews post without images.Results
Renderer, on CPU (Chrome for Testing 156 headless shell, arm64):
Permissions, local Claude Code 2.1.327 with this PR's allow rules and no extra settings:
Dry runs of the Actions path,
@claude reviewon 5 merged PRs (fakeaws, nothing posted):Times are Claude's whole run with local Claude Code 2.1.327 (Opus 5.5, effort high) on a Linux dev machine. In the 5274 run, Claude wrote
review_body.mdbefore it opened any pr-image file, wrote 6 sketches, drew the top 2 and uploaded only the pick. For loose reference, the bot's last 100 finished jobs took 2.75 min median, over all kinds of requests (gh run list).You may ask:
NOTE:
issue_commentrun uses the default branch's workflow and.claude/. The dry runs above stand in until it merges.sudoline insetup_script, Google Chrome 157 and its fonts, and Claude Code 2.1.280 (the pinned version). A failure there costs the image, not the review.--no-sandbox. Exploiting that needs a Chrome bug that a Claude-written page triggers. Whether the runner's Chrome works without the flag is untested.Test plan