Skip to content

ci(auto-update): wait for state to settle and surface real errors#5958

Merged
MarkusNeusinger merged 1 commit intomainfrom
claude/auto-update-pr-branches-fix
May 7, 2026
Merged

ci(auto-update): wait for state to settle and surface real errors#5958
MarkusNeusinger merged 1 commit intomainfrom
claude/auto-update-pr-branches-fix

Conversation

@MarkusNeusinger
Copy link
Copy Markdown
Owner

Summary

First run of `auto-update-pr-branches.yml` after #5957 found 0 BEHIND PRs even though three were stuck behind main (#5916, #5870, #5902). Two issues:

  1. Timing. The workflow runs ~4s after the push to main, but GitHub recomputes `mergeStateStatus` and the cached PR head SHA asynchronously. Right after the push the field is still UNKNOWN and the cached head can be stale → `update-branch` returns expected head sha didn't match current head ref. Add a 30s sleep at the start.
  2. Over-strict filter. The script only iterated PRs where `mergeStateStatus == "BEHIND"`, skipping UNKNOWN candidates — exactly the ones we wanted to fix. Drop the filter: after a push to main, every open auto-merge PR is behind, and `update-branch` is a no-op when the head is already up-to-date.

Also:

  • Bump permissions to `contents: write` (update-branch creates a merge commit on the head ref).
  • Drop `--silent` and capture stderr so the actual GitHub error lands in the log.

Verified manually: calling `PUT /pulls/{num}/update-branch` from the CLI on #5916 and #5870 worked and they auto-merged within seconds. The 422 on #5902 was a real history-divergence conflict (4 ahead / 58 behind / merge_base differs) — separate problem.

Test plan

  • After this merges, push something to main and confirm the workflow finds N>0 PRs (where N is open auto-merge PRs).
  • Confirm any genuinely stuck PR (conflict) gets a clear error in the log instead of `likely conflict or stale ref`.

Copilot AI review requested due to automatic review settings May 7, 2026 20:22
@MarkusNeusinger MarkusNeusinger enabled auto-merge (squash) May 7, 2026 20:22
@MarkusNeusinger MarkusNeusinger merged commit 9245686 into main May 7, 2026
8 checks passed
@MarkusNeusinger MarkusNeusinger deleted the claude/auto-update-pr-branches-fix branch May 7, 2026 20:22
The first run after #5957 merged found 0 BEHIND PRs even though three
PRs were stuck behind main. Two issues:

1. The workflow runs ~4s after the push to main, but GitHub
   recomputes `mergeStateStatus` and the cached PR head SHA
   asynchronously. Right after the push the field can still be
   "UNKNOWN" and the cached head can be stale. Add a 30s sleep at
   the start so GitHub has time to settle.

2. The script filtered for `mergeStateStatus == "BEHIND"` and
   skipped UNKNOWN candidates — exactly the ones we wanted to fix.
   Drop the filter: after a push to main, every open auto-merge PR
   is by definition behind, and update-branch is a no-op when the
   head is already up-to-date.

Also:
- Bump permissions to `contents: write` since update-branch creates
  a merge commit on the head ref.
- Drop `--silent` and capture stderr so the actual GitHub error
  (conflict, SHA mismatch, etc.) lands in the workflow log instead
  of the generic "likely conflict or stale ref" guess.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adjusts the Auto-update PR branches workflow to more reliably update auto-merge PR branches immediately after main advances, avoiding missed updates caused by GitHub’s asynchronous recomputation of PR merge state / cached head SHAs and improving error visibility in logs.

Changes:

  • Add an initial 30s delay to allow PR mergeability/head SHA state to settle after a push to main.
  • Iterate all open PRs with auto-merge enabled (instead of filtering strictly on mergeStateStatus == BEHIND), avoiding skips when the status is temporarily UNKNOWN.
  • Increase workflow token permissions to allow update-branch writes and capture/log real gh api errors (stderr) instead of suppressing them.

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