Skip to content

[ci] The @claude review draws one image of the change - #6239

Draft
felipemello1 wants to merge 6 commits into
pytorch:mainfrom
felipemello1:felipemello1/pr-image-review
Draft

felipemello1 wants to merge 6 commits into
pytorch:mainfrom
felipemello1:felipemello1/pr-image-review

Conversation

@felipemello1

@felipemello1 felipemello1 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary (human-written)

Agent details

TLDR: On the first @claude review of 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 new pr-image skill: 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.

main:     @claude review -> pr-review -> text review
this PR:  @claude review -> pr-review -> Steps 1-6: the review text, written to review_body.md
                                      -> Step 7:   pr-image: 6 sketches, the top 2 drawn as HTML, one picked
                                                   render_html.py renders; Claude checks the PNG against the diff
                                                   render_html.py --upload -> URL -> ![alt](url) in the review
                                      -> Step 8:   post

Problem

  1. The review explains a PR in 2-4 sentences and a text example.
  2. Many changes are easier to see than to read: a race, a memory layout, which requests hit a cache.
  3. The bot can't post an image today. It may run gh commands, 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 strips data: image URLs and inline <svg> from comments.

Solution

  1. .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.
  2. render_html.py renders 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 under review-logs/claude-code/<repo>/<pr>/images/.
  3. pr-review: Step 6 writes the review text to review_body.md first, so drawing never shapes it. Step 7 decides when to draw, loads pr-image only then, uploads the pick and adds ![alt](url) and <!-- pr-image drawn at <sha> -->. Step 8 posts.
  4. claude-code.yml: python-version: "3.12" and a setup_script that installs Pillow and copies render_html.py to /tmp/pr-image/. One new allow rule: Bash(python3 -I /tmp/pr-image/render_html.py:*).
  5. No image for a question, "review my review", a ghstack PR, or a PR where nothing runs differently. A failed render or upload posts the review without the image, with one line under "Not verified": "No image: ". The review text is unchanged otherwise.

Security

  • The renderer Claude runs is the default branch's copy. setup_script installs 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.
  • The page can't read local files or reach the network:
    1. Chrome loads it as a data: URL, so file:// iframes and images stay blank.
    2. A Content-Security-Policy tag allows only inline styles and scripts, and data: images and fonts.
    3. Chrome resolves no host names and sends no WebRTC UDP packets. This also stops navigations and STUN requests, which the CSP doesn't cover.
    4. Chrome's env has only PATH and an empty HOME.
  • Symlinks a PR plants: the input must resolve to a regular .html file, and both output PNGs are deleted before they are written.
  • The upload's bucket, prefix and key shape are fixed in the script. It uploads only its own fresh render, and runs aws with an empty HOME, so no ~/.aws/cli/alias can turn s3 cp into another command.
  • setup_script can't fail the job: without the renderer, reviews post without images.
  • An image is one more public channel, and the action redacts secrets only from text. Claude can already post text.

Results

Renderer, on CPU (Chrome for Testing 156 headless shell, arm64):

data: URL + CSP vs a file:// render of the same page   3/3 shipped examples pixel-equal (22/22 of the source set)
full Chromium found on PATH vs headless shell          pixel-equal
page with a local-file iframe                          iframe blank
hostname image, IP-literal image and fetch             blocked; the CSP logged img-src and connect-src
WebRTC STUN / TURN-over-UDP to a local listener        no packet (20-byte packets without the WebRTC flag)
x.html -> /proc/self/environ, notes.txt, Lock.Lane.html  refused before rendering
symlink planted at lanes.png                           replaced, its target unchanged
Chrome that fails to start                             "Chrome exited with 127: ... libnss3.so", no page text
--upload after an HTML edit                            refused
--upload with a fake aws                               review-logs/claude-code/pytorch/torchtitan/6181/images/
                                                       44437007501_2_lanes.png, --content-type image/png
--upload with the real aws and a planted CLI alias     the alias is ignored; s3 cp runs
setup_script with a failing pip, bash -e               prints "pr-image setup failed ...", exit 0

Permissions, local Claude Code 2.1.327 with this PR's allow rules and no extra settings:

Edit /tmp/pr-image/render_html.py                      denied
write through pr_image/x.html -> the renderer          refused: "it is a symbolic link"
write through a folder link to /tmp/pr-image           denied: "resolves through a symlink ... outside"
python ..., the checkout's copy, "... && curl ..."     denied
GITHUB_RUN_ATTEMPT=7 python3 -I ..., env VAR=x ...     denied
python3 -I /tmp/pr-image/render_html.py pr_image/x.html  allowed

Dry runs of the Actions path, @claude review on 5 merged PRs (fake aws, nothing posted):

PR     expected   result                                                 whole review
this PR's flow (review text first, 2 drawings):
5274   image      2 drawn, 1 uploaded (stage columns, list vs numpy)     5.9 min
5332   none       no image, no line (test-only change)                   0.8 min
earlier version (1 drawing, drawn before the review text):
5298   image      image uploaded (lock lanes, 0.6.0 vs 0.7.0)            3.3 min
5271   image      image uploaded (top-2 cutoff bars)                     6.6 min
5274   image      image uploaded (list vs numpy cells)                   5.1 min
5290   image      image uploaded (GC heap cells)                         5.4 min

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.md before 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:

  • Why not Mermaid in the review text? It needs no upload, but Claude can't preview it (a syntax error shows as an error box), and it can't draw to-scale cells or hatched waits.
  • Why the run-log prefix? The workflow's AWS role already writes run logs there, and the prefix is public.
  • Why not upload in a test-infra step after Claude? Those steps run after Claude exits, but the review needs the URL before it is posted.
  • Why 2 drawings and a pick, not 3? Drawing is the slow part. When we drew 3 per PR, the drawer's own pick matched blind reviewers' choice about as often as the image it listed first (33 vs 32 of 50 PRs). Two keeps one alternative to compare, for less time.
  • Why sketch in text first? A sketch costs a paragraph. It drops forms that don't show the cause before any drawing time is spent.

NOTE:

  • This PR can't test itself: an issue_comment run uses the default branch's workflow and .claude/. The dry runs above stand in until it merges.
  • Not checked on the runner: the sudo line in setup_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.
  • Chrome runs with --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.
  • WebRTC over TCP (TURN) is untested: no probe got Chrome to open such a connection, even with no flags.
  • ghstack PRs get no image, because Write is disabled there. TODO in pr-review Step 7.
  • The S3 bucket belongs to pytorch/test-infra. They get a note before this leaves draft.

Test plan

cd "$(mktemp -d)" && cp <repo>/.claude/skills/pr-image/examples/*.html .
python3 -I <repo>/.claude/skills/pr-image/scripts/render_html.py 5918_rows_text.html   # look at 5918_rows_text_900px.png
cd <repo> && pre-commit run --files .claude/skills/pr-image/scripts/render_html.py .github/workflows/claude-code.yml

@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: @claude review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 19, 2026
@claude

claude Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @felipemello1's task in 4m 39s —— View job


Verdict: Needs discussion -- review

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ![alt](url) and <!-- pr-image drawn at <sha> -->
next review, image's main claim still true -> no image, no line

Must fix

  1. 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.
  2. .claude/skills/pr-image/SKILL.md:46 -- in local mode, the agent edits the PR body without approval (also §5 and references/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's execution_log_s3_prefix with nothing tying them together.
  • .github/workflows/claude-code.yml:33 -- the system Python plus apt-get install python3-pil might replace python-version and the chown -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 of render_html.py, the hardcoded bucket and prefix, and the setup_script/chown lines 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-version and setup_script are 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 and aws, so the chown -R of the Python prefix doesn't break them. The runner is ubuntu-latest, which is ephemeral.
  • render_html.py: the name check, symlink resolution, unlink before write, the --upload cwd check, the re-render compare, the env with only PATH and an empty HOME for Chrome and aws, and the 120 KiB argv cap all look right. No line-level bugs found.
  • pr-review Step 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.

Comment on lines +46 to +47
## 2. Pick the form before drawing

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +33 to +39
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"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Felipe Mello added 2 commits November 18, 2026 22:00
…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.

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

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant