Skip to content

fix(pr-merge): skip a pull request whose auto-merge arm is refused instead of failing the run - #9680

Merged
kyle-sexton merged 4 commits into
mainfrom
fix/pr-merge-skip-refused-arm
Oct 24, 2026
Merged

kyle-sexton merged 4 commits into
mainfrom
fix/pr-merge-skip-refused-arm

Conversation

@kyle-sexton

@kyle-sexton kyle-sexton commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Closes #9620

Summary

When GitHub refused to arm auto-merge on one pull request, or the arm kept failing on the network, enable-auto-merge failed the whole step, so a single bad candidate turned the merge lane red on every run. Now that pull request gets a warning naming the reason, it is skipped for this run, and the other candidates still get armed. The run still fails when no arm lands, or when the error hits every pull request alike.

Fix

In .github/scripts/pr-merge/enable-auto-merge.mjs:

  • Per-PR refusal. refused(error, runWide) treats an error as GitHub refusing one pull request when it is a GitHubError with GraphQL errors (status 200) or any 4xx except 401, 403 and 429. It is never a refusal when the answer is run-wide:

    • rate-limited by header (x-ratelimit-remaining: 0 or retry-after), which main reads through createGitHub's onResponse;
    • or a GraphQL error typed RATE_LIMITED, FORBIDDEN or INSUFFICIENT_SCOPES.

    GitHub's docs say a primary GraphQL rate limit answers 200 with errors. A refusal logs ::warning title=enable-auto-merge::#N arm refused, skipped this run: <status line>: <GitHub's messages>.

  • Per-PR network failure. The issue's case is run 40058246788, which logged ##[error]#9540 arm: fetch failed, a TypeError with no cause. An arm that still fails on the network after the existing resends logs ::warning title=enable-auto-merge::#N arm failed on the network after its resends, skipped this run: <error>. Why fix(planning): brief TLDR reads "1 question" for a single question #9540 failed this way is unknown; it has since merged.

  • In-flight slots. withRetry tags each error it throws with its send count (attempts). Only a refusal on the first send frees the pull request's merge.max-in-flight slot. A refusal after a resend, or a network failure, keeps the slot counted, because an earlier send may have landed. The next run counts it again from autoMergeRequest.

  • When the run fails. It fails when no arm in it landed and either every arm failed on the network, or two or more arms ran and each one failed without a reason of its own: a network failure, a 404, or GraphQL errors that name no type. Such failures may be the run's own fault, for example a wrong API URL. Refusals that name their reason, such as a 422 or a typed GraphQL error, belong to each pull request, so two pull requests refused for their own reasons keep the run green. A single refused arm stays green. Either way, a summary line every arm this run failed: #a, #b is written, as an error or a warning to match the outcome.

  • Unchanged. Network errors keep the full-jitter resend. A 401, 403, 429 or 5xx answer, a failed disarm and a failed pin still fail the run. check-trusted-trigger is unchanged.

Verification

  • Every new test was written first and failed on the code before its fix. After the fix, each test checks:
    • a refusal on the first send is skipped with a warning, and the run stays green;
    • one of two refused on the first send: the other still arms at cap 1;
    • two arms each refused with a 422: warnings, and the run stays green;
    • two arms both answered 404: the run fails;
    • the warning carries GitHub's message;
    • one arm fails on the network every attempt while another arms: green, with a warning;
    • both arms fail on the network: the run fails;
    • a lone arm fails on the network: the run fails;
    • a network-failed arm keeps its slot at cap 1, so the second pull request is not armed;
    • a refusal after a resend keeps its slot at cap 1;
    • GraphQL answers typed RATE_LIMITED, FORBIDDEN and INSUFFICIENT_SCOPES fail the run and are not counted as refusals.
  • The rate-limit and type checks run through main's real client against a stubbed fetch. The header rate-limit test carries no error type, so the headers alone decide it. Guard tests keep 401, 403, 429 and 502 red with no resend.
  • node --test .github/scripts/pr-merge/*.test.mjs: 336 pass, 0 fail. scripts/check-affected.sh --tests: 9 passed, 5 skipped.
  • Left out: a live run against GitHub, since there is no failing pull request to arm.

Related

🤖 Generated with Claude Code

…stead of failing the run

GitHub refusing one pull request's arm (a GraphQL error or a 4xx other
than 401, 403 and 429, and not rate-limited) is now a warning carrying
GitHub's message; that pull request is skipped this run, its slot under
merge.max-in-flight is released, and the other candidates are still
armed. The step stays green, with a summary warning when every arm was
refused. Network errors keep the existing resend, and a 401, 403, 429,
5xx or rate-limited answer still fails the run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DUS7XB8hUjcDnuSYLqJRzd
@kyle-sexton
kyle-sexton marked this pull request as ready for review October 24, 2026 16:26
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-24T16:29:14.776048Z d588220 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 41cdb9944b4bb6d599c7de2a3526b2e829d53031: 0 finding(s), 0 as inline comments.

No security issues found in the incremental change (enable-auto-merge.mjs and its test file, since c2f8018).

I read the incremental diff and the PR context, and checked the answer handling in main against the file at the head SHA.

  • merge.max-in-flight cap. The new accounting errs toward counting more merges as in flight, never fewer. A slot is freed only when GitHub refused on the first send (error.attempts === 1). A refusal after a resend, or a network failure, keeps the slot, because an earlier send may have landed. This closes a path where a lost response could let the cap be exceeded. Tests cover both cases.
  • Run-wide errors. RATE_LIMITED, FORBIDDEN and INSUFFICIENT_SCOPES GraphQL error types, and rate-limit headers, are never treated as a per-PR refusal. A token or permission failure therefore still fails the run instead of being skipped with a warning. A 404, or GraphQL errors with no type, count as "unexplained". Two or more of those arms in a run, with none landing, fail the run.
  • Stale answer. answer is the newest response, and refused() only accepts a GitHubError built from a response. Within refused(), the parsed body therefore belongs to the arm that failed, not to an earlier call.
  • error.attempts tagging. It only adds a number to the error object when the error is an object. It sets no control flow other than the slot check above.
  • Holds and disarm. The hold, disarm and pin failure paths are untouched, and a failed disarm still fails the run.
  • Input handling. answerBody parses GitHub's response with JSON.parse inside a try/catch, and the messages it returns go into the existing escapeCommand and describe paths for workflow-command output. This diff adds no new injection surface.
  • Manifests and instruction surfaces. The change touches no plugin manifest, trusted-actors path, CODEOWNERS, .gitmodules or standing instruction file. No manifest <field> lines apply.
  • PR context. The PR context contained no embedded directives.

critical-findings: 0

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

claude-review: 1 inline finding(s) on d588220f4c92a438c321317bb180486ad55c630e; the summary is in this lane's pull request comment.

claude-lane: claude-review

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

claude-review reviewed 41cdb9944b4bb6d599c7de2a3526b2e829d53031: 0 finding(s), 0 as inline comments.

Incremental review of .github/scripts/pr-merge/enable-auto-merge.mjs and its test file, covering the change since c2f8018. I found nothing that meets the high-signal bar.

I only read the code; I did not run the tests. The PR body reports 335 passing tests, which is author-claimed and unverified by me.

What I checked:

  • Slot accounting. withRetry now sets error.attempts on the error it throws. An arm refused on its first send frees its inFlight slot. An arm refused after a resend, or one that failed on the network, keeps the slot. The attempts assignment sits on the single throw path, so a final transient failure gets attempts = 3 and a non-transient error gets its own attempt count. main always wraps github in withRetry, so attempts is always set when main reads it. The ?? 1 fallback is only defensive.
  • Run-wide detection. answerBody reads the newest response. Only a GitHubError carries a response, so the stale-answer case (a network error right after an earlier answered call) never reaches refused. RATE_LIMITED, FORBIDDEN and INSUFFICIENT_SCOPES types, and the rate-limit headers, route to the error path and fail the run.
  • Outage rule. The run fails when no arm landed and either all arms failed on the network, or two or more arms failed with no reason of their own (network, 404, or untyped GraphQL errors). Refusals that name a reason stay green. This matches the PR description. I checked it against the new tests: lone network failure is red, one network failure plus one armed is green, two 422s are green, two 404s are red.
  • Removed answered tracking. A listing read that fails on the network still returns 1 through the outer catch in main. The earlier test for a run where no call answers was replaced by "every arm … failing on the network". That leaves the listing-read failure path without a dedicated test. It is pre-existing behaviour and the path is unchanged, so I'm not counting it as a finding.

Closing issue #9620: its body is omitted from the PR context. The one comment kept says the defect is confirmed and asks for a quick fix, and it states no acceptance criteria. Nothing to check against.

No plugin manifests changed, and no hold class applies: no model or API spend, no trusted-actor or CODEOWNERS files, no critical security finding.

…rk once the run has an answer

An arm that keeps failing on the network after its resends, in a run
where another GitHub call answered, is now a warning naming the pull
request and the error; that pull request is skipped and its in-flight
slot released, and the run stays green. A run where no call answered is
an outage and still fails red.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DUS7XB8hUjcDnuSYLqJRzd

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d588220f4c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

claude-review: 2 inline finding(s) on c2f8018113ddd959ea97b008f5733b59ffa7e89d; the summary is in this lane's pull request comment.

claude-lane: claude-review

kyle-sexton and others added 2 commits October 24, 2026 12:50
…a run where no arm landed

An arm that failed on the network, or was refused after a resend, keeps
its merge.max-in-flight slot, since an earlier send may have landed; only
a refusal on the first send frees it. withRetry tags each thrown error
with its send count. A run fails when every arm in it failed on the
network, or when two or more arms ran and none landed. A GraphQL error
typed RATE_LIMITED, FORBIDDEN or INSUFFICIENT_SCOPES is run-wide, never
a refusal of one pull request.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ason

Two or more arms all refused now fail the run only when every one failed
on the network, answered 404, or carried GraphQL errors that name no
type, which may be the run's own fault (a wrong API URL). Refusals that
name their reason, such as a 422, stay per pull request, so two pull
requests each refused for their own reason no longer keep the job red.
The header rate-limit test no longer carries a RATE_LIMITED type, so the
headers alone decide it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kyle-sexton
kyle-sexton added this pull request to the merge queue Oct 24, 2026
Merged via the queue into main with commit b19b7f0 Oct 24, 2026
72 of 75 checks passed
@kyle-sexton
kyle-sexton deleted the fix/pr-merge-skip-refused-arm branch October 24, 2026 18:45
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.

fix(pr-merge): enable-auto-merge retries a persistent arm failure on one PR as a network blip and fails every run

1 participant