fix: auto-recover on merge-pr pre-flight failures#249
Conversation
Instead of just reporting failures and stopping, the command now takes automatic recovery actions: requests a reviewer when approval is missing, suggests next steps for failing/pending checks, and offers to add missing release labels. Also adds --repo flag and fetches the PR URL for context. https://claude.ai/code/session_01LQjQRCbNWpNwEHxpcQTUYR
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughUpdates Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.claude/commands/merge-pr.md:
- Line 19: The markdown headings in the "Handling failures" section need a blank
line before each level-3 heading; specifically add an empty line immediately
above "### reviewDecision is empty or not APPROVED" and likewise before the
other level-3 headings in that section so each subsection heading is separated
by a blank line for proper linting and rendering.
- Around line 33-34: Clarify the placeholder in the missing-release-label
instruction: update the guidance that `gh pr edit <number> --repo
bd73-com/fetchthechange --add-label <label>` uses `<number>` as the PR number
obtained from the step 1 JSON query (the PR id field returned by that query) so
users know to substitute that value rather than a commit or branch name; mention
explicitly to extract the `number`/`id` field from the step 1 output and use it
in the `gh pr edit` command.
- Around line 19-24: The auto-request logic must actually filter collaborators
and handle edge cases: first fetch the PR JSON (use gh api
repos/.../pulls/<number> to get .number, .user.login and .requested_reviewers),
fetch collaborators with gh api repos/.../collaborators --jq '.[].login', then
compute eligible reviewers using jq to exclude the PR author and any logins
already in .requested_reviewers (e.g. combine/join lists and filter out
matches); if the resulting list is empty, return a clear message to the user
instead of calling gh pr edit; otherwise call gh pr edit --repo <repo>
--add-reviewer <login> using the actual .number from the PR JSON. Ensure all
steps reference the PR's "number" field and handle the case where the author is
the only collaborator or all collaborators were already requested by not
attempting to add an invalid reviewer.
- Line 9: The doc/logic incorrectly treats MERGEABLE as a valid GitHub GraphQL
mergeStateStatus value; update any checks or mappings that reference
mergeStateStatus (e.g., code or docs that test for "MERGEABLE") to use only
valid enum values (such as "CLEAN") or implement a mapping layer that translates
older/REST statuses to GraphQL ones; specifically search for uses of
mergeStateStatus and replace acceptance of "MERGEABLE" with "CLEAN" or add
explicit handling that maps "MERGEABLE" -> "CLEAN"/other valid enum values
before using the GraphQL response.
🪄 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: ASSERTIVE
Plan: Pro
Run ID: dbd05214-4d99-4d19-b4b4-57b128cf5776
📒 Files selected for processing (1)
.claude/commands/merge-pr.md
- Replace invalid MERGEABLE with valid mergeStateStatus enum values (CLEAN, HAS_HOOKS) per GitHub GraphQL API spec - Rename CONFLICTING to DIRTY to match actual enum - Add edge case handling for reviewer auto-request when no eligible collaborators exist - Improve jq filtering to exclude PR author from collaborator list https://claude.ai/code/session_01LQjQRCbNWpNwEHxpcQTUYR
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (2)
.claude/commands/merge-pr.md (2)
19-19:⚠️ Potential issue | 🟡 MinorAdd blank lines before subsection headings.
Each level-3 heading in the "Handling failures" section needs a blank line immediately before it to comply with markdown formatting standards and ensure proper rendering.
📐 Proposed formatting fix
If a pre-flight check fails, report exactly which check failed. Do NOT retry or attempt to bypass branch protection. Then take **automatic recovery actions** based on the failure type: + ### reviewDecision is empty or not APPROVEDApply the same pattern before lines 26, 31, and 34.
Also applies to: 26-26, 31-31, 34-34
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.claude/commands/merge-pr.md at line 19, Add a single blank line immediately before each level-3 heading in the "Handling failures" section: ensure there is an empty line before the "### reviewDecision is empty or not APPROVED" heading and do the same for the other level-3 headings referenced at lines 26, 31, and 34 so all subsection headings have a blank line above them to match Markdown formatting standards.
34-35: 🛠️ Refactor suggestion | 🟠 MajorEnumerate valid release labels for clarity.
The instruction should explicitly list the valid release labels from the project's release-drafter configuration to guide the user's choice. Additionally, clarify that
<number>refers to the PR number from step 1's JSON output.📝 Proposed improvement
### Missing release label -- Ask the user which label to apply and offer to add it: `gh pr edit <number> --repo bd73-com/fetchthechange --add-label <label>`. +- Ask the user which label to apply (`breaking`, `feature`, `fix`, `chore`, `docs`, or `security`) and offer to add it: `gh pr edit <number> --repo bd73-com/fetchthechange --add-label <label>` (replace `<number>` with the PR number from step 1, and `<label>` with the user's choice).Based on learnings, PRs must carry one of the following release labels:
feature,fix,breaking,chore,docs,security.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.claude/commands/merge-pr.md around lines 34 - 35, Update the "Missing release label" instruction to enumerate the allowed release labels and clarify the PR number placeholder: state that PRs must have one of these labels — feature, fix, breaking, chore, docs, security — and show the edit command using the PR number from step 1's JSON output (i.e., replace <number> with that PR number) when suggesting the gh pr edit --add-label invocation referenced in the existing text.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.claude/commands/merge-pr.md:
- Line 5: The gh CLI JSON query used by the gh pr view command is missing the
required author field referenced by the auto-recovery logic; update the gh pr
view --json invocation (the command on the first line) to request the "author"
property as well so the subsequent code that excludes the PR author (referenced
as "author" or "user" in the auto-recovery logic) can read it without runtime
errors.
---
Duplicate comments:
In @.claude/commands/merge-pr.md:
- Line 19: Add a single blank line immediately before each level-3 heading in
the "Handling failures" section: ensure there is an empty line before the "###
reviewDecision is empty or not APPROVED" heading and do the same for the other
level-3 headings referenced at lines 26, 31, and 34 so all subsection headings
have a blank line above them to match Markdown formatting standards.
- Around line 34-35: Update the "Missing release label" instruction to enumerate
the allowed release labels and clarify the PR number placeholder: state that PRs
must have one of these labels — feature, fix, breaking, chore, docs, security —
and show the edit command using the PR number from step 1's JSON output (i.e.,
replace <number> with that PR number) when suggesting the gh pr edit --add-label
invocation referenced in the existing text.
🪄 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: ASSERTIVE
Plan: Pro
Run ID: cdaba1ea-655a-4429-964d-382b32e75ec7
📒 Files selected for processing (1)
.claude/commands/merge-pr.md
… enumerate labels - Add `author` to gh pr view --json fields for reviewer auto-request logic - Add blank lines after ### headings (MD022 compliance) - Enumerate valid release labels in missing-label recovery section https://claude.ai/code/session_01LQjQRCbNWpNwEHxpcQTUYR
All review comments addressed in commit ec863c2
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
.claude/commands/merge-pr.md (1)
5-5:⚠️ Potential issue | 🟠 MajorAuto-reviewer recovery can re-select already requested reviewers and fail idempotency
The flow excludes only author, not existing requested reviewers. That can cause
gh pr edit --add-reviewerto fail/no-op and break auto-recovery.Proposed doc fix
-1. Run `gh pr view --repo bd73-com/fetchthechange --json number,url,state,reviewDecision,mergeStateStatus,statusCheckRollup,labels,author` to check the PR's current status. +1. Run `gh pr view --repo bd73-com/fetchthechange --json number,url,state,reviewDecision,mergeStateStatus,statusCheckRollup,labels,author,requestedReviewers` to check the PR's current status. ... -2. Fetch repo collaborators, excluding the PR author: `gh api repos/bd73-com/fetchthechange/collaborators --jq '[.[].login] | map(select(. != "AUTHOR_LOGIN")) | first'` (replace `AUTHOR_LOGIN` with the actual author login). +2. Fetch repo collaborators and exclude both PR author and already-requested reviewers; pick first eligible login. + (Use `author.login` and `requestedReviewers[].login` from step 1 when filtering.)Does `gh pr view --json` support `requestedReviewers` for pull requests, and what is the exact JSON shape (especially reviewer login fields)?Also applies to: 21-24
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.claude/commands/merge-pr.md at line 5, The current PR status command doesn't fetch existing requested reviewers so the auto-recovery can re-add them; update the gh query to include requestedReviewers (e.g., change the --json list used in gh pr view to include requestedReviewers) and in the recovery logic that calls gh pr edit --add-reviewer filter out any reviewers whose requestedReviewers[].login matches the users you would add (use the login field from requestedReviewers) as well as the author, ensuring you only call gh pr edit --add-reviewer for truly new reviewer logins.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.claude/commands/merge-pr.md:
- Line 10: Update the "exactly one release label" recovery flow to handle
multiple labels: detect if a PR has more than one of the allowed labels
(feature, fix, breaking, chore, docs, security), prompt the user to choose which
single label to keep, remove all other release labels, and then re-run the label
check; implement this additional recovery path alongside the existing "missing
label" recovery so the merge gate enforces and recovers to exactly one release
label.
---
Duplicate comments:
In @.claude/commands/merge-pr.md:
- Line 5: The current PR status command doesn't fetch existing requested
reviewers so the auto-recovery can re-add them; update the gh query to include
requestedReviewers (e.g., change the --json list used in gh pr view to include
requestedReviewers) and in the recovery logic that calls gh pr edit
--add-reviewer filter out any reviewers whose requestedReviewers[].login matches
the users you would add (use the login field from requestedReviewers) as well as
the author, ensuring you only call gh pr edit --add-reviewer for truly new
reviewer logins.
🪄 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: ASSERTIVE
Plan: Pro
Run ID: e80a959c-66cd-4eb6-83fa-8b880188d587
📒 Files selected for processing (1)
.claude/commands/merge-pr.md
…-requested reviewers - Auto-reviewer recovery now excludes already-requested reviewers from candidates - Added "Multiple release labels" recovery section for the exactly-one-label gate https://claude.ai/code/session_01LQjQRCbNWpNwEHxpcQTUYR
All comments addressed in 321f7e2
Summary
The
/merge-prcommand previously stopped cold when a pre-flight check failed, only telling the user what went wrong without taking any action. This made the workflow tedious — you'd have to manually request reviewers, look up the PR URL, or figure out which check failed. This PR makes/merge-prautomatically take recovery actions for each failure type.Changes
reviewDecisionis empty/not approved, the command now fetches repo collaborators, excludes the PR author, and requests a review from the first available collaboratorCONFLICTINGgh pr editinstead of just reporting it missing--repo bd73-com/fetchthechangeto allghcommands (was missing), addedurlto the JSON query, and acceptedCLEANas a validmergeStateStatusHow to test
/merge-prhttps://claude.ai/code/session_01LQjQRCbNWpNwEHxpcQTUYR
Summary by CodeRabbit