damccorm opened a new pull request, #41860:
URL: https://github.com/apache/beam/pull/41860

   Context: I found I was getting much better results from my local agent than 
I was from the review bot. This tries to fix the problem, but I expect we'll 
want to do more hill climbing from here
   
   ## Overall Change (Gemini Code Review Overhaul)
   
   Splits draft PR #41844 into a **2-PR stack** (1/2: trusted review guide; 
2/2: workflow YAML + `infra/gemini_code_review/` helper scripts) that replaces 
the single-pass `web_fetch`-based review workflow with a hardened, two-pass 
**Hunter → Verifier** review agent operating over read-only local context 
(`repo/` + `pr_context/`):
   
   - **Problem:** The existing workflow uses `web_fetch` on the PR URL with no 
checkout, no `grep_search` across callers/subclasses, no diff-hunk or 
`commit_id` validation, no `dry_run` testing mode, and single-pass JSON output 
— leading to missed bugs on non-trivial PRs and occasional hallucinated false 
positives.
   - **Solution:** Pre-fetch read-only PR context (`pr.diff`, exact 1-based 
`pr.numbered.diff`, `valid_lines.json`, bounded `head_files/`, 
`incremental.diff`, `checks.json`, git log/static checks, and 
`$RUNNER_TEMP`-isolated `threads.json`), pin `.github/gemini_review_guide.md` 
in system memory under a random per-run filename, run Pass 1 (high-recall 
Adversarial Hunter) → Pass 2 (high-precision Skeptical Verifier & JSON 
Formatter) → optional Pass 2b (JSON syntax repair), validate single-/multi-line 
same-hunk placement pinned to `head_sha`, and add a `workflow_dispatch` 
`dry_run` mode.
   - **End-to-end verification:** Evaluated iteratively using 
`workflow_dispatch` with `dry_run=true` across a representative sample of 10 
open Java, Python, Go, YAML, runner, and I/O PRs—comparing the bot's output 
against independent blind reviews without posting comments—including a clean PR 
check to verify precision (0 false positives). Also verified workflow lint, 
license, whitespace, and security checks (`beam_PreCommit_GHA`, 
`beam_PreCommit_RAT`, `beam_PreCommit_Whitespace`, and `zizmor`).
   
   ### What This PR Changes (`2/2`, stacked on #41851)
   
   Updates 
[`.github/workflows/gemini_code_review.yml`](.github/workflows/gemini_code_review.yml)
 to delegate to standalone scripts under `infra/gemini_code_review/` (checked 
out from the trusted base branch into `repo/`, keeping the workflow file slim 
at 156 lines while preserving the `pull_request_target` trust boundary):
   
   - 
**[`.github/workflows/gemini_code_review.yml`](.github/workflows/gemini_code_review.yml):**
     - Adds `workflow_dispatch.inputs.dry_run` (`type: boolean`, `default: 
false`), `checks: read` permission, `timeout-minutes: 30`, and `retries: 3` on 
read-only `actions/github-script@v9` steps (keeping `retries: 0` on review 
posting).
     - Leaves existing `concurrency.group` and `/gemini review` `issue_comment` 
trigger conditions unchanged from `master`.
     - Adds `Checkout trusted base branch` (`path: repo`, `fetch-depth: 50`, 
`persist-credentials: false`), invokes the 4 scripts below from 
`repo/infra/gemini_code_review/`, and adds an `if: always()` cleanup step for 
temporary files and `$RUNNER_TEMP/gemini_review_threads.json`.
   - 
**[`infra/gemini_code_review/prepare_context.js`](infra/gemini_code_review/prepare_context.js):**
 Fetches read-only `pr_context/` artifacts: `head_sha.txt`, `valid_lines.json`, 
`java_line_length.txt` (>100-col added Java lines heuristic), `pr.diff`, exact 
1-based `pr.numbered.diff`, `incremental.diff` since the last Gemini review, 
bounded non-binary `head_files/` (path-traversal-guarded), `changed_files.txt`, 
`checks.json` failed annotations, lazy `mergeable`/`mergeable_state` refresh, 
`metadata.json`, and `threads.json` staged outside the workspace in 
`$RUNNER_TEMP` (with GraphQL `isResolved`/`isOutdated` metadata and prior 
`github-actions[bot]` summary prose omitted to avoid anchoring).
   - 
**[`infra/gemini_code_review/collect_static_checks.sh`](infra/gemini_code_review/collect_static_checks.sh):**
 Collects recent `master` `git log` for touched paths 
(`core.hooksPath=/dev/null`) and runs non-executing local formatters/linters 
(`yapf`, `ruff`, `gofmt`, `google-java-format`, or the `java_line_length.txt` 
fallback) without importing or executing PR code.
   - 
**[`infra/gemini_code_review/run_review_agent.sh`](infra/gemini_code_review/run_review_agent.sh):**
 Replaces `web_fetch` with strictly read-only local tools (`read_file`, 
`grep_search`, `glob`, `list_directory`), pins 
`repo/.github/gemini_review_guide.md` in system memory under a random per-run 
`GEMINI_TRUSTED_GUIDE_<16hex>.md` filename (`discoveryMaxDirs: 1`, 
`memoryBoundaryMarkers: []`, `compressionThreshold: 0.9`) to prevent context 
drift and untrusted `GEMINI.md` injection, and runs **Pass 1 (Hunter, 65 turns, 
graceful exit-53 fallback)** → reveals `threads.json` → **Pass 2 (Verifier, 35 
turns)** → optional **Pass 2b (JSON syntax repair, `read_file`-only, 4 
turns)**. Includes a sync comment pointing to `.github/gemini_review_guide.md` 
and keeps all CLI prompt heredocs free of literal `@` tokens.
   - 
**[`infra/gemini_code_review/post_review.js`](infra/gemini_code_review/post_review.js):**
 Pins `commit_id`, validates single- and multi-line same-hunk placement against 
`valid_lines.json` (preserving single-line `suggestion` blocks when `start_line 
=== line && start_side === side`, routing out-of-hunk notes to `## 💬 Additional 
Findings`), warns explicitly on `JSON.parse` failures, and prints formatted 
logs + JSON payload + `$GITHUB_STEP_SUMMARY` without calling 
`pulls.createReview` when `DRY_RUN === 'true'`.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to