Skip to content

[CI] Add incremental diffs, isolated threads, check annotations, and static checks to Gemini review context (Stack 3/5) - #41853

Closed
damccorm wants to merge 1 commit into
users/damccorm/gemini-review-2-pr-diff-and-head-filesfrom
users/damccorm/gemini-review-3-context-enrichment
Closed

damccorm wants to merge 1 commit into
users/damccorm/gemini-review-2-pr-diff-and-head-filesfrom
users/damccorm/gemini-review-3-context-enrichment

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

Enriches the pre-fetched read-only context in .github/workflows/gemini_code_review.yml (+306 / -5) with historical, review-thread, CI, and non-executing static-check signals:

  • Permissions: Adds checks: read (minimal scope for check-run and annotation metadata).
  • Incremental diff (pr_context/incremental.diff): Finds the most recent prior github-actions[bot] Gemini review commit (last_gemini_review_sha) and fetches last_gemini_review_sha...head_sha when new commits have been pushed.
  • Prior threads staged outside the workspace ($RUNNER_TEMP/gemini_review_threads.json):
    • Fetches reviews, inline review comments, recent issue comments (last 30), and GraphQL reviewThreads resolution metadata (isResolved/isOutdated).
    • Sets body: null for prior github-actions[bot] summary reviews so re-reviews cannot parrot earlier bot prose.
    • Writes threads.json outside the workspace root (to $RUNNER_TEMP, cleaned up in if: always()) so Pass 1 in PR 5/5 physically cannot read or anchor on prior threads before finishing its independent bug hunt.
  • CI check runs & annotations (pr_context/checks.json): Summarizes check-run totals and fetches up to 20 annotations for up to 5 failing check runs on head_sha (pure metadata API, no artifact extraction).
  • Lazy mergeability refresh: Re-fetches pulls.get once after the other API calls finish if GitHub initially returned mergeable: null, mergeable_state: "unknown".
  • Recent history & non-executing static checks (Collect recent history and non-executing static checks):
    • Writes pr_context/recent_history.txt (git -C repo -c core.hooksPath=/dev/null log -n 10 --oneline per touched path, truncated via temp file to avoid SIGPIPE under pipefail).
    • Runs yapf, ruff, gofmt, and google-java-format when available on the runner (never importing or executing PR code), falling back to pr_context/java_line_length.txt when google-java-format is absent.

Standalone safety: Populates additional read-only files only; leaves the agent invocation and posting steps unchanged until PRs 4–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