From 652535412388b5ac613db9edf3fe01a3a90ffddf Mon Sep 17 00:00:00 2001 From: Mao Nakamoto <41178744+maonakamoto@users.noreply.github.com> Date: Fri, 14 Aug 2026 02:45:59 +0200 Subject: [PATCH] fix(ci): report why a PR could not be woken instead of guessing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The wake path read `mergeable` from the cached `gh pr list` payload. GitHub computes that lazily and invalidates it whenever the base moves — which is precisely when this workflow runs — so it is often UNKNOWN. A conflicted PR therefore slipped past the CONFLICTING branch and was told it was "already current with main", pointing at close/reopen, which would not have helped. That is this file's own bug class: a skip line that reads plausible and sends the reader somewhere useless. So on failure, ask GitHub for the real mergeable state and name the actual reason — conflict, or genuinely current. One extra API call on a path that only runs when a wake has already failed. Co-Authored-By: Claude Opus 5 (1M context) --- scripts/ci/auto-merge-sweep.sh | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/scripts/ci/auto-merge-sweep.sh b/scripts/ci/auto-merge-sweep.sh index 2bc31ae..890627b 100644 --- a/scripts/ci/auto-merge-sweep.sh +++ b/scripts/ci/auto-merge-sweep.sh @@ -224,12 +224,24 @@ for number in $(printf '%s' "$prs_json" | jq -r 'sort_by(.number) | .[].number') echo "- 🔁 #${number} had no checks and was woken; CI is running now — ${title}" >> "$GITHUB_STEP_SUMMARY" fi else - # Already level with the base, so there is nothing to merge in and - # no push to make. Close/reopen is the only remaining trigger, and - # that is a human's call — say so instead of retrying every sweep. - echo "[auto-merge] #${number} could not be woken (already current with ${BASE_BRANCH}?) — close/reopen it to force checks: ${title}" >&2 + # update-branch refuses for two unrelated reasons, and guessing + # between them is how this file's whole class of bug starts. The + # cached mergeable above can be UNKNOWN (GitHub recomputes it + # lazily, and it is invalidated every time the base moves — i.e. + # exactly when this workflow runs), so a conflicted PR can reach + # here and get told it is "already current". Ask for the real + # reason rather than print a plausible one. + why=$(gh pr view "$number" --repo "$REPO" --json mergeable --jq '.mergeable' 2>/dev/null || echo UNKNOWN) + if [ "$why" = "CONFLICTING" ]; then + reason="it conflicts with ${BASE_BRANCH} — resolve the conflict (or \`@dependabot recreate\`)" + else + # Nothing to merge in, so there is no push to make. Close/reopen + # is the only remaining trigger, and that is a human's call. + reason="it is already current with ${BASE_BRANCH} — close/reopen it to force checks" + fi + echo "[auto-merge] #${number} has no checks and could not be woken: ${reason} — ${title}" >&2 if [ -n "${GITHUB_STEP_SUMMARY:-}" ]; then - echo "- ⚠️ #${number} has no checks and could not be woken — close/reopen it to force CI — ${title}" >> "$GITHUB_STEP_SUMMARY" + echo "- ⚠️ #${number} has no checks and could not be woken: ${reason} — ${title}" >> "$GITHUB_STEP_SUMMARY" fi fi fi