Skip to content

[CI] Harden Gemini review triggers and prepare read-only PR diff/head-file context (Stack 2/5) - #41852

Closed
damccorm wants to merge 1 commit into
users/damccorm/gemini-review-1-review-guidefrom
users/damccorm/gemini-review-2-pr-diff-and-head-files
Closed

damccorm wants to merge 1 commit into
users/damccorm/gemini-review-1-review-guidefrom
users/damccorm/gemini-review-2-pr-diff-and-head-files

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 (2/5)

Hardens trigger/concurrency controls and adds the trusted base checkout plus core read-only PR context fetching in .github/workflows/gemini_code_review.yml (+331 / -8):

  • Trigger & concurrency hardening:
    • Gates /gemini review comments on author_association (OWNER, MEMBER, COLLABORATOR, CONTRIBUTOR) or PR author (github.event.issue.user.login == github.event.comment.user.login).
    • Simplifies concurrency.group to gemini-code-review-<pr_number> so duplicate triggers across event types/actors coalesce cleanly.
    • Adds retries: 3 on read-only actions/github-script@v9 steps (Check for existing Gemini review from draft and Prepare read-only PR context) to guard against transient GitHub API HTTP 500s (keeping retries: 0 on review posting).
  • Trusted base checkout (Checkout trusted base branch): Checks out only the trusted base branch into repo/ (fetch-depth: 50, persist-credentials: false), never untrusted PR code.
  • Core read-only context (Prepare read-only PR context): Writes pr_context/ containing:
    • head_sha.txt — pinned PR head commit SHA.
    • valid_lines.json — per-file RIGHT/LEFT diff hunk [start, end] ranges.
    • java_line_length.txt — added Java lines exceeding 100 columns (excluding import, package, and URLs) as a deterministic Spotless heuristic when google-java-format is absent.
    • pr.diff (with fallback to assembling per-file patches on HTTP 406) and pr.numbered.diff (every hunk line prefixed with exact 1-based [L<old>|R<new>] line numbers to prevent off-by-1 line references).
    • head_files/<path> — bounded (max 40 files, 250 KB/file, non-binary, path-traversal-guarded) full head-SHA text contents of modified/added files.
    • changed_files.txt and metadata.json.
  • Cleanup step (Clean up temporary review files, if: always()): Removes pr_context/, .gemini/, prompt files, and raw Gemini output files on runner exit.

Standalone safety: Keeps the existing Run Gemini Enterprise Code Review Agent and Post PR Review to GitHub steps unchanged, so the workflow remains completely functional if merged before PRs 3–5.

@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