[ci] hand the review subagents the PR diff as a file - #658
Open
tiankongdeguiji wants to merge 1 commit into
Open
[ci] hand the review subagents the PR diff as a file#658tiankongdeguiji wants to merge 1 commit into
tiankongdeguiji wants to merge 1 commit into
Conversation
The reviewer subagents have Read but no shell, and the PR checkout is fetch-depth: 1, so no local git command can produce the change. Their only view of it came from whatever the dispatcher wrote into their prompts, and since --permission-mode manual denies both shell redirection and Write, the dispatcher could only pass a diff along when `gh pr diff` happened to exceed the harness inline limit and got spilled to disk; on smaller PRs it fell back to paraphrasing, and the agents reviewed HEAD instead of the change. A workflow step now saves the diff to pr.diff in the review checkout before the model starts, so the file always exists and needs no write permission. review-pr.md points the dispatcher at it and states what the subagents can do, and each agent is told to read it first rather than infer the change from HEAD. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013KX52EswZ1UUySg2CN2nEg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The five reviewer subagents are declared
tools: Glob, Grep, Read— no shell — and the PR checkout usesfetch-depth: 1, so there is no merge base on disk for anygit diffto resolve against.gh pr diffis the only source of the change, and it is main-agent-only.That left the subagents' view of the change entirely up to what the dispatcher managed to put in their prompts, and since
facfbd00added--permission-mode manualthe dispatcher can no longer create the file itself: shell redirection is refused (Output redirection to '…' was blocked), andWriteis not in--allowedTools. The one channel still working was accidental — whengh pr diffoutput exceeds the harness inline limit, Claude Code spills it to atool-results/*.txtfile and the dispatcher can pass that path along. Under the limit, the output stays in the dispatcher's context and the subagents get a prose paraphrase instead, so they read files atHEADand infer what is new.The perverse part is the direction: large PRs get the real diff, small ones do not.
Fix
A workflow step saves the diff before the model starts:
The file then exists for every PR at every size, with no write permission involved and no dependence on
--add-dir /or on the dispatcher noticing a persisted-output notice.review-pr.mdpoints the dispatcher atpr.diffand states what the subagents actually have, and each agent carries a one-line**Scope:**paragraph telling it to read the diff first rather than reconstruct the change fromHEAD— so the fix holds even when the dispatcher writes a sloppy prompt.The step runs after
use_trusted_agent_files.sh, sopr.diffstays untracked and the trusted-swap commit is unchanged; it also lands after the PR checkout, so a PR cannot pre-seed the file.Both jobs get the step. The codex job needs it for the same reason and more strictly: its subagents run
sandbox_mode = "read-only"with no network, sogh pr diffis unreachable from inside a review there.Bash(gh pr diff:*)stays in the allowlist as a fallback; the instructions simply stop asking for it.Test Plan
Rehearsed the CI step sequence locally against a shallow clone (
--depth 1), running the realuse_trusted_agent_files.shfollowed by the new step:CLAUDE.mdand a nestedtzrec/.claude/are stripped and replaced, andpr.difflands untracked (?? pr.diff) so the setup commit is unaffected.git diff master...HEADin that checkout still fails withunknown revision, confirming the file is genuinely the only channel available to the reviewers.**Scope:**line.Ran the diff command against a small PR and a large one (91 lines / 3 files and 1256 lines / 11 files) — both produce a well-formed unified diff as a file, including the small case that previously fell back to prose.
Confirmed the harness resolves a relative
Readpath against the session working directory, so a subagent findspr.diffwhether it is handed an absolute or a relative path.scripts/ci/gen_codex_review.pyregenerated: all five.codex/agents/*.tomlcarry the scope instruction and the emitted prompt carries thepr.diffcontract. Workflow YAML parses and both jobs show the new step in order.pre-commit run --filespasses on all seven changed files.🤖 Generated with Claude Code
https://claude.ai/code/session_013KX52EswZ1UUySg2CN2nEg