Skip to content

[CI] Switch Gemini code review to two-pass Hunter/Verifier agent with local read-only tools (Stack 5/5) - #41855

Closed
damccorm wants to merge 1 commit into
users/damccorm/gemini-review-4-posting-and-dry-runfrom
users/damccorm/gemini-review-5-two-pass-agent
Closed

damccorm wants to merge 1 commit into
users/damccorm/gemini-review-4-posting-and-dry-runfrom
users/damccorm/gemini-review-5-two-pass-agent

Conversation

@damccorm

@damccorm damccorm commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

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 5 small, focused, independently valid stacked PRs that replace 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 (5/5)

Replaces the single-pass web_fetch invocation in Run Gemini Enterprise Code Review Agent (.github/workflows/gemini_code_review.yml, +225 / -17) with the two-pass local read-only pipeline:

  • Strictly read-only local tools: Replaces web_fetch / directWebFetch with tools.core: ["read_file", "grep_search", "glob", "list_directory"] over repo/ and pr_context/ (no shell, no file writes, no network access).
  • Pinned system-memory guide & prompt-injection hardening: Copies repo/.github/gemini_review_guide.md (added in PR 1/5) to a per-run random filename (GEMINI_TRUSTED_GUIDE_<16hex>.md) and sets context.fileName, discoveryMaxDirs: 1, memoryBoundaryMarkers: [], and model.compressionThreshold: 0.9. This prevents long-context instruction drift on large PRs and blocks untrusted PRs from injecting GEMINI.md via pr_context/head_files/.
  • @-free CLI prompts: Keeps hunter_prompt.txt, verifier_prompt.txt, and repair_prompt.txt completely free of literal @ characters so gemini-cli's @file preprocessor cannot attach unrelated workspace files.
  • Pass 1 — Adversarial Hunter (maxSessionTurns: 65): Runs while threads.json is still staged outside the workspace in $RUNNER_TEMP, outputting free-form Markdown to pr_context/hunter_findings.md (printed inside ::group:: when dry_run=true). Gracefully catches FatalTurnLimitedError (exit 53) with a warning and fallback note so Pass 2 still runs.
  • Pass 2 — Skeptical Verifier & JSON Formatter (maxSessionTurns: 35): Moves threads.json into pr_context/threads.json, verifies every Pass 1 candidate against pr_context/head_files/ and repo/, checks exact 1-based line numbers in pr_context/pr.numbered.diff and hunks in valid_lines.json, and emits strict JSON.
  • Pass 2b — JSON Syntax Repair (maxSessionTurns: 4, tools.core: ["read_file"]): Validates gemini_response.txt with Node's JSON.parse; only if invalid (e.g., an unescaped " inside a markdown code span), runs a read-only syntax-repair pass without altering findings or line numbers.
  • Observability, timeout & cleanup: Logs .stats.tools and .stats.models for each pass, raises timeout-minutes from 15 to 30, and cleans up all temporary prompt/output/GEMINI_TRUSTED_GUIDE_*.md files in if: always().

Exact equivalence: The final tree of this PR matches the benchmarked commit (48f502e5dbd on #41844) byte-for-byte.

@damccorm

damccorm commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Consolidated into the 2-PR stack (#41851 and #41860) with review feedback incorporated.

@damccorm damccorm closed this Dec 1, 2026
@damccorm
damccorm removed this pull request from stack #41857 December 1, 2026 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build size/m M: 50-249 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant