Repository navigation
feat(ci): add /address-reviews skill for CodeRabbit auto-loop (#2266) - #2330
Conversation
Introduces a Claude Code skill that fetches unresolved CodeRabbit review comments on the current PR, classifies each into valid-fix / style / false-positive / security-flag, applies fixes, and replies to threads. Security-critical findings are never auto-fixed — they route to a human. A PreToolUse hook (ci/hooks/check_pr_merge_reviews.py) blocks gh pr merge while unresolved CodeRabbit threads remain, enforcing the loop. - .claude/skills/address-reviews/SKILL.md — skill definition + workflow - ci/tools/coderabbit_addressor.py — plan / reply / check helper - ci/hooks/check_pr_merge_reviews.py — PreToolUse merge guard - .claude/settings.json — wire hook under Bash matcher - agents/docs/workflow.md — agent-onboarding paragraph Closes #2266. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
📝 WalkthroughWalkthroughThis pull request introduces an automated AI-to-AI review loop system that enables Claude Code to read CodeRabbit review comments, classify them, apply fixes for valid issues, and reply to threads before merging. It includes a pre-merge hook, a CLI tool for managing the workflow, and supporting documentation and configuration. Changes
Sequence DiagramsequenceDiagram
participant User as User / Claude Code
participant Hook as check_pr_merge_reviews.py
participant Addressor as coderabbit_addressor.py
participant GH as GitHub API
participant CB as CodeRabbit Comments
User->>Hook: gh pr merge (Bash command)
Hook->>Hook: Parse stdin JSON payload
Hook->>Addressor: uv run --check (30s timeout)
Addressor->>GH: Fetch PR details
GH-->>Addressor: PR number
Addressor->>GH: GET /pulls/{pr}/comments
GH-->>CB: Request CodeRabbit comments
CB-->>Addressor: Review comment list
Addressor->>Addressor: Classify comments<br/>(security-flag, valid-fix, style, false-positive)
Addressor->>Addressor: Apply resolution heuristics<br/>(check for non-CodeRabbit replies)
Addressor->>Addressor: Exit with 0 (all resolved)<br/>or 1 (unresolved found)
Hook->>Hook: Check exit code
alt Unresolved Reviews (exit 1)
Hook->>Hook: Write stderr message
Hook->>User: Exit with code 2 (DENY merge)
User->>User: Run /address-reviews skill
User->>Addressor: --plan mode (fetch & classify)
Addressor-->>User: JSON plan report
User->>User: Review & apply fixes
User->>Addressor: --reply mode (post responses)
User->>User: Commit & push changes
User->>Hook: Retry gh pr merge
else All Resolved (exit 0)
Hook->>User: Exit with code 0 (ALLOW merge)
User->>User: Merge PR
end
Estimated Code Review Effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly Related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
ci/tools/coderabbit_addressor.py (1)
59-59:MAX_ITERATIONSis advertised but never enforced.Both the skill doc ("Max 3 iterations per PR") and the workflow doc promise a hard cap, but
MAX_ITERATIONSonly ships as informational metadata in the plan payload (line 182). Nothing incheck()or the hook counts prior/address-reviewsruns, so a runaway loop on the agent side is only prevented by the agent obeying the doc.Consider tracking iteration count via a PR label (e.g.,
address-reviews/iter-N) or a sentinel commit-trailer, and havingcheck()return a distinct code when the cap is reached so the hook can escalate to a human-required state instead of silently continuing.Also applies to: 178-183
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ci/tools/coderabbit_addressor.py` at line 59, The MAX_ITERATIONS constant is only metadata and not enforced; update check() to count prior /address-reviews iterations (e.g., by reading PR labels like address-reviews/iter-N or scanning commit trailers for an address-reviews: N marker) and compare against MAX_ITERATIONS, returning a distinct non-success code or raising a specific exception when the cap is reached so the hook can escalate to a human-required state instead of continuing; ensure any place that currently emits the plan payload (where MAX_ITERATIONS is included) still sets the metadata but rely on the new label/trailer-based counting logic in check() and update the hook to interpret the new return code and stop/notify when the cap is exceeded.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@ci/tools/coderabbit_addressor.py`:
- Around line 215-239: The CLI entrypoint main() currently calls ap.parse_args()
directly which prevents tests from injecting argv; change main to accept an
optional argv: list[str] | None parameter (e.g. def main(argv: list[str] | None
= None) -> int) and pass that to ap.parse_args(argv) so unit tests can call
main([...]) without mutating sys.argv; keep all existing behavior and return
values, and ensure type hints are updated and any internal calls (plan, reply,
check, _current_pr) remain unchanged.
- Around line 34-48: The SECURITY_KEYWORDS list currently contains the entry "
auth" which causes false positives via the plain substring match; update the
matching to use whole-word/anchored regexes instead of raw substrings: replace
the literal " auth" with a word-boundary pattern (or convert SECURITY_KEYWORDS
into regex patterns) and change the classification substring check to use
re.search with \b... for each keyword (referencing the SECURITY_KEYWORDS
variable and the classification matching code), and add a unit test asserting
that benign words like "author", "authoritative", or "authentic" do NOT trigger
the security-flag bucket while true auth tokens do.
- Around line 146-155: The _is_resolved function currently uses a list
comprehension and treats any non-CodeRabbit reply as resolution; replace the
comprehension with an explicit loop over all_comments to find replies where
c.in_reply_to == comment.id (for clarity/debugging), then tighten the heuristic:
first, prefer using the authoritative GraphQL review-thread isResolved field if
available on Comment; otherwise consider a reply resolving only if the replier
equals the PR author (compare reply.author to the PR author passed into or
accessible from the context) AND the reply references a newer commit than the
CodeRabbit message (compare reply.commit_sha or reply.commit_id to
comment.commit_sha/commit_id), and ignore any replies from CODERABBIT_LOGINS;
update _is_resolved to return True only when those stricter conditions are met.
---
Nitpick comments:
In `@ci/tools/coderabbit_addressor.py`:
- Line 59: The MAX_ITERATIONS constant is only metadata and not enforced; update
check() to count prior /address-reviews iterations (e.g., by reading PR labels
like address-reviews/iter-N or scanning commit trailers for an address-reviews:
N marker) and compare against MAX_ITERATIONS, returning a distinct non-success
code or raising a specific exception when the cap is reached so the hook can
escalate to a human-required state instead of continuing; ensure any place that
currently emits the plan payload (where MAX_ITERATIONS is included) still sets
the metadata but rely on the new label/trailer-based counting logic in check()
and update the hook to interpret the new return code and stop/notify when the
cap is exceeded.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: be89e316-a0cc-46de-838c-ccd5d8e66dfd
📒 Files selected for processing (5)
.claude/settings.json.claude/skills/address-reviews/SKILL.mdagents/docs/workflow.mdci/hooks/check_pr_merge_reviews.pyci/tools/coderabbit_addressor.py
| SECURITY_KEYWORDS = [ | ||
| "security", | ||
| "cve", | ||
| " auth", | ||
| "credential", | ||
| "secret", | ||
| "rce", | ||
| "injection", | ||
| "critical", | ||
| "data loss", | ||
| "uaf", | ||
| "use-after-free", | ||
| "buffer overflow", | ||
| "out-of-bounds", | ||
| ] |
There was a problem hiding this comment.
" auth" substring causes false-positive security-flag classification.
" auth" (space + "auth") will match common innocuous words like author, authoritative, authentic, autopilot→no wait—only author*. CodeRabbit frequently writes things like "The author of this change…" or "This is authoritative…". Any such comment will be routed to security-flag and per the skill doc (lines 24, 47) is never auto-fixed and blocks merge, stranding benign nits in a human-only bucket.
Since classification is a plain substring search (line 75), tighten to whole-word/anchored matches or use a regex list.
🐛 Proposed fix
-SECURITY_KEYWORDS = [
- "security",
- "cve",
- " auth",
- "credential",
- "secret",
- "rce",
- "injection",
- "critical",
- "data loss",
- "uaf",
- "use-after-free",
- "buffer overflow",
- "out-of-bounds",
-]
+SECURITY_PATTERNS = [
+ re.compile(p, re.IGNORECASE)
+ for p in (
+ r"\bsecurity\b", r"\bCVE\b", r"\bauth(?:n|z|entication|orization)?\b",
+ r"\bcredential\b", r"\bsecret\b", r"\bRCE\b", r"\binjection\b",
+ r"\bCRITICAL\b", r"\bdata loss\b", r"\bUAF\b", r"\buse-after-free\b",
+ r"\bbuffer overflow\b", r"\bout-of-bounds\b",
+ )
+]
@@
- body_lower = self.body.lower()
- for kw in SECURITY_KEYWORDS:
- if kw in body_lower:
- return "security-flag"
+ for pat in SECURITY_PATTERNS:
+ if pat.search(self.body):
+ return "security-flag"Worth adding a unit test pinning the expected bucket for a handful of representative CodeRabbit comment bodies.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@ci/tools/coderabbit_addressor.py` around lines 34 - 48, The SECURITY_KEYWORDS
list currently contains the entry " auth" which causes false positives via the
plain substring match; update the matching to use whole-word/anchored regexes
instead of raw substrings: replace the literal " auth" with a word-boundary
pattern (or convert SECURITY_KEYWORDS into regex patterns) and change the
classification substring check to use re.search with \b... for each keyword
(referencing the SECURITY_KEYWORDS variable and the classification matching
code), and add a unit test asserting that benign words like "author",
"authoritative", or "authentic" do NOT trigger the security-flag bucket while
true auth tokens do.
| def _is_resolved(comment: Comment, all_comments: list[Comment]) -> bool: | ||
| # Resolution heuristic: a non-CodeRabbit author replied in-thread since | ||
| # the last CodeRabbit message. Proper GraphQL "resolved" state is also | ||
| # honored via the review-thread API but needs a heavier call — start | ||
| # with the reply heuristic and evolve if false positives show up. | ||
| replies = [c for c in all_comments if c.in_reply_to == comment.id] | ||
| if not replies: | ||
| return False | ||
| latest = max(replies, key=lambda c: c.id) | ||
| return latest.author not in CODERABBIT_LOGINS |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Confirm GitHub exposes a resolved flag on review threads via GraphQL that the tool could query.
gh api graphql -f query='{
repository(owner:"FastLED", name:"FastLED") {
pullRequest(number: 2330) {
reviewThreads(first: 5) { nodes { isResolved comments(first:1){ nodes { id author { login } } } } }
}
}
}' 2>&1 | head -40Repository: FastLED/FastLED
Length of output: 129
🏁 Script executed:
cat -n ci/tools/coderabbit_addressor.py | sed -n '146,155p'Repository: FastLED/FastLED
Length of output: 703
🏁 Script executed:
rg -n "CODERABBIT_LOGINS" ci/tools/coderabbit_addressor.py -B 2 -A 2Repository: FastLED/FastLED
Length of output: 518
Replace list comprehension with explicit loop and tighten resolution heuristic.
The function incorrectly marks threads resolved on any non-CodeRabbit reply, regardless of content or author identity. A maintainer posting "Looking at this" will flip the thread to resolved and allow --check to pass even though no code change occurred.
Additionally, line 151 uses a list comprehension; use an explicit loop instead for clarity and debuggability per coding standards.
Consider either:
- Use the GraphQL
isResolvedfield directly, which GitHub exposes and is authoritative. - Require the replier to be the PR author AND the thread to reference a newer commit than the CodeRabbit message.
Current code
def _is_resolved(comment: Comment, all_comments: list[Comment]) -> bool:
# Resolution heuristic: a non-CodeRabbit author replied in-thread since
# the last CodeRabbit message. Proper GraphQL "resolved" state is also
# honored via the review-thread API but needs a heavier call — start
# with the reply heuristic and evolve if false positives show up.
replies = [c for c in all_comments if c.in_reply_to == comment.id]
if not replies:
return False
latest = max(replies, key=lambda c: c.id)
return latest.author not in CODERABBIT_LOGINS
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@ci/tools/coderabbit_addressor.py` around lines 146 - 155, The _is_resolved
function currently uses a list comprehension and treats any non-CodeRabbit reply
as resolution; replace the comprehension with an explicit loop over all_comments
to find replies where c.in_reply_to == comment.id (for clarity/debugging), then
tighten the heuristic: first, prefer using the authoritative GraphQL
review-thread isResolved field if available on Comment; otherwise consider a
reply resolving only if the replier equals the PR author (compare reply.author
to the PR author passed into or accessible from the context) AND the reply
references a newer commit than the CodeRabbit message (compare reply.commit_sha
or reply.commit_id to comment.commit_sha/commit_id), and ignore any replies from
CODERABBIT_LOGINS; update _is_resolved to return True only when those stricter
conditions are met.
| def main() -> int: | ||
| ap = argparse.ArgumentParser() | ||
| ap.add_argument( | ||
| "pr", nargs="?", type=int, help="PR number (default: current branch)" | ||
| ) | ||
| group = ap.add_mutually_exclusive_group(required=True) | ||
| group.add_argument("--plan", action="store_true") | ||
| group.add_argument("--reply", nargs=2, metavar=("COMMENT_ID", "MESSAGE")) | ||
| group.add_argument("--check", action="store_true") | ||
| args = ap.parse_args() | ||
|
|
||
| pr = args.pr or _current_pr() | ||
| if pr is None: | ||
| print("[address-reviews] no PR found for current branch", file=sys.stderr) | ||
| return 2 | ||
|
|
||
| if args.plan: | ||
| print(json.dumps(plan(pr), indent=2)) | ||
| return 0 | ||
| if args.reply: | ||
| reply(pr, int(args.reply[0]), args.reply[1]) | ||
| return 0 | ||
| if args.check: | ||
| return check(pr) | ||
| return 2 |
There was a problem hiding this comment.
🛠️ Refactor suggestion | 🟠 Major
parse_args should accept an optional list[str] for testability, and --check is effectively untestable without it.
main() hard-codes ap.parse_args() with no argv override, so unit tests can't drive the CLI without mutating sys.argv. Per the repo's Python standards, parse_args functions must accept an optional list[str].
As per coding guidelines: "parse_args functions MUST accept an optional list[str] parameter for testing flexibility".
♻️ Proposed refactor
-def main() -> int:
- ap = argparse.ArgumentParser()
+def main(argv: Optional[list[str]] = None) -> int:
+ ap = argparse.ArgumentParser()
ap.add_argument(
"pr", nargs="?", type=int, help="PR number (default: current branch)"
)
group = ap.add_mutually_exclusive_group(required=True)
group.add_argument("--plan", action="store_true")
group.add_argument("--reply", nargs=2, metavar=("COMMENT_ID", "MESSAGE"))
group.add_argument("--check", action="store_true")
- args = ap.parse_args()
+ args = ap.parse_args(argv)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@ci/tools/coderabbit_addressor.py` around lines 215 - 239, The CLI entrypoint
main() currently calls ap.parse_args() directly which prevents tests from
injecting argv; change main to accept an optional argv: list[str] | None
parameter (e.g. def main(argv: list[str] | None = None) -> int) and pass that to
ap.parse_args(argv) so unit tests can call main([...]) without mutating
sys.argv; keep all existing behavior and return values, and ensure type hints
are updated and any internal calls (plan, reply, check, _current_pr) remain
unchanged.
Summary
Closes the CodeRabbit ↔ AI-agent loop from issue #2266.
/address-reviewsskill at.claude/skills/address-reviews/SKILL.md— fetches CodeRabbit comments, classifies each, applies fixes, replies to threads.ci/tools/coderabbit_addressor.py— three modes:--plan(fetch+classify),--reply <id> <msg>,--check(exit non-zero if unresolved).ci/hooks/check_pr_merge_reviews.py— PreToolUse hook on Bash that blocksgh pr mergewhile unresolved CodeRabbit threads remain..claude/settings.json— wires the hook under the Bash matcher.agents/docs/workflow.md— agent-onboarding paragraph.Safety rails
security-flagbucket for a human.Scope boundaries
.coderabbit.yaml— already correctly configured.Test plan
uv run python ci/tools/coderabbit_addressor.py --helpwired upbash lintpassesOpen question
Security-flag keyword list is a heuristic. Acceptable as-is, or prefer stricter (CodeRabbit's explicit CRITICAL tag only)?
Closes #2266.
🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
Documentation
Chores