Skip to content

Fix PR auto-update to catch behind PRs with pending checks#142

Merged
mikepsinn merged 3 commits into
mainfrom
feature/fix-pr-autoupdate
Jul 25, 2026
Merged

Fix PR auto-update to catch behind PRs with pending checks#142
mikepsinn merged 3 commits into
mainfrom
feature/fix-pr-autoupdate

Conversation

@mikepsinn

@mikepsinn mikepsinn commented Jul 25, 2026

Copy link
Copy Markdown
Owner

Problem

update-pr-branches.yml is supposed to keep every open PR up to date with main so no one clicks "Update branch" by hand. But it only acted on PRs whose mergeStateStatus == BEHIND.

GitHub reports BEHIND only when a PR is behind main and otherwise mergeable (checks green, reviews satisfied, no conflicts). A behind PR with pending CI or unsatisfied reviews reports as UNSTABLE/BLOCKED, which masks the behind-ness. With ~20-minute CI plus bot reviewers, behind PRs are almost always non-clean right after a merge lands — so the workflow skipped exactly the PRs that a human then updates manually once checks settle.

Fix

Compute behind-ness directly from the compare API (behind_by > 0) instead of trusting the composite status. Now any behind, non-draft, conflict-free PR is auto-updated regardless of its check/review state. Conflicted PRs still fail cleanly and are listed as "needs human" in the job summary.

Notes

  • Draft PRs are now explicitly skipped (they shouldn't be force-updated).
  • Trigger unchanged (runs on every push to main). Takes effect once merged.

Summary by CodeRabbit

  • Bug Fixes
    • Improved detection of pull requests that are behind the main branch.
    • Prevented branch updates when comparison checks fail or branches are already up to date.
    • Enhanced job summaries to clearly record updated, skipped, and failed branch-update attempts.

The workflow only updated PRs whose mergeStateStatus was exactly BEHIND.
GitHub reports BEHIND only when a PR is behind AND otherwise mergeable;
a behind PR with pending CI or unsatisfied reviews reports as
UNSTABLE/BLOCKED, masking the behind-ness. With ~20-min CI plus bot
reviewers, behind PRs are almost always non-clean right after a merge
lands, so the workflow skipped exactly the PRs a human then updates by
hand.

Now compute behind-ness directly from the compare API (behind_by > 0)
and update any behind, non-draft, conflict-free PR regardless of its
check/review state.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 25, 2026 01:38
@vercel

vercel Bot commented Jul 25, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
optimitron-web Ready Ready Preview, Comment Jul 25, 2026 5:18pm

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@mikepsinn, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 59 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: b7b1ec7f-a333-4af3-babe-d4209771f79e

📥 Commits

Reviewing files that changed from the base of the PR and between ed0a558 and 7ca5c57.

📒 Files selected for processing (1)
  • .github/workflows/update-pr-branches.yml
📝 Walkthrough

Walkthrough

The branch-update workflow now lists eligible pull requests, checks each branch against main through the GitHub Compare API, updates only branches with a positive behind_by value, and records comparison failures or up-to-date branches separately.

Changes

PR branch update workflow

Layer / File(s) Summary
Compare PR branches before updates
.github/workflows/update-pr-branches.yml
The workflow uses gh pr list and the Compare API to determine branch lag, skips up-to-date branches, records comparison failures, and updates only branches behind main.

Estimated code review effort: 3 (Moderate) | ~15–30 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Workflow as update-pr-branches.yml
  participant PRList as gh pr list
  participant CompareAPI as GitHub Compare API
  participant BranchUpdater as PR branch updater
  Workflow->>PRList: List open non-draft PRs
  PRList-->>Workflow: Return number and headRefName
  Workflow->>CompareAPI: Compare main...head
  CompareAPI-->>Workflow: Return behind_by
  alt behind_by greater than 0
    Workflow->>BranchUpdater: Update PR branch
  else up to date
    Workflow-->>Workflow: Record up-to-date skip
  end
Loading

Suggested reviewers: copilot

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: updating behind PR detection so auto-update catches PRs with pending checks.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix-pr-autoupdate

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.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ed0a558bf2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .github/workflows/update-pr-branches.yml Outdated

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

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/update-pr-branches.yml:
- Around line 38-40: Update the PR discovery loop around gh pr list to capture
its output and status before iterating, rather than executing it directly in
command substitution. If gh pr list fails, exit the workflow step with a
non-zero status; otherwise preserve the existing filtering and row iteration
behavior.
- Around line 39-42: Update the PR metadata query and row parsing in the
workflow loop to also retrieve each PR’s headRepositoryOwner, then construct the
compare API reference as main...<owner>:<head> instead of using headRefName
alone. Preserve the existing behind_by lookup and draft-PR filtering while
ensuring fork PR heads retain their repository ownership.
🪄 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 Plus

Run ID: 73214fe2-5564-4f2a-94cb-327d718a2ffa

📥 Commits

Reviewing files that changed from the base of the PR and between 538c9ed and ed0a558.

📒 Files selected for processing (1)
  • .github/workflows/update-pr-branches.yml

Comment thread .github/workflows/update-pr-branches.yml Outdated
Comment thread .github/workflows/update-pr-branches.yml Outdated
- Fail the job when PR discovery fails: capture `gh pr list` output/exit
  status before iterating instead of swallowing a failure inside `$(...)`,
  so an API/auth outage aborts the job loudly instead of reporting "no PRs
  to update".
- Qualify fork PR heads in the compare request: fetch headRepositoryOwner
  and compare against `<owner>:<branch>` when the head repo differs from
  the base repo, so a future fork PR compares its own commits instead of
  an unrelated same-named branch (or a 404) in the base repo.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@mikepsinn
mikepsinn enabled auto-merge July 25, 2026 17:09
@mikepsinn
mikepsinn merged commit 37c1308 into main Jul 25, 2026
11 of 13 checks passed
@mikepsinn
mikepsinn deleted the feature/fix-pr-autoupdate branch July 25, 2026 17:16
mikepsinn pushed a commit that referenced this pull request Jul 25, 2026
update-pr-branches.yml (merged in #142) pushes merge-from-main commits as
github-actions[bot]. claude-code-action hard-fails for non-human actors
("Workflow initiated by non-human actor"), so every auto-updated PR got a
red claude-review check the moment the auto-updater did its job — first
seen on PR #143 within a minute of #142 landing.

Skip the job for bot-triggered synchronize events instead of allowlisting
the bot: a merge from main leaves the PR diff unchanged, so re-reviewing
it would burn a full review run on nothing new.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Mf3c4CzpfCCqAQA2k4UQKH
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.

2 participants