Skip to content

pr-merge-autopilot.sh consistently reports "Failed to merge" when merge actually succeeded #173

Closed

Description

@jobordu

Context

Over the course of 2026-05-12/13, every successful auto-merge via scripts/pr-merge-autopilot.sh printed:

```
[HH:MM:SS] Conditions met for merge
✗ Failed to merge PR #NNN
```

…immediately followed by GitHub showing the PR as merged with a real merge commit (PRs #157, #158, #159, #161, #162, #163, #164, #166 all hit this).

The autopilot's gh pr merge call seems to race against GitHub's auto-merge feature — by the time the script invokes gh pr merge --squash, the PR has already auto-merged (because all required checks went green during the polling loop), and the merge call returns non-zero because there's nothing left to merge.

This forced a manual gh pr view <n> after every autopilot run to confirm actual merge status, which defeats the autopilot's purpose.

Proposed solution

After the gh pr merge call returns non-zero, the script should:

  1. Re-query gh pr view <PR> --json state,mergedAt,mergeCommit
  2. If state === "MERGED" (regardless of merge-call exit code) → report success
  3. Only report failure if the PR is still OPEN after the merge attempt

The current behavior trusts the gh CLI's exit code as authoritative; the fix is to trust the GitHub server state instead.

Acceptance criteria

  • Race-merged PRs (auto-merged before script's merge call lands) report success, not failure
  • Genuinely-failed merges (e.g., still BLOCKED) continue to report failure with a clear reason
  • Exit code matches the actual server state

Activity

  1. added 3 commits that reference this issue on May 18, 2026
    c8d1f9b
    b1d7561
    6daaf30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions