damccorm opened a new pull request, #41844:
URL: https://github.com/apache/beam/pull/41844
Improves `.github/workflows/gemini_code_review.yml` to produce deeper,
higher-signal, lower-false-positive automated PR reviews while keeping
`pull_request_target` strictly read-only (never executing untrusted PR code).
### Summary of Changes
1. **Read-only local base checkout + pre-fetched PR context (replacing
`web_fetch`)**
- Checks out the trusted default branch (`master`) via
`actions/checkout@v7` (`path: repo`, `fetch-depth: 50`, `persist-credentials:
false`).
- Pre-fetches PR metadata (`mergeable`/`mergeable_state`, commits), full
unified diff (`pr.diff`), incremental diff since the previous Gemini review
(`incremental.diff`), valid `LEFT`/`RIGHT` diff hunk ranges
(`valid_lines.json`), full head-SHA contents of modified/added non-binary files
(`pr_context/head_files/`, capped at 40 files / 250 KB each with path-traversal
and symlink guards), prior reviews/threads/issue comments (including GraphQL
`isResolved`/`isOutdated`), and check runs/annotations (`checks.json`).
- Replaces `tools.core: ["web_fetch"]` with strictly read-only local
tools (`read_file`, `grep_search`, `glob`, `list_directory`) and explicit
`tools.exclude` (`run_shell_command`, `write_file`, `replace`, `web_fetch`,
`google_web_search`, `save_memory`). Removing `web_fetch` also reduces
SSRF/exfiltration surface on self-hosted runners.
- Increases `maxSessionTurns` from `25` to `50` and job timeout from `15`
to `20` minutes so larger PRs can trace callers, subclasses, and sibling
implementations.
2. **Versioned, Beam-specific adversarial review guide
(`.github/gemini_review_guide.md`)**
- Loaded from the trusted `repo/` checkout with explicit prompt-injection
boundaries treating everything under `pr_context/` as untrusted data.
- Instructs the agent to read full surrounding functions/classes, grep
callers/subclasses/JMH benchmarks, compare sibling implementations, check
recent `master` history, follow a Beam-specific checklist (concurrency/locking,
serialization/savepoint compatibility, Python/Java/Go SDK pitfalls, GHA
security, RAT headers), and perform a mandatory self-verification pass to
eliminate false positives and duplicate threads on re-reviews.
3. **Recent git history & opportunistic non-executing static checks**
- Collects `git log -n 10 --oneline` for touched files/directories
(`recent_history.txt`) to catch recent `master` drift/conflicts.
- Runs pure AST/token formatters/linters (`yapf --diff`, `ruff check
--no-fix`, `gofmt -d`, `google-java-format --dry-run`) opportunistically
against `pr_context/head_files/` when installed on the runner (without
executing or importing PR code), using SIGPIPE-safe truncation.
4. **Workflow & review-posting fixes**
- Pins `commit_id: headSha` on `pulls.createReview` so comments don't
shift if new commits are pushed mid-run.
- Validates each inline comment's `(path, line, side)` and optional
multi-line `(start_line, start_side)` against `valid_lines.json` (same diff
hunk) before submission, moving only unplaceable comments to the summary
instead of falling back all-or-nothing on HTTP `422`.
- Adds `start_line` / `start_side` support to the JSON schema for
multi-line `suggestion` blocks.
- Gates `issue_comment` `/gemini review` triggers to `OWNER`, `MEMBER`,
`COLLABORATOR`, `CONTRIBUTOR`, or the PR author.
- Removes `github.actor` from `concurrency.group` so concurrent `/gemini
review` comments on the same PR deduplicate.
- Adds an `if: always()` cleanup step for temporary review files on
self-hosted runners.
### Verification
- Validated YAML syntax (`yaml.safe_load`), Bash syntax (`bash -n`),
embedded JS syntax (`node --check` on all 3 `actions/github-script` steps),
trailing whitespace/tabs/CRLF, Apache 2.0 headers, zero `${{ ... }}`
interpolation inside `run:`/`script:`, and zero deprecated GCS CLI references.
- Unit-tested `parseDiffHunks` with Node across multi-hunk, pure-addition,
pure-deletion, and `\ No newline at end of file` patches.
- Verified exact `tools.core` / `tools.exclude` / `maxSessionTurns` names
against `google-gemini/gemini-cli` `v0.37.1` (`base-declarations.ts` and
`settingsSchema.ts`).
--
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]