From fe5eb8c9f7565aa8104040f409f7242f44ce595e Mon Sep 17 00:00:00 2001 From: Vader Yang Date: Tue, 9 Jun 2026 14:32:31 +0800 Subject: [PATCH] fix(review): inject the diff into the prompt instead of having the agent fetch it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit vivi's review came back COMMENTED on every PR with a body like: I'll start by getting the PR diff... Bash...gh pr diff N --patch... diff --git ... The model backend emits tool calls as *plain text* instead of invoking them natively, so the agent never actually receives the diff, produces no `### Summary` heading, and post_review falls back to COMMENTED — leaving every PR blocked on a review that never really ran. Make the review backend-agnostic: run_review.sh now pre-fetches the diff and appends it to the prompt (capped at 800 KB; appended, not via envsubst, which would mangle `${...}` byte sequences in a diff). prompt.md reviews the inline diff directly instead of instructing a first `gh pr diff` tool call. Read/Grep stay available for deeper investigation when native tool-calling works; when it doesn't, the agent still produces a real review from the diff — including the critical leakage check, which only needs the diff. post_review tests unchanged (16 pass); run_review.sh shellcheck/`bash -n` clean. Co-Authored-By: Claude Opus 4.8 (1M context) --- scripts/pr-review/prompt.md | 11 +++++++---- scripts/pr-review/run_review.sh | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/scripts/pr-review/prompt.md b/scripts/pr-review/prompt.md index 3240f93..c0c0a3e 100644 --- a/scripts/pr-review/prompt.md +++ b/scripts/pr-review/prompt.md @@ -71,8 +71,10 @@ When you see code that smells like one of these, call it out as ## Method — do exactly this, in this order -1. **Get the diff**: `gh pr diff ${PR_NUMBER} --patch`. Skim once - for shape (size, languages touched). +1. **Read the diff** — it is pre-fetched and included at the END of + this prompt; no tool call is needed to get it. Skim once for shape + (size, languages touched). (If it was truncated for size, fetch the + rest yourself with `gh pr diff ${PR_NUMBER} --patch`.) 2. **For each changed file** (cap at 25 if there are more — list the skipped in your output): @@ -149,5 +151,6 @@ explicit recommendation: APPROVE / COMMENT / REQUEST_CHANGES. - **Cap your investigation**: ≤ 60 turns. If you hit the cap, dump what you have — partial reviews are still useful. -Now start. Your first tool call should be `Bash: gh pr diff -${PR_NUMBER} --patch`. +Now start. The full diff is included at the end of this prompt — review +it directly; use Read / Grep on the changed files for the deeper checks +above. Your output must begin with `### Summary`. diff --git a/scripts/pr-review/run_review.sh b/scripts/pr-review/run_review.sh index f223444..0b4370e 100755 --- a/scripts/pr-review/run_review.sh +++ b/scripts/pr-review/run_review.sh @@ -35,6 +35,25 @@ BASE_REF="$(gh pr view "$PR_NUMBER" --json baseRefName --jq .baseRefName)" export PR_NUMBER HEAD_SHA BASE_REF envsubst < "$WORKDIR/prompt.md" > "$PROMPT" +# Pre-fetch the diff and inject it into the prompt. The review must NOT depend +# on the agent issuing its own `gh pr diff` tool call: some model backends emit +# tool calls as plain text (`…`) instead of invoking them natively, +# so the agent never actually receives the diff and produces an empty, +# heading-less review that falls back to COMMENTED on every PR. Injecting the +# diff up front makes the review backend-agnostic — the agent can review +# directly, and Read/Grep stay available for deeper investigation when native +# tool-calling does work. Appended (not via envsubst) because a diff can contain +# `${…}` byte sequences envsubst would mangle; capped so a huge PR can't blow +# the context window (the agent can fetch more itself when tool-calling works). +{ + echo + echo '## The diff under review (pre-fetched — review this directly)' + echo + echo '```diff' + gh pr diff "$PR_NUMBER" --patch 2>/dev/null | head -c 800000 + echo '```' +} >> "$PROMPT" + # Source the harness adapter — it sources litellm-wait.sh and owns the gateway # pre-flight wait + the retry-on-gateway-down loop. The CLI is the consumer's # .agent-ops.json harness.kind (default: claude).