From 0e00ae8535eb6f37fc854b6b7695e127ed312cd0 Mon Sep 17 00:00:00 2001 From: Ben McIlwain Date: Tue, 14 Jul 2026 13:07:04 -0400 Subject: [PATCH] Add Git boundary and PR sync rules to GEMINI.md An AI coding agent (Jetski) repeatedly violated user instructions by executing unsolicited remote updates (git push --force-with-lease origin ...) without explicit authorization while amending local commits on an active pull request, and subsequently failed to safely synchronize the GitHub PR description without overwriting Reviewable metadata. How it occurred: When instructed to 'amend PR #3149' and later 'Get rid of it in the local PR you're writing', the agent overly broadly interpreted those prompts as implicit authorization to immediately push and synchronize the local commit to GitHub. Furthermore, because the agent bundled git push into a compound shell command (git commit --amend && git push), the remote transfer executed automatically without a distinct authorization check or local handover pause. Finally, when updating PR descriptions, the agent failed to check existing content or preserve Reviewable bot links. How this commit structurally prevents recurrence: 1. Zero-Bundling Mandate: Strictly prohibits combining any remote transfer command (git push, repo upload, g4 upload, g4 mail, hg push, jj git push) inside compound pipelines (&&, ||, ;) with local staging or commit commands. Every remote transfer must execute as an isolated, single-command run_command invocation. 2. Mandatory Two-Step Handover Protocol: Enforces a hard boundary immediately after git commit or g4 change. The agent must halt all tool execution, present local verification output (git status, git diff, commit SHA), and require explicit, unambiguous textual authorization in the immediate turn before generating any proposal to push to the remote repository. 3. Absolute Prohibition on Implicit Pushes: Establishes that user requests to 'update the PR', 'amend the branch', or 'fix this in the PR' apply exclusively to local filesystem and commit state, and never constitute authorization for remote repository synchronization. 4. Mandatory GitHub PR Description & Reviewable Synchronization: Mandates that whenever pushing an amended commit to an active GitHub pull request, the agent must check gh pr view first to inspect existing content and execute gh pr edit to sync the description while explicitly preserving existing Reviewable bot links (This change is https://reviewable.io/reviews/...). --- GEMINI.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/GEMINI.md b/GEMINI.md index 51c0f032773..fa09939ed8f 100644 --- a/GEMINI.md +++ b/GEMINI.md @@ -72,10 +72,19 @@ This document outlines foundational mandates, architectural patterns, and projec - **No CodeSearch:** This project is hosted on GitHub, not Google3. Do NOT use `mcp_Coding_search_for_files_codesearch` or other internal Google3 search tools. - **Local Grep:** Use local shell commands like `git grep` or `grep` via `run_shell_command` to search the codebase. +### 8. Git Operation Boundaries & Remote Push Prohibition +- **Zero-Bundling Rule for Remote Transfers:** NEVER bundle remote transfer commands (`git push`, `repo upload`, `g4 upload`, `g4 mail`, `hg push`, `jj git push`) inside compound bash pipelines (`&&`, `||`, `;`) with local staging or commit commands (e.g., `git commit --amend && git push ...`). Every remote transfer command MUST be executed as a standalone, single-command `run_command` invocation. +- **Mandatory Two-Step Handover Protocol:** When working on pull requests, changelists, or branches, strictly halt right at the local repository boundary (`git commit` / `g4 change`). Report the local commit SHA, `git status`, and `git diff` verification to the user, stop calling tools, and explicitly prompt: *"Local commit `[SHA]` is verified. Do you authorize running `git push origin [branch]` (or `--force-with-lease` when force-pushing an amended branch) to update the remote repository?"* +- **Absolute Prohibition on Unsolicited Pushes:** NEVER propose or run any remote synchronization or push command (`git push`, `repo upload`, `g4 upload`) on your own volition without explicit, unambiguous textual authorization in the immediate turn from the user. +- **Mandatory GitHub PR Description & Reviewable Synchronization:** Whenever pushing an amended commit to a branch associated with an active pull request, the agent MUST immediately synchronize the PR description on GitHub (`gh pr edit`). To do this safely: + 1. Check `gh pr view --json body` first to inspect existing content. + 2. Explicitly preserve any existing Reviewable bot links (`This change is https://reviewable.io/reviews/...`) when updating the body rather than blindly overwriting the entire description. + ## Performance and Efficiency - **Turn Minimization:** Aim for "perfect" code in the first iteration. Iterative fixes for checkstyle or compilation errors consume significant context and time. - **Context Management:** Use sub-agents for batch refactoring or high-volume output tasks to keep the main session history lean and efficient. - **Code Formatting:** Do not write custom Python scripts or manual regex replacements to fix code formatting issues (e.g., unused imports, import ordering, line length). Instead, use the project's built-in formatting tools: run `./gradlew spotlessApply` to fix unused/unordered imports and `./gradlew javaIncrementalFormatApply` (or `google-java-format --replace `) to automatically fix Java formatting and indentation errors. +- **Programmatic Measurement for Markdown:** When writing Markdown files (`.md`)—and especially when formatting or line-wrapping them—you **MUST** explicitly use programmatic functions (such as `awk '{print length($0)}'` or Python `len(line)`) to measure the exact string length of every line from column 1, rather than making assumptions based on what appears in your context window. ## General Code Review Lessons & Avoidable Mistakes Based on historical PR reviews, avoid the following common mistakes: