Skip to content

fix(bin): retry fm-pr-merge a bounded number of times when GitHub mergeable is UNKNOWN - #6110

Merged
kunchenguid merged 2 commits into
kunchenguid:mainfrom
karotkriss:fm/fm-up-6020-pr-merge-mergeable-unknown
Sep 29, 2026
Merged

kunchenguid merged 2 commits into
kunchenguid:mainfrom
karotkriss:fm/fm-up-6020-pr-merge-mergeable-unknown

Conversation

@karotkriss

@karotkriss karotkriss commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Fixes #6020

bin/fm-pr-merge.sh refuses a GitHub merge whenever the pull request's mergeable field is not literally MERGEABLE.
GitHub reports UNKNOWN for a short while after a push or a base-branch change while it recomputes mergeability, so a green, conflict-free pull request is refused as if it could not be merged.
The merge gate should retry a bounded number of times when mergeable is UNKNOWN, re-reading and re-checking every live condition on each attempt, and when the bound is spent it should say mergeability is still being computed rather than calling the pull request unmergeable.
Every other refusal (closed, draft, conflicting, red or missing checks, away authority, queue protection) stays exactly as it is and is never retried.

What Changed

  • github_verify_mergeable in bin/fm-pr-merge.sh now returns 3 instead of 1 when mergeable=UNKNOWN is the only failing condition. Every other refusal (closed, draft, conflicting or DIRTY, red or missing checks, and the rest) still returns 1 and is never retried.
  • The GitHub merge path makes up to 5 attempts, waiting FM_PR_GITHUB_MERGEABLE_RETRY_DELAY seconds between them (default 3). Each attempt re-reads the live PR view and re-checks every condition. If the bound runs out, the script prints mergeability for <url> is still being computed by GitHub; retry shortly instead of calling the PR unmergeable, and still exits 1.
  • tests/fm-pr-merge.test.sh now has a gh stub that can serve a different mergeable value on each read, plus three new cases:
    • UNKNOWN then MERGEABLE merges after exactly 2 reads.
    • UNKNOWN on every read stops after 5 reads, reports the pending message and never runs pr merge.
    • CONFLICTING is refused at once, with no retry and no pending message.

Risk Assessment

✅ Low: The change is small and well-bounded. github_verify_mergeable returns 3 only when mergeable=UNKNOWN is the sole failing condition. The caller re-runs the full live read at most 5 times and then exits 1 with a message saying mergeability is still being computed. Other refusals (closed, draft, DIRTY, red or missing checks, unreadable reads) still return 1 immediately with unchanged text. The away-authority and queue-protection gates still run once, before or after the loop, and are never retried. The behavioral tests drive the script through gh mocks and cover three cases: UNKNOWN resolving to MERGEABLE, UNKNOWN never resolving, and CONFLICTING not being retried.

Testing

I ran the targeted tests/fm-pr-merge.test.sh suite (all passing), then drove the real merge script end to end against a disposable fake GitHub forge in throwaway state directories. Covered: UNKNOWN resolving after 1, 2 or 4 retries; UNKNOWN that never resolves; UNKNOWN combined with every other refusal; a check turning red mid-retry; CONFLICTING; unreadable mergeable; an unreadable away record; and away-mode merge-queue protection. I also measured the default-delay timing: about 5s for one retry, and about 14s to exhaust the bound with 5 reads. The base commit's script reproduces the reported refusal on the same fixtures. Every scenario matched the intent, and the worktree is left clean. No real GitHub pull request was used, because producing an UNKNOWN window would mean creating and pushing a public pull request.

  • Live validation: ✅ go - 7 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Green, conflict-free PR reads UNKNOWN briefly, then MERGEABLE: the merge gate retries and merges exactly once ✅ pass live scenarios-transcript.txt: unknown-twice-then-mergeable exit=0 reads=3 merge calls=1; unknown-four-then-mergeable-on-5th exit=0 reads=5 merge calls=1; timing-default-delay.txt: unknown-once exit=0 in 4…
Mergeable stays UNKNOWN: the bound is spent after 5 reads, no merge is attempted, and the error says mergeability is still being computed rather than calling the PR unmergeable ✅ pass live scenarios-transcript.txt: unknown-forever exit=1 reads=5 merge calls=0, stderr only 'mergeability ... is still being computed by GitHub; retry shortly'; timing-default-delay.txt shows 13.7s total with…
Before the fix, a single UNKNOWN read is refused as unmergeable (bug reproduction) ✅ pass live before-fix-base-commit.txt: the base-commit script exits 1 after 1 read with 'mergeable is "UNKNOWN", not MERGEABLE'
Adversarial: a check turns red during the UNKNOWN retry, the next attempt re-checks every condition, refuses naming the red check, and no merge is sent ✅ pass live scenarios-transcript.txt: unknown-then-check-turns-red and unknown-then-stays-unknown-check-turns-red exit=1 reads=2 merge calls=0, stderr names "check 'ci' is not green"
Adversarial: UNKNOWN combined with any other refusal (draft, red check, closed, DIRTY) is refused immediately with 1 read and no pending message ✅ pass live scenarios-transcript.txt: unknown-plus-draft/red-check/closed/dirty each exit=1 reads=1 merge calls=0, and each refusal lists both conditions
CONFLICTING or unreadable mergeable is refused immediately and never retried ✅ pass live scenarios-transcript.txt: conflicting and mergeable-unreadable exit=1 reads=1 merge calls=0 with the unchanged refusal wording
Away-authority and merge-queue-protection refusals are unchanged and never retried ✅ pass live scenarios-transcript.txt: an unreadable away record refuses with 0 reads; with away mode plus a merge queue, UNKNOWN resolves after 2 reads, then the queue refusal fires once with exit=2 and no merge
Evidence: Scenario transcripts (real fm-pr-merge.sh vs disposable fake forge)

Source: Scenario transcripts (real fm-pr-merge.sh vs disposable fake forge)

=== baseline-mergeable
mergeable sequence: MERGEABLE  retry delay: 0
exit=0  mergeable reads=1  merge calls=1  elapsed=1.7s
--- stderr:
  ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ●  WATCHER DOWN - SUPERVISION IS OFF
  ●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
  ●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
  ●  This is a supervision warning only; the guarded operation WILL still run.
  ●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
  ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  verified: https://github.com/example/repo/pull/6020 is open and mergeable, with every unwaived required check reported and every unwaived check green at head 6020602060206020602060206020602060206020

=== unknown-twice-then-mergeable
mergeable sequence: UNKNOWN UNKNOWN MERGEABLE  retry delay: 0
exit=0  mergeable reads=3  merge calls=1  elapsed=1.8s
--- stderr:
  ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ●  WATCHER DOWN - SUPERVISION IS OFF
  ●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
  ●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
  ●  This is a supervision warning only; the guarded operation WILL still run.
  ●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
  ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  verified: https://github.com/example/repo/pull/6020 is open and mergeable, with every unwaived required check reported and every unwaived check green at head 6020602060206020602060206020602060206020

=== unknown-four-then-mergeable-on-5th
mergeable sequence: UNKNOWN UNKNOWN UNKNOWN UNKNOWN MERGEABLE  retry delay: 0
exit=0  mergeable reads=5  merge calls=1  elapsed=1.9s
--- stderr:
  ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ●  WATCHER DOWN - SUPERVISION IS OFF
  ●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
  ●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
  ●  This is a supervision warning only; the guarded operation WILL still run.
  ●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
  ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  verified: https://github.com/example/repo/pull/6020 is open and mergeable, with every unwaived required check reported and every unwaived check green at head 6020602060206020602060206020602060206020

=== unknown-forever
mergeable sequence: UNKNOWN  retry delay: 0
exit=1  mergeable reads=5  merge calls=0  elapsed=1.7s
--- stderr:
  ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ●  WATCHER DOWN - SUPERVISION IS OFF
  ●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
  ●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
  ●  This is a supervision warning only; the guarded operation WILL still run.
  ●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
  ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  error: mergeability for https://github.com/example/repo/pull/6020 is still being computed by GitHub; retry shortly

=== unknown-then-check-turns-red
mergeable sequence: UNKNOWN MERGEABLE  retry delay: 0
exit=1  mergeable reads=2  merge calls=0  elapsed=1.6s
--- stderr:
  ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ●  WATCHER DOWN - SUPERVISION IS OFF
  ●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
  ●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
  ●  This is a supervision warning only; the guarded operation WILL still run.
  ●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
  ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  error: refusing to merge https://github.com/example/repo/pull/6020
    - check 'ci' is not green
  error: these checks are not green: ci

=== unknown-then-stays-unknown-check-turns-red
mergeable sequence: UNKNOWN UNKNOWN  retry delay: 0
exit=1  mergeable reads=2  merge calls=0  elapsed=1.6s
--- stderr:
  ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ●  WATCHER DOWN - SUPERVISION IS OFF
  ●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
  ●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
  ●  This is a supervision warning only; the guarded operation WILL still run.
  ●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
  ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  error: refusing to merge https://github.com/example/repo/pull/6020
    - check 'ci' is not green
    - mergeable is "UNKNOWN", not MERGEABLE
  error: these checks are not green: ci

=== unknown-plus-draft
mergeable sequence: UNKNOWN  retry delay: 0
exit=1  mergeable reads=1  merge calls=0  elapsed=1.5s
--- stderr:
  ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ●  WATCHER DOWN - SUPERVISION IS OFF
  ●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
  ●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
  ●  This is a supervision warning only; the guarded operation WILL still run.
  ●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
  ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  error: refusing to merge https://github.com/example/repo/pull/6020
    - the pull request is a draft
    - mergeable is "UNKNOWN", not MERGEABLE

=== unknown-plus-red-check
mergeable sequence: UNKNOWN  retry delay: 0
exit=1  mergeable reads=1  merge calls=0  elapsed=1.5s
--- stderr:
  ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ●  WATCHER DOWN - SUPERVISION IS OFF
  ●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
  ●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
  ●  This is a supervision warning only; the guarded operation WILL still run.
  ●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
  ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  error: refusing to merge https://github.com/example/repo/pull/6020
    - check 'ci' is not green
    - mergeable is "UNKNOWN", not MERGEABLE
  error: these checks are not green: ci

=== unknown-plus-closed
mergeable sequence: UNKNOWN  retry delay: 0
exit=1  mergeable reads=1  merge calls=0  elapsed=1.4s
--- stderr:
  ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ●  WATCHER DOWN - SUPERVISION IS OFF
  ●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
  ●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
  ●  This is a supervision warning only; the guarded operation WILL still run.
  ●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
  ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  error: refusing to merge https://github.com/example/repo/pull/6020
    - state is "CLOSED", not open
    - mergeable is "UNKNOWN", not MERGEABLE

=== unknown-plus-dirty
mergeable sequence: UNKNOWN  retry delay: 0
exit=1  mergeable reads=1  merge calls=0  elapsed=1.5s
--- stderr:
  ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ●  WATCHER DOWN - SUPERVISION IS OFF
  ●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
  ●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
  ●  This is a supervision warning only; the guarded operation WILL still run.
  ●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
  ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  error: refusing to merge https://github.com/example/repo/pull/6020
    - mergeStateStatus is DIRTY (conflicts)
    - mergeable is "UNKNOWN", not MERGEABLE

=== conflicting
mergeable sequence: CONFLICTING  retry delay: 0
exit=1  mergeable reads=1  merge calls=0  elapsed=1.4s
--- stderr:
  ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ●  WATCHER DOWN - SUPERVISION IS OFF
  ●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
  ●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
  ●  This is a supervision warning only; the guarded operation WILL still run.
  ●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
  ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  error: refusing to merge https://github.com/example/repo/pull/6020
    - mergeable is "CONFLICTING", not MERGEABLE

=== mergeable-unreadable
mergeable sequence: <static view>  retry delay: 0
exit=1  mergeable reads=1  merge calls=0  elapsed=1.5s
--- stderr:
  ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ●  WATCHER DOWN - SUPERVISION IS OFF
  ●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
  ●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
  ●  This is a supervision warning only; the guarded operation WILL still run.
  ●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
  ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  error: refusing to merge https://github.com/example/repo/pull/6020
    - mergeable is "unreadable", not MERGEABLE

=== unknown-then-mergeable-away-record-unreadable
mergeable sequence: UNKNOWN MERGEABLE  retry delay: 0
exit=1  mergeable reads=0  merge calls=0  elapsed=0.1s
--- stderr:
  error: PR merge refused - the away-posture record could not be read; nothing was merged

=== unknown-then-mergeable-away-queue-protection
mergeable sequence: UNKNOWN MERGEABLE  retry delay: 0
exit=2  mergeable reads=2  merge calls=0  elapsed=1.6s
--- stderr:
  ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ●  WATCHER DOWN - SUPERVISION IS OFF
  ●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
  ●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
  ●  This is a supervision warning only; the guarded operation WILL still run.
  ●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
  ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  verified: https://github.com/example/repo/pull/6020 is open and mergeable, with every unwaived required check reported and every unwaived check green at head 6020602060206020602060206020602060206020
  error: GitHub merge refused while away because the base branch's merge-queue state does not prove an immediate merge; nothing was handed to the forge
Evidence: Default 3s retry delay timing (bounded ~14s exhaust)

Source: Default 3s retry delay timing (bounded ~14s exhaust)

unknown-once-default-delay: exit=0 reads=2 merge calls=1 elapsed=4.8s unknown-forever-default-delay: exit=1 reads=5 merge calls=0 elapsed=13.7s error: mergeability for https://github.com/example/repo/pull/6020 is still being computed by GitHub; retry shortly

=== unknown-once-default-delay
mergeable sequence: UNKNOWN MERGEABLE  retry delay: default
exit=0  mergeable reads=2  merge calls=1  elapsed=4.8s
--- stderr:
  ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ●  WATCHER DOWN - SUPERVISION IS OFF
  ●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
  ●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
  ●  This is a supervision warning only; the guarded operation WILL still run.
  ●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
  ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  verified: https://github.com/example/repo/pull/6020 is open and mergeable, with every unwaived required check reported and every unwaived check green at head 6020602060206020602060206020602060206020

=== unknown-forever-default-delay
mergeable sequence: UNKNOWN  retry delay: default
exit=1  mergeable reads=5  merge calls=0  elapsed=13.7s
--- stderr:
  ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ●  WATCHER DOWN - SUPERVISION IS OFF
  ●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
  ●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
  ●  This is a supervision warning only; the guarded operation WILL still run.
  ●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
  ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  error: mergeability for https://github.com/example/repo/pull/6020 is still being computed by GitHub; retry shortly
Evidence: Before-fix reproduction on base commit 46d58d6

Source: Before-fix reproduction on base commit 46d58d6

unknown-twice-then-mergeable (base): exit=1 reads=1 merge calls=0 error: refusing to merge https://github.com/example/repo/pull/6020&#10;- mergeable is "UNKNOWN", not MERGEABLE

=== unknown-twice-then-mergeable
mergeable sequence: UNKNOWN UNKNOWN MERGEABLE  retry delay: 0
exit=1  mergeable reads=1  merge calls=0  elapsed=1.4s
--- stderr:
  error: refusing to merge https://github.com/example/repo/pull/6020
    - mergeable is "UNKNOWN", not MERGEABLE

=== unknown-forever
mergeable sequence: UNKNOWN  retry delay: 0
exit=1  mergeable reads=1  merge calls=0  elapsed=1.4s
--- stderr:
  error: refusing to merge https://github.com/example/repo/pull/6020
    - mergeable is "UNKNOWN", not MERGEABLE

=== conflicting
mergeable sequence: CONFLICTING  retry delay: 0
exit=1  mergeable reads=1  merge calls=0  elapsed=1.7s
--- stderr:
  error: refusing to merge https://github.com/example/repo/pull/6020
    - mergeable is "CONFLICTING", not MERGEABLE
Evidence: Targeted test file log

Source: Targeted test file log

ok - fm-pr-merge reports exact queue retry flags after a zero-exit false success
ok - fm-pr-merge omits merge-queue retry guidance for a closed GitHub PR
ok - fm-pr-merge aggregates agreeing merge-queue rules
ok - fm-pr-merge reports ambiguity for conflicting merge-queue rules
ok - fm-pr-merge records pr= and pr_head= for a verified GitHub merge
ok - fm-pr-merge records pr= before the forge call can land the merge
ok - fm-pr-merge propagates a real merge failure without silently succeeding
ok - fm-pr-merge refuses a GitHub merge call that leaves the PR open and unqueued
ok - fm-pr-merge retries a bounded number of times when mergeable is UNKNOWN and merges once it resolves
ok - fm-pr-merge reports mergeability still pending after its bounded UNKNOWN retry is spent
ok - fm-pr-merge refuses a genuine mergeable conflict immediately, without retrying
ok - fm-pr-merge keeps PR bookkeeping when it cannot read a successful merge call's outcome
ok - fm-pr-merge refuses with the forge's own output quoted apart from its verdict
ok - fm-pr-merge quotes the forge output when it cannot read the outcome either
ok - fm-pr-merge does not echo back queue flags the caller already used
ok - fm-pr-merge still names retry flags when the caller used a different method
ok - fm-pr-merge names the queue requirement even when its method is unrecognised
ok - fm-pr-merge distinguishes unreadable branch rules from a base with no merge queue
ok - fm-pr-merge reads a plan-gated 403 on branch rules as no merge queue, not unreadable
ok - fm-pr-merge says nothing about a merge queue when the base branch has no queue rule
ok - fm-pr-merge accepts only a proved merge from the gh-axi fallback
ok - fm-pr-merge explains an armed auto-merge that landed nothing on a queue-less base
ok - fm-pr-merge never reports auto-merge as armed when the merge command failed
ok - fm-pr-merge claims no acceptance for a failed merge command carrying queue flags
ok - fm-pr-merge falls back to the gh-axi view when gh's read fails
ok - fm-pr-merge names a landed state hiding behind a failed GitHub merge command
ok - fm-pr-merge refuses a GitHub merge when gh is missing, before recording
ok - fm-pr-merge refuses a GitHub merge when gh is missing rather than merging blind
ok - fm-pr-merge verifies a genuinely merged GitHub pull request
ok - fm-pr-merge refuses to claim a merge when poll recording fails
ok - fm-pr-merge accepts and accurately reports a GitHub merge-queue entry
ok - fm-pr-merge explains how to retry with the required GitHub merge queue method
ok - fm-pr-merge refuses branch deletion unless --attended-override is passed
ok - fm-pr-merge refuses before merging when task meta is missing
ok - fm-pr-merge refuses malformed PR URLs before calling gh-axi
ok - fm-pr-merge refuses unsafe PR URL segments before recording state
ok - fm-pr-merge refuses repo override args before recording state
ok - fm-pr-merge refuses a bundled short-option repo override and refuses -d unless attended
ok - fm-pr-merge does not add default --squash when the caller passes an explicit merge method
ok - fm-pr-merge respects --method=<value> as an explicit merge method
ok - fm-pr-merge parses a GitHub PR URL into gh-axi number and --repo arguments
ok - fm-pr-merge refuses a caller --sha on GitHub because the head comes from the live read
ok - fm-pr-merge merges a GitLab merge request through glab instead of refusing it
ok - fm-pr-merge takes the GitLab instance from the URL rather than assuming one
ok - fm-pr-merge imposes no merge method on GitLab, leaving the project's own one
ok - fm-pr-merge refuses GitLab source-branch deletion unless --attended-override is passed
ok - fm-pr-merge propagates a real glab merge failure without silently succeeding
ok - fm-pr-merge refuses on each GitLab pre-merge condition independently
ok - fm-pr-merge reports every failing GitLab condition, not only the first
ok - fm-pr-merge reports a stale recorded head and verifies the live one
ok - fm-pr-merge refuses an unreadable GitLab merge request state rather than merging blind
ok - fm-pr-merge refuses a GitLab head commit it cannot validate
ok - fm-pr-merge refuses before recording anything when glab or jq is absent
ok - fm-pr-merge refuses a GitLab head override before recording state
ok - a merge a secondmate home performs itself is reported upward exactly once
ok - a locally routed secondmate home reports the landed PR into its parent's own channel
ok - a landed GitLab merge request is reported upward on the same channel
ok - a queued GitLab merge stays silent and leaves confirmation to the armed poll
ok - a refused or failed merge reports no outcome
ok - a GitLab merge refused before the forge call reports no outcome
ok - a merge a main home performs itself leaves one durable wake naming the PR
ok - a queued GitHub merge stays silent and leaves confirmation to the armed poll
ok - distinct merged PRs for one task retain distinct captain-facing wakes
ok - an uncommitted marker retry preserves at least one durable outcome
ok - a secondmate home that cannot report upward says so instead of merging in silence
ok - fm-pr-merge proceeds when the home carries no backlog at all
ok - fm-pr-merge refuses when the backlog exists but cannot be read
ok - fm-pr-merge refuses when its configured backend cannot be read
ok - fm-pr-merge refuses when its user backend configuration cannot be read
ok - fm-pr-merge refuses when its user backend configuration directory cannot be traversed
ok - fm-pr-merge proceeds once when its user configuration directory and backlog are genuinely absent
ok - fm-pr-merge honors a backend override over an unreadable user configuration
ok - fm-pr-merge refuses red GitHub checks and waives only a named --allow-red check
ok - fm-pr-merge refuses a draft pull request and one with no boolean draft state
ok - fm-pr-merge merges when a failed check run was replaced by a passing re-run
ok - fm-pr-merge never lets a check run supersede a legacy status context
ok - fm-pr-merge still refuses when a check's current run failed after an earlier pass
ok - fm-pr-merge uses start order when the old success finishes last
ok - fm-pr-merge supersedes an old cancellation that finishes last
ok - fm-pr-merge keeps a check red while its re-run is still in flight
ok - fm-pr-merge never lets one check's pass clear another check's failure
ok - fm-pr-merge clears a failure only on a proven later pass of the same check
ok - fm-pr-merge keeps --allow-red scoped to its named check beside a superseded failure
ok - fm-pr-merge rechecks away presence before an attended red merge
ok - fm-pr-merge keeps a quiet-mode home's merges attended, the named red-check waiver included
ok - fm-pr-merge accepts exactly one separately named red-check waiver
ok - while the away-posture record exists any green merge lands under away authority, yolo or not, and attended merges stay untagged
ok - under the away-posture record the branch merges a green task, is refused on a red check with or without --allow-red, and is refused at the partition while attended
ok - a branch merge refuses under the lock when the away record is archived during preflight
ok - away posture permits immediate merges but refuses every asynchronous path
ok - away merge proceeds on a plan-gated 403 because that repository cannot have a merge queue
ok - the away record does not bypass red checks, and a recorded pr= must match the URL
ok - an unreadable away-posture record refuses the merge instead of skipping the record
ok - no away-record archive or replacement lands between the authority read and the merge
ok - a record made unreadable before the merge's own authority read refuses the merge
ok - a merge that cannot lock the away record refuses instead of merging unlocked
ok - fm-pr-merge refuses --allow-red on GitLab
ok - fm-pr-merge refuses when a required check from branch protection or a ruleset never reported
ok - fm-pr-merge merges when every required check reported and is green
ok - fm-pr-merge reports a red check and an unreported required check together with every other failure
ok - fm-pr-merge refuses when the required checks cannot be read, and tells a plan without rules apart
ok - fm-pr-merge --allow-missing waives only its named unreported check
ok - fm-pr-merge --allow-missing is single use, attended-only, and GitHub-only like --allow-red
ok - fm-pr-merge enforces required producer identity and named waivers
ok - fm-pr-merge matches an app-bound required commit status by name
ok - fm-pr-merge reports known missing checks and all independent read errors
Evidence: Scenario driver script

Source: Scenario driver script

#!/usr/bin/env bash
# Drives the real bin/fm-pr-merge.sh against a disposable fake GitHub forge
# (the repo's own gh/gh-axi fakes, extracted to harness.sh) in a throwaway
# FM_HOME/state per case. Prints a transcript per scenario.
EV=$(cd "$(dirname "$0")" && pwd)
. "$EV/harness.sh"
set +e
URL=https://github.com/example/repo/pull/6020

reads() { grep -c '^pr view .*statusCheckRollup' "$1/gh.log"; }
merges() { grep -c '^pr merge ' "$1/gh.log"; }

# Swap the forge's live view JSON to a red-check variant from the Nth read on.
red_from_read() {
  local case_dir=$1 n=$2
  mv "$case_dir/fakebin/gh" "$case_dir/fakebin/gh.real"
  cp "$case_dir/github-view.json" "$case_dir/view-green.json"
  jq -c '.statusCheckRollup[0].conclusion="FAILURE"' "$case_dir/view-green.json" > "$case_dir/view-red.json"
  cat > "$case_dir/fakebin/gh" <<SH
#!/usr/bin/env bash
case " \$* " in *statusCheckRollup*)
  c=\$(( \$(cat "$case_dir/wrap-count" 2>/dev/null || echo 0) + 1 )); echo \$c > "$case_dir/wrap-count"
  [ "\$c" -ge $n ] && cp "$case_dir/view-red.json" "$case_dir/github-view.json" ;;
esac
exec "$case_dir/fakebin/gh.real" "\$@"
SH
  chmod +x "$case_dir/fakebin/gh"
}

scenario() {  # name seq(space-separated or '') [setup-fn] [delay-env]
  local name=$1 seq=$2 setup=${3:-} delay=${4-0} case_dir t0 t1 rc
  case_dir=$(make_case "$name"); mkdir -p "$case_dir/wt"
  add_gh_mocks "$case_dir" 6020602060206020602060206020602060206020
  : > "$case_dir/gh-axi.log"; : > "$case_dir/gh.log"
  [ -n "$setup" ] && $setup "$case_dir"
  local envs=()
  if [ -n "$seq" ]; then printf '%s\n' $seq > "$case_dir/seq"; envs+=(FM_TEST_GH_MERGEABLE_SEQUENCE="$case_dir/seq"); fi
  [ "$delay" = default ] || envs+=(FM_PR_GITHUB_MERGEABLE_RETRY_DELAY="$delay")
  t0=$(date +%s.%N)
  env "${envs[@]}" bash -c "$(declare -f run_pr_merge); ROOT='$ROOT' PR_MERGE='$PR_MERGE' REAL_MV='$REAL_MV'; run_pr_merge '$case_dir' task-x1 '$URL'" > "$case_dir/stdout" 2> "$case_dir/stderr"
  rc=$?
  t1=$(date +%s.%N)
  echo "=== $name"
  echo "mergeable sequence: ${seq:-<static view>}  retry delay: $delay"
  printf 'exit=%s  mergeable reads=%s  merge calls=%s  elapsed=%.1fs\n' "$rc" "$(reads "$case_dir")" "$(merges "$case_dir")" "$(echo "$t1 - $t0" | bc)"
  echo '--- stderr:'; sed 's/^/  /' "$case_dir/stderr"
  echo
}

set_draft()      { jq -c '.isDraft=true' "$1/github-view.json" > "$1/v" && mv "$1/v" "$1/github-view.json"; }
set_red()        { jq -c '.statusCheckRollup[0].conclusion="FAILURE"' "$1/github-view.json" > "$1/v" && mv "$1/v" "$1/github-view.json"; }
set_closed()     { jq -c '.state="CLOSED"' "$1/github-view.json" > "$1/v" && mv "$1/v" "$1/github-view.json"; }
set_dirty()      { jq -c '.mergeStateStatus="DIRTY"' "$1/github-view.json" > "$1/v" && mv "$1/v" "$1/github-view.json"; }
set_unreadable() { jq -c 'del(.mergeable)' "$1/github-view.json" > "$1/v" && mv "$1/v" "$1/github-view.json"; }
red_on_2nd()     { red_from_read "$1" 2; }
away_unreadable(){ printf 'not-a-contract\n' > "$1/state/.afk-contract"; }
away_queue()     { printf 'merge_method=MERGE\n' > "$1/github-rules"; write_away_record "$1" --words 'merge task-x1 when green'; }

case "${1:-all}" in
  timing)
    scenario unknown-once-default-delay "UNKNOWN MERGEABLE" "" default
    scenario unknown-forever-default-delay "UNKNOWN" "" default ;;
  *)
    scenario baseline-mergeable "MERGEABLE"
    scenario unknown-twice-then-mergeable "UNKNOWN UNKNOWN MERGEABLE"
    scenario unknown-four-then-mergeable-on-5th "UNKNOWN UNKNOWN UNKNOWN UNKNOWN MERGEABLE"
    scenario unknown-forever "UNKNOWN"
    scenario unknown-then-check-turns-red "UNKNOWN MERGEABLE" red_on_2nd
    scenario unknown-then-stays-unknown-check-turns-red "UNKNOWN UNKNOWN" red_on_2nd
    scenario unknown-plus-draft "UNKNOWN" set_draft
    scenario unknown-plus-red-check "UNKNOWN" set_red
    scenario unknown-plus-closed "UNKNOWN" set_closed
    scenario unknown-plus-dirty "UNKNOWN" set_dirty
    scenario conflicting "CONFLICTING"
    scenario mergeable-unreadable "" set_unreadable
    scenario unknown-then-mergeable-away-record-unreadable "UNKNOWN MERGEABLE" away_unreadable
    scenario unknown-then-mergeable-away-queue-protection "UNKNOWN MERGEABLE" away_queue ;;
esac

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 7 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Green, conflict-free PR reads UNKNOWN briefly, then MERGEABLE: the merge gate retries and merges exactly once ✅ pass live scenarios-transcript.txt: unknown-twice-then-mergeable exit=0 reads=3 merge calls=1; unknown-four-then-mergeable-on-5th exit=0 reads=5 merge calls=1; timing-default-delay.txt: unknown-once exit=0 in 4…
Mergeable stays UNKNOWN: the bound is spent after 5 reads, no merge is attempted, and the error says mergeability is still being computed rather than calling the PR unmergeable ✅ pass live scenarios-transcript.txt: unknown-forever exit=1 reads=5 merge calls=0, stderr only 'mergeability ... is still being computed by GitHub; retry shortly'; timing-default-delay.txt shows 13.7s total with…
Before the fix, a single UNKNOWN read is refused as unmergeable (bug reproduction) ✅ pass live before-fix-base-commit.txt: the base-commit script exits 1 after 1 read with 'mergeable is "UNKNOWN", not MERGEABLE'
Adversarial: a check turns red during the UNKNOWN retry, the next attempt re-checks every condition, refuses naming the red check, and no merge is sent ✅ pass live scenarios-transcript.txt: unknown-then-check-turns-red and unknown-then-stays-unknown-check-turns-red exit=1 reads=2 merge calls=0, stderr names "check 'ci' is not green"
Adversarial: UNKNOWN combined with any other refusal (draft, red check, closed, DIRTY) is refused immediately with 1 read and no pending message ✅ pass live scenarios-transcript.txt: unknown-plus-draft/red-check/closed/dirty each exit=1 reads=1 merge calls=0, and each refusal lists both conditions
CONFLICTING or unreadable mergeable is refused immediately and never retried ✅ pass live scenarios-transcript.txt: conflicting and mergeable-unreadable exit=1 reads=1 merge calls=0 with the unchanged refusal wording
Away-authority and merge-queue-protection refusals are unchanged and never retried ✅ pass live scenarios-transcript.txt: an unreadable away record refuses with 0 reads; with away mode plus a merge queue, UNKNOWN resolves after 2 reads, then the queue refusal fires once with exit=2 and no merge
  • bash tests/fm-pr-merge.test.sh (106/106 ok, including the 3 new UNKNOWN retry/exhaust/conflicting tests)
  • drive-scenarios.sh all: the real bin/fm-pr-merge.sh run against a disposable fake gh forge for 14 mergeable/refusal combinations
  • drive-scenarios.sh timing: the same with the default 3s retry delay (no env override) to measure the real bound
  • The same scenarios run against the base commit's fm-pr-merge.sh (temporary copy, deleted afterwards) to reproduce the original bug
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…KNOWN

Fixes kunchenguid#6020

bin/fm-pr-merge.sh refused a GitHub merge whenever the pull request's
mergeable field was not literally MERGEABLE. GitHub reports UNKNOWN for
a short while after a push or a base-branch change while it recomputes
mergeability, so a green, conflict-free pull request was refused as if
it could not be merged.

github_verify_mergeable now returns a distinct status when mergeable is
the only failing condition and reads UNKNOWN. The caller retries up to
5 times, 3 seconds apart (overridable in tests), re-reading and
re-checking every live condition on each attempt. Once the bound is
spent it reports mergeability as still being computed rather than
unmergeable, with the same nonzero exit as before. Every other refusal
(closed, draft, conflicting, red or missing checks, away authority,
queue protection) is unchanged and never retried.
@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[High risk] Adds retry logic to the pull request merge gate.

The PR appears safe to merge; no outstanding finding or new actionable issue remains.

Reviews (2) · Last reviewed commit: "no-mistakes(ci): I fixed both review fin..."

Comment thread tests/fm-pr-merge.test.sh Resolved
Comment thread bin/fm-pr-merge.sh Resolved
…full suite (`bash tests/fm-pr-merge.test.sh`) ran to completion. Its last lines showed all `ok`, and any failure would have stopped the run early. I watched the output through `tail`, so I didn't see the new test's own `ok` line directly. **ci-2 (`bin/fm-pr-merge.sh`), retry delay not validated.** What must hold: the retry wait is always a short, valid `sleep` argument, so a bad `FM_PR_GITHUB_MERGEABLE_RETRY_DELAY` can never trip `set -e` or hold the task lock for a long time. The retry loop is the only place that reads this variable. The script now reads the value once before the loop and accepts only whole numbers from 0 to 10. Anything else (empty, `abc`, `-1`, `1.5`, `11`, a huge number, leading spaces) falls back to 3. I ran those values through the check by hand and each came out as expected. The loop now sleeps on that checked value. **ci-1 (`tests/fm-pr-merge.test.sh`), no test for a check changing between UNKNOWN reads.** What must hold: every retry re-checks all live conditions, not just mergeable. The fake `gh pr view` in the test can now take an optional second word on each line of the mergeable sequence, which sets the first check's result. The new test `test_github_mergeable_unknown_retry_rechecks_checks` feeds `UNKNOWN`, then `UNKNOWN FAILURE`. It asserts: - exit code 1 after exactly 2 reads, - the refusal names `check 'ci' is not green`, - the message does not say mergeability is still being computed, - `pr merge` was never called. If a later change made the retry look only at mergeable, the loop would read UNKNOWN 5 times, end with the "still being computed" message, and this test would fail. I didn't run it against a deliberately broken script to confirm that. `bash -n` passes. `shellcheck` reports only the existing info-level notes about files it can't follow. Only `bin/fm-pr-merge.sh` and `tests/fm-pr-merge.test.sh` changed
@kunchenguid
kunchenguid merged commit c5f48e4 into kunchenguid:main Sep 29, 2026
20 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: this is merged. Thank you @karotkriss — really appreciate you taking the time on this.

Squash-merged vs tip 46d58d644d1ef59d6c34ec19d11d67868cbf9d40 (now c5f48e4cad279e6acaf14208522c44e28fac6835). HEAD 2a9c8d73c8368760a67521bb0412f3f103fc6cad. Attestation MATCH. CI 36550551087 SUCCESS. NM 36550551135 SUCCESS. MERGEABLE/CLEAN.

Contract-class: restore — fm-pr-merge already promised a green, conflict-free GitHub PR can land; treating transient forge mergeable=UNKNOWN as a terminal unmergeable refusal broke that concrete default path. Bounded retry (re-check all live conditions; pending report after bound; other refusals unchanged) restores it. Delay capped 0–10s. Not a new default-on surface.

VISION.md: all 7 align (honest merge outcomes; authority/away/queue refusals unchanged; scripted forge gate; restart-safe; delivery rigor; forge-agnostic provider case; command-layer merge script + tests).

Overlap: closes #6020. Sibling #6115 (same issue) will be closed as leftover naming this landed PR.
Firstmate flag no.