Skip to content

fix: auto-recover on merge-pr pre-flight failures#249

Merged
bd73-com merged 5 commits intomainfrom
claude/optimize-command-handling-8Rt1w
Mar 22, 2026
Merged

fix: auto-recover on merge-pr pre-flight failures#249
bd73-com merged 5 commits intomainfrom
claude/optimize-command-handling-8Rt1w

Conversation

@bd73-com
Copy link
Owner

@bd73-com bd73-com commented Mar 22, 2026

Summary

The /merge-pr command 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-pr automatically take recovery actions for each failure type.

Changes

  • Auto-request reviewers: When reviewDecision is empty/not approved, the command now fetches repo collaborators, excludes the PR author, and requests a review from the first available collaborator
  • Status check guidance: Lists specific failed/pending checks and tells the user whether to wait or investigate
  • Conflict handling: Directs user to rebase locally when merge state is CONFLICTING
  • Missing label recovery: Offers to add the release label via gh pr edit instead of just reporting it missing
  • Bug fixes: Added --repo bd73-com/fetchthechange to all gh commands (was missing), added url to the JSON query, and accepted CLEAN as a valid mergeStateStatus

How to test

  1. Open a PR that has no approvals and run /merge-pr
  2. Verify it reports the failure and automatically requests a reviewer
  3. Open a PR with all checks passing and approval — verify it still merges normally
  4. Open a PR missing a release label — verify it asks which label to add and offers to apply it

https://claude.ai/code/session_01LQjQRCbNWpNwEHxpcQTUYR

Summary by CodeRabbit

  • Chores
    • Updated merge workflow documentation to query PR status with additional fields (including PR URL and author).
    • Enhanced pre-flight evaluation to assess all checks and produce a summary table; broadened accepted merge-state logic and explicitly treat draft, unstable, dirty, behind, and blocked as failing conditions.
    • Expanded failure-handling guidance with automatic recovery actions: request missing reviews, report status-check failures/pending, direct conflict resolution, and prompt adding missing release labels.

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
@github-actions github-actions bot added the fix label Mar 22, 2026
@coderabbitai
Copy link

coderabbitai bot commented Mar 22, 2026

Warning

Rate limit exceeded

@bd73-com has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 2 minutes and 53 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 48caae14-6dd6-4e21-8c39-0250a8208962

📥 Commits

Reviewing files that changed from the base of the PR and between ec863c2 and 8c8d75d.

📒 Files selected for processing (1)
  • .claude/commands/merge-pr.md
📝 Walkthrough

Walkthrough

Updates .claude/commands/merge-pr.md to query PR status from bd73-com/fetchthechange, request url and author in gh pr view JSON, evaluate all pre-flight checks and report a summary table, change gating to accept CLEAN or HAS_HOOKS (treat DIRTY, BEHIND, BLOCKED, DRAFT, UNSTABLE as failures), and replace abort-on-first-failure with structured recovery actions.

Changes

Cohort / File(s) Summary
Merge PR Command Documentation
​.claude/commands/merge-pr.md
Query PR status from bd73-com/fetchthechange; add --repo bd73-com/fetchthechange to merge flow. Request additional JSON fields (url, author). Replace abort-on-first-check with evaluation of all checks and a summary table. Change merge gating to accept CLEAN or HAS_HOOKS; treat DIRTY, BEHIND, BLOCKED, DRAFT, UNSTABLE as failures. Add explicit handling: request collaborator review if reviewDecision missing/not APPROVED, report statusCheckRollup FAILURE/PENDING, instruct conflict resolution for DIRTY, and prompt adding missing release label via gh pr edit --add-label.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: implementing automatic recovery actions for merge-pr pre-flight check failures instead of aborting.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/optimize-command-handling-8Rt1w

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[bot]
coderabbitai bot previously requested changes Mar 22, 2026
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 74c91ee and da5969b.

📒 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
coderabbitai[bot]
coderabbitai bot previously requested changes Mar 22, 2026
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (2)
.claude/commands/merge-pr.md (2)

19-19: ⚠️ Potential issue | 🟡 Minor

Add 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 APPROVED

Apply 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 | 🟠 Major

Enumerate 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

📥 Commits

Reviewing files that changed from the base of the PR and between da5969b and 01453ac.

📒 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
@bd73-com bd73-com dismissed stale reviews from coderabbitai[bot] and coderabbitai[bot] March 22, 2026 15:20

All review comments addressed in commit ec863c2

coderabbitai[bot]
coderabbitai bot previously requested changes Mar 22, 2026
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
.claude/commands/merge-pr.md (1)

5-5: ⚠️ Potential issue | 🟠 Major

Auto-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-reviewer to 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

📥 Commits

Reviewing files that changed from the base of the PR and between 01453ac and ec863c2.

📒 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
@bd73-com bd73-com dismissed coderabbitai[bot]’s stale review March 22, 2026 15:32

All comments addressed in 321f7e2

@bd73-com bd73-com merged commit ace217e into main Mar 22, 2026
2 checks passed
@bd73-com bd73-com deleted the claude/optimize-command-handling-8Rt1w branch March 22, 2026 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants