XMC Address PR Comment
Automates addressing PR comments (fetching context, running tests, measuring coverage, and GKE redeployment).
Warnings for the author
- "name" should use lowercase letters, digits and single hyphens only
- "name" should match the name of the directory that holds SKILL.md
- Not listed through the skills extension: the directory must be named after the skill.
PR Comment-Driven Development Workflow
This document defines a structured agent workflow that automates the process of addressing GitHub Pull Request comments while enforcing comment integrity, programmatic enumeration, and 1-to-1 thread resolution verification.
graph TD
A["User provides PR / comment link"] --> B["Agent runs generate_review_checklist.py"]
B --> C["Agent populates pr_review_checklist.md"]
C --> D["Agent runs fetch_pr_comment.py for comment context"]
D --> E["Agent extracts: body, file path, line"]
E --> D2["Agent performs Comment Validity & Pushback Triage"]
D2 --> J2["Agent prepares & posts inline pushback replies (for Push Back items)"]
J2 --> M["1-to-1 Thread Resolution Verification (verify_pr_comment_resolution.py)"]
D2 --> D3{"Any Adopt items?"}
D3 -->|Yes| F["Agent performs Bazel Query to find affected binaries"]
D3 -->|No| M
F --> G["Agent prepares Implementation Plan"]
G --> H["Agent runs Unit Tests & Coverage"]
H --> I["Agent builds affected targets locally"]
I --> J["Agent commits changes & replies 'code changed'"]
J --> K["Agent builds & pushes OCI Images"]
K --> L["Agent performs Kubectl Rollout Restart"]
L --> M["1-to-1 Thread Resolution Verification (verify_pr_comment_resolution.py)"]
M --> N["Agent conducts Root-Cause Retrospective & Proposes /XMC Iterative Reflection"]
N --> O{"User approves reflection?"}
O -->|Yes| P["Invoke /XMC Iterative Reflection (Benchmark & Update Rules/Skills)"]
P --> Q["Agent reports status & completes task"]
O -->|No / Done| Q
[!IMPORTANT] All execution steps in this skill MUST strictly adhere to the mandatory PR Review & Inspection Guidelines, Skills & Automation Guidelines, and Core Engineering Standards.
Guidelines for Using CLI Tools
When invoking helper tools under tools/ (e.g. tools/pr_review/generate_review_checklist.py, tools/pr_review/fetch_pr_comment.py, tools/pr_review/reply_pr_comment.py, tools/pr_review/review_threads.py, tools/common/build_oci.py):
- Do not read tool source code: Do not open or read the Python source code of helper tools. Refer to Skills & Automation Guidelines.
- Use
--help: To learn about the tool's usage, options, and parameters, run it with the--helpflag (e.g../tools/pr_review/fetch_pr_comment.py --help). - Parse Structured Output & Handle Errors: All tools output structured JSON; check the exit code per Helper Tool Exit Codes.
- Shell & Payload Safety: Execute standalone
.pyscript files or pass arguments via script parameters. Avoid double-quoted inline commands (python3 -c "...").- Backtick Safety: When passing reply messages containing backticks (e.g. markdown code spans), avoid double-quoted string arguments in bash. Use
--message-file(or-f) to safely read the reply message from a file instead.
- Backtick Safety: When passing reply messages containing backticks (e.g. markdown code spans), avoid double-quoted string arguments in bash. Use
1. Automated Review Checklist Generation
When addressing PR review feedback or starting a review pass on a Pull Request, the agent first generates a checklist of all unresolved comments directly from the GitHub API.
When to Call
- PR Review Start: Call immediately when beginning to process review comments on a PR.
- Review Pass Check: Call during post-PR creation checks or whenever an updated checklist of unresolved comments is needed.
Execution Command
./tools/pr_review/generate_review_checklist.py <owner> <repo> <pr_number> [-o pr_review_checklist.md]
Result Output Schema
{
"status": "success",
"result": {
"owner": "google",
"repo": "xmc",
"pr_number": 145,
"output_file": "pr_review_checklist.md",
"unresolved_comment_count": 3
}
}
This generates pr_review_checklist.md in the workspace populated with interactive - [ ] checkboxes for each unresolved comment.
2. Input & Comment Details Fetching
The agent accepts a comment link or PR number. The helper script tools/pr_review/fetch_pr_comment.py or GitHub API queries retrieve the raw comment context.
Execution Command
./tools/pr_review/fetch_pr_comment.py "<github_comment_url>"
Result Schema
{
"type": "review_comment",
"comment_id": 12345678,
"author": "reviewer_username",
"body": "Comment text describing the request (e.g., 'Refactor this to avoid nested if-else checks')",
"file_path": "pkg/auth/oauth2/handlers.go",
"line": 150,
"diff_hunk": "@@ -148,5 +148,8 @@...",
"commit_id": "a1b2c3d4e5f6..."
}
2.5. Comment Validity & Pushback Triage (Mandatory Before Planning Edits)
Before planning code changes for any review comment (human or automated review bot), the agent MUST critically verify each comment against the actual source tree, .agents/rules/ (especially language guidelines matching the modified file extension, such as Go Guidelines), and PR scope / diff-size limits (./tools/analyze_diff_size.py). Never blindly assume a review suggestion is valid.
Classify every unresolved comment into one of three dispositions:
Adopt (Valid Fix): The comment identifies a genuine bug, race condition, rule violation, or clean improvement within PR scope. Plan the code edit and unit test verification.Push Back (Rule / Technical Conflict): Adopting the suggestion would violate an existing repository rule (for example, Go Guidelines §9 requiring a fresh, bounded context for post-failure diagnostics,defer,t.Cleanup, or non-retried post-commit compensation paths when the parentctxmay already be expired or canceled) or break runtime behavior/existing architecture. Do not modify the code; instead, prepare a concise, respectful inline technical pushback reply citing the governing rule or execution trace.Push Back / Defer (Scope Creep or Diff-Size Breach): Adopting the suggestion requires out-of-scope production refactoring in a focused/test PR or pushes the diff past./tools/analyze_diff_size.pythresholds. Propose an inline reply explaining why the change is deferred to a dedicated follow-up PR.
3. Dependency Mapping & Impact Analysis
To make the workflow precise, the agent must figure out which Bazel binaries and Kubernetes deployments are impacted by the changed file.
Bazel Package Dependency Mapping
The agent runs bazel query to discover all go_binary targets that transitively depend on the modified package:
# 1. Identify the package of the modified file
# E.g. file_path = "pkg/auth/oauth2/handlers.go" -> package //pkg/auth/oauth2
# 2. Query all binaries depending on it
bazel query "kind(go_binary, rdeps(//..., //pkg/auth/oauth2))"
Example Output:
//cmd/xid_service:xid_service//cmd/experiment_state_server:experiment_state_server
Mapping Binaries to GKE Deployments
Each go_binary mapped above is associated with an OCI image builder and GKE deployment:
| Bazel Target | Push Command Target | Helm Template File | GKE Deployment Name |
|---|---|---|---|
//cmd/xid_service:xid_service | //cmd/xid_service:xid_service_image_push | deploy/helm/templates/xid/deployment.yaml | xid-service-deployment |
//cmd/experiment_state_server | //cmd/experiment_state_server:experiment_state_server_image_push | deploy/helm/templates/ess/deployment.yaml | experiment-state-server-deployment |
//cmd/actuator:actuator | //cmd/actuator:actuator_image_push | deploy/helm/templates/actuator/deployment.yaml | actuator-deployment |
//cmd/reconciler:reconciler | //cmd/reconciler:reconciler_image_push | deploy/helm/templates/reconciler/deployment.yaml | reconciler-deployment |
//cmd/log_monitor:log_monitor | //cmd/log_monitor:log_monitor_image_push | deploy/helm/templates/log-monitor/deployment.yaml | log-monitor-deployment |
//cmd/ui (Frontend TS/HTML) | //cmd/ui:ui_image_push | deploy/helm/templates/ess/ui-deployment.yaml | ui-deployment |
//cmd/health_service:health_service | //cmd/health_service:health_service_image_push | deploy/helm/templates/health-service/deployment.yaml | health-service-deployment |
//cmd/rod_data_provider:rod_data_provider | //cmd/rod_data_provider:rod_data_provider_image_push | deploy/helm/templates/rod/deployment.yaml | rod-data-provider-deployment |
4. Implementation Plan Preparation
Based on the parsed review comments, validity triage, and impacted targets, the agent creates a draft implementation plan (e.g., pr_comment_resolution_plan.md) for user review:
- Comment Validity & Pushback Triage Table: A summary table (
Comment ID | Summary | Disposition (Adopt / Push Back / Defer) | Technical Rationale) classifying every comment per Section 2.5. - Analysis: Visual code excerpt and summary of the reviewer's concern.
- Proposed Resolution (Code Changes vs. Inline Pushback Reply): For
Adoptitems, specify target file path, exact lines to modify, and a git diff style code snippet. ForPush Backitems, state explicitly that no code change will be made and draft the exact technical rationale reply to be posted via./tools/pr_review/reply_pr_comment.py. - Affected Components list: Which binaries and deployments need to be verified (for
Adoptitems). - Execution steps: A sequence of commands to verify, commit, reply, and deploy.
5. Test Verification & Code Coverage Check
To verify code correctness, the agent runs all affected unit tests (including reverse dependencies) and measures code coverage.
Run Affected Unit Tests
# Run all Bazel unit tests affected by the branch changes (also executed by ./.githooks/pre-commit)
python3 ./tools/run_affected_tests.py
Check Coverage
To verify test coverage, the agent runs:
bazel coverage --combined_report=lcov //pkg/auth/oauth2/...
The output coverage file is generated under bazel-out/_coverage/_coverage_report.dat.
The agent will parse this file (or generate a summary) to report the package test coverage percentage and point out any lines missing tests.
6. Local Commit & GitHub Notification (On Success)
Execution in this phase branches based on each comment's disposition from Section 2.5:
- For
Adopt (Valid Fix)items: Once local unit tests pass, build the affected binary targets locally, commit the changes as a distinct follow-up commit, and post an inline reply summarizing the fix and commit SHA. - For
Push Back/Deferitems: Bypass local builds andgit commit(if a batch contains zeroAdoptitems, no commit is created) and proceed directly to Post GitHub Comment Notification to post the technical rationale drafted in Section 4.
Build Targets Locally (Adopt Items Only)
Before committing or deploying, verify that the affected binaries build successfully:
bazel build //cmd/xid_service:xid_service
Git Commit to Current Branch (Adopt Items Only)
The agent stages all changes and commits them as a new, distinct follow-up commit with a message that includes a description of the changes and the URL of the original comment:
git add .
git commit -m "<type>(<scope>): address review comment
Comment link: <github_comment_url>"
git push origin HEAD
[!CAUTION] Strict Prohibition of Force-Pushing on Active PRs: NEVER use
git commit --amendorgit push --force(-f) when addressing review comments on an active PR branch. Always append distinct follow-up commits so reviewers can inspect incremental diffs via GitHub's "Changes since last review" view. Squashing happens automatically at merge time via GitHub's "Squash and merge" feature, NEVER during active review rounds.
Reconcile Live PR Description & Tradeoffs (Adopt Items Only)
After pushing follow-up commits, compare gh pr view <pr_number> --json title,body,baseRefName against git diff origin/<baseRefName>...HEAD (fetching origin <baseRefName> first if needed, e.g., on stacked gh-stack PRs). Whenever review fixes change behavior, touched packages, or surface a load-bearing architectural tradeoff (for example, keeping filtering client-side or deferring a schema migration), update the Motivation & Context, Key Changes, and Assumptions sections via ./tools/pr_review/update_pr_description.py after presenting the updated preview for confirmation per XMC Create PR §4.
Verify CI on the Pushed Commit (Adopt Items Only)
After the CI wait buffer, block on CI for the new head commit with the helper tool instead of polling bare gh pr checks (which exits 8 while checks are pending):
./tools/pr_review/wait_for_ci.py <pr_number>
Exit 0 means all checks passed; on exit 1, triage failed_checks and their bounded log_tail fields from its error JSON rather than fetching full CI logs.
Post GitHub Comment Notification
The agent runs the helper script tools/pr_review/reply_pr_comment.py to reply to each comment according to its disposition (a code fix summary and commit SHA for Adopt items, or the technical pushback / deferral rationale drafted in Section 4 for Push Back / Defer items):
export GITHUB_TOKEN="your_github_token"
./tools/pr_review/reply_pr_comment.py "<github_comment_url>" "code changed"
When the reply contains backticks or multi-line rationale (such as a Push Back / Defer technical explanation or a detailed fix summary), pass a file containing the message via --message-file (or -f):
cat << 'EOF' > reply_message.txt
Addressed review comment for `handlers.go` (or technical pushback rationale from Section 4).
EOF
./tools/pr_review/reply_pr_comment.py "<github_comment_url>" --message-file reply_message.txt
[!WARNING] Backtick Subshell Command Safety: Avoid passing double-quoted strings containing backticks (
`) directly on the command line (e.g../tools/pr_review/reply_pr_comment.py "<url>" "Fixedfunc_name()"). Bash evaluates backticks in double-quoted strings as subshell commands prior to executing python, causing unwanted command execution or syntax errors. Always use--message-file(or-f) when the reply message contains backticks or markdown code formatting.
Resolve Review Threads
For Adopt items, pass --resolve so the tool resolves the comment's review thread right after posting the reply (via github_utils.resolve_review_thread). Leave Push Back / Defer threads unresolved so the reviewer can adjudicate, unless the user instructs otherwise:
./tools/pr_review/reply_pr_comment.py "<github_comment_url>" --message-file reply_message.txt --resolve
If --resolve fails after the reply was posted, the tool exits with a handled error carrying the reply_id; do NOT re-post the reply, retry resolution only.
To audit thread state or batch-resolve threads you have already replied to, use tools/pr_review/review_threads.py (it paginates and identifies your replies via the authenticated gh / GITHUB_TOKEN user):
# List threads: thread_id, path:line, is_resolved, replied_by_me, first-comment snippet
./tools/pr_review/review_threads.py list <owner> <repo> <pr_number> --unresolved-only
# Preview, then resolve only unresolved threads that have a reply from you
./tools/pr_review/review_threads.py resolve-replied <owner> <repo> <pr_number> --dry-run
./tools/pr_review/review_threads.py resolve-replied <owner> <repo> <pr_number>
[!IMPORTANT]
Files of this skill
This skill has no supporting files.