From 0c1adb4877f344af8276d5277871e8056cef3ad5 Mon Sep 17 00:00:00 2001 From: ethernet Date: Wed, 15 Jul 2026 17:51:34 -0400 Subject: [PATCH] fix(ci): handle merge race in js-autofix poll loop (#65231) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the bot PR auto-merges, main moves — which the poll loop detects as 'main moved' and tries to close the PR. But the PR is already merged, so gh pr close fails with an error. Fix: when main moves, re-check PR state before closing. If it's already MERGED, exit cleanly. Also make gh pr close non-fatal (|| true) as a belt-and-suspenders guard against the same race on the other close paths. --- .github/workflows/js-autofix.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/js-autofix.yml b/.github/workflows/js-autofix.yml index ae6caab0f..ca9ec82aa 100644 --- a/.github/workflows/js-autofix.yml +++ b/.github/workflows/js-autofix.yml @@ -207,12 +207,17 @@ jobs: exit 0 fi - # If main moved, close the PR — the next workflow run re-applies - # on the current state. + # If main moved, the PR may have already merged (which moves + # main) or another commit landed. Re-check state first. CURRENT_SHA=$(gh api "repos/${{ github.repository }}/branches/main" --jq '.commit.sha') if [ "$CURRENT_SHA" != "$START_SHA" ]; then + STATE=$(gh pr view "$PR_NUM" --json state --jq '.state') + if [ "$STATE" = "MERGED" ]; then + echo "PR #$PR_NUM merged (main moved to $CURRENT_SHA)." + exit 0 + fi echo "Main moved ($START_SHA → $CURRENT_SHA). Closing stale PR." - gh pr close "$PR_NUM" --delete-branch + gh pr close "$PR_NUM" --delete-branch || true exit 0 fi