Skip to content

server: fall back to direct merge when auto-merge hits "clean status"#58

Open
AntonNiklasson wants to merge 1 commit into
mainfrom
an/auto-merge-clean-status-fallback
Open

server: fall back to direct merge when auto-merge hits "clean status"#58
AntonNiklasson wants to merge 1 commit into
mainfrom
an/auto-merge-clean-status-fallback

Conversation

@AntonNiklasson

Copy link
Copy Markdown
Owner

Summary

When toggling auto-merge on a PR that's already in a mergeable state, GitHub's enablePullRequestAutoMerge mutation refuses to enqueue because there's nothing to wait on. Today that surfaces as a 500 in the dashboard. This change catches that specific error and falls through to a direct squash merge, matching the user's intent ("merge this").

Error response from server logs

Captured while clicking auto-merge on a PR that had already gone green:

GraphqlResponseError: Request failed due to following response errors:
 - Pull request Pull request is in clean status
    at .../packages/server/src/routes.ts:281:7
  errors: [
    {
      type: 'UNPROCESSABLE',
      path: [Array],
      locations: [Array],
      message: 'Pull request Pull request is in clean status'
    }
  ],
  data: { enablePullRequestAutoMerge: null },
  request: {
    query: 'mutation($id: ID!) { enablePullRequestAutoMerge(input: { pullRequestId: $id, mergeMethod: SQUASH }) { pullRequest { id } } }',
    variables: { id: 'PR_kwDOR3u_wM7dZnTn' }
  }

The existing handler only caught /auto.?merge is not allowed/i, so this clean status variant bubbled up unhandled.

Behavior

  • Auto-merge enable on a not-yet-mergeable PR: unchanged.
  • Auto-merge enable on an already-mergeable PR: now does a squash merge instead of erroring. Response is { ok: true, merged: true }.
  • merge_rejected errors from the fallback merge are surfaced the same way the dedicated /merge endpoint does.

Test plan

  • Click auto-merge on a PR with pending required checks → auto-merge enqueued as before.
  • Click auto-merge on a PR that's already green → PR is merged in one click; row disappears from the list.
  • Click auto-merge on a green PR with a branch-protection violation (e.g. unresolved conversation) → toast shows the actionable reason, no 500.

If a PR is already mergeable, GitHub's enablePullRequestAutoMerge mutation
returns UNPROCESSABLE ("Pull request Pull request is in clean status"),
because there's nothing for auto-merge to wait on. Match the error and
fall through to a direct squash merge so the click does the right thing.
@AntonNiklasson AntonNiklasson marked this pull request as ready for review May 20, 2026 08:46
Copilot AI review requested due to automatic review settings May 20, 2026 08:46

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.

Pull request overview

This PR updates the server’s POST /:instanceId/prs/:owner/:repo/:prNumber/auto-merge route to handle GitHub’s “Pull request is in clean status” GraphQL error by falling back to a direct squash merge, avoiding a 500 when a PR is already mergeable.

Changes:

  • Catch the “clean status” auto-merge enable error and perform a direct squash merge instead.
  • Surface merge rejection errors from the fallback merge as merge_rejected (422) with a flattened, user-actionable message.
  • Optimistically remove merged PRs from cached prs/reviews, record the mutation, and schedule a resync (including recent-prs).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

});
scheduleResync(instanceId, ["prs", "reviews", "recent-prs"]);

return c.json({ ok: true, merged: true });
Comment on lines +293 to +300
const fullRepo = `${owner}/${repo}`;
try {
await client.pulls.merge({
owner,
repo,
pull_number: num,
merge_method: "squash",
});
Comment on lines +290 to +294
// PR is already mergeable — GitHub refuses to queue auto-merge.
// Fall through to a direct squash merge to match user intent.
if (/clean status/i.test(msg)) {
const fullRepo = `${owner}/${repo}`;
try {
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