Skip to content

feat(ci): add /address-reviews skill for CodeRabbit auto-loop (#2266) - #2330

Merged
zackees merged 1 commit into
masterfrom
feat/claude-address-reviews-skill
Apr 18, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/claude-address-reviews-skill

Conversation

@zackees

@zackees zackees commented Apr 18, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes the CodeRabbit ↔ AI-agent loop from issue #2266.

  • /address-reviews skill 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 blocks gh pr merge while unresolved CodeRabbit threads remain.
  • .claude/settings.json — wires the hook under the Bash matcher.
  • agents/docs/workflow.md — agent-onboarding paragraph.

Safety rails

  • Max 3 iterations per PR (documented in SKILL.md).
  • Security-critical findings never auto-fixed. Any comment containing security / CVE / auth / credential / secret / RCE / injection / CRITICAL / data loss / UAF / use-after-free / buffer overflow / out-of-bounds routes to the security-flag bucket for a human.
  • Hook fails open on unexpected errors rather than silently blocking merges.

Scope boundaries

  • Does NOT touch .coderabbit.yaml — already correctly configured.
  • Does NOT ship as a GitHub Action — skill + hook first; Action variant can follow.
  • FastLED-repo only; org-wide rollout is out of scope.

Test plan

  • uv run python ci/tools/coderabbit_addressor.py --help wired up
  • Hook passthrough on non-merge Bash commands (rc=0)
  • Hook passthrough on non-Bash tools (rc=0)
  • bash lint passes
  • Live run on this PR once CodeRabbit posts
  • Live merge block test

Open 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

    • Added comprehensive workflow documentation for addressing PR review comments prior to merge.
    • Documented review classification procedures and handling guidelines for different finding types.
  • Chores

    • Implemented automated pre-merge validation that requires all PR reviews to be resolved before allowing merges.
    • Added tooling to streamline the PR review resolution workflow.

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]>
@coderabbitai

coderabbitai Bot commented Apr 18, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This 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

Cohort / File(s) Summary
Configuration
.claude/settings.json
Added a PreToolUse hook for Bash that executes the pre-merge check script with a 45-second timeout, resolving the project root via nearest pyproject.toml.
Documentation & Skills
.claude/skills/address-reviews/SKILL.md, agents/docs/workflow.md
Added end-to-end workflow documentation describing the /address-reviews skill, the CodeRabbit review loop process, classification buckets, commit conventions, iteration limits, and the pre-merge blocking mechanism.
Pre-merge Hook
ci/hooks/check_pr_merge_reviews.py
Implements a Python hook that intercepts gh pr merge commands, invokes the check script with a 30-second timeout, and blocks the merge if unresolved CodeRabbit reviews remain. Handles subprocess timeouts and missing executables gracefully.
Review Addressor CLI
ci/tools/coderabbit_addressor.py
Implements a three-mode CLI tool (--plan, --reply, --check) that fetches CodeRabbit comments via GitHub API, classifies them by type (security-flag, valid-fix, style, false-positive), applies resolution heuristics, and provides both human-readable reporting and merge-blocking checks.

Sequence Diagram

sequenceDiagram
    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
Loading

Estimated Code Review Effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly Related PRs

Poem

🐰 Hops through reviews with eager eyes,
ClassifyFind bugs, mark as wise—
CodeRabbit comments, Claude replies,
Before merge, all threads resolve, no surprise! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding a new /address-reviews skill for CodeRabbit auto-loop integration with CI hooks.
Linked Issues check ✅ Passed The PR fully implements all coding requirements from issue #2266: fetch CodeRabbit comments [coderabbit_addressor.py], classify findings [Comment classification], apply fixes [--plan mode], reply to threads [--reply mode], and block merges on unresolved comments [check_pr_merge_reviews.py hook]. Safety limits (max 3 iterations, security-flag handling) are documented.
Out of Scope Changes check ✅ Passed All changes align with issue #2266 scope: skill documentation, pre-merge hook, CI tools, and workflow documentation. No modifications to unrelated systems like .coderabbit.yaml or GitHub Actions.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/claude-address-reviews-skill

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
ci/tools/coderabbit_addressor.py (1)

59-59: MAX_ITERATIONS is advertised but never enforced.

Both the skill doc ("Max 3 iterations per PR") and the workflow doc promise a hard cap, but MAX_ITERATIONS only ships as informational metadata in the plan payload (line 182). Nothing in check() or the hook counts prior /address-reviews runs, 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 having check() 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

📥 Commits

Reviewing files that changed from the base of the PR and between 83c9d46 and eba3b36.

📒 Files selected for processing (5)
  • .claude/settings.json
  • .claude/skills/address-reviews/SKILL.md
  • agents/docs/workflow.md
  • ci/hooks/check_pr_merge_reviews.py
  • ci/tools/coderabbit_addressor.py

Comment on lines +34 to +48
SECURITY_KEYWORDS = [
"security",
"cve",
" auth",
"credential",
"secret",
"rce",
"injection",
"critical",
"data loss",
"uaf",
"use-after-free",
"buffer overflow",
"out-of-bounds",
]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

" 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.

Comment on lines +146 to +155
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 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 -40

Repository: 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 2

Repository: 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:

  1. Use the GraphQL isResolved field directly, which GitHub exposes and is authoritative.
  2. 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.

Comment on lines +215 to +239
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ 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.

@zackees
zackees merged commit 2230aa4 into master Apr 18, 2026
7 of 82 checks passed
@zackees
zackees deleted the feat/claude-address-reviews-skill branch April 19, 2026 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(ci): AI-to-AI review loop — auto-address CodeRabbit reviews before merge

1 participant