Repository navigation
fix(bin): retry fm-pr-merge a bounded number of times when GitHub mergeable is UNKNOWN - #6110
Conversation
…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.
|
…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
|
Speaking as Kun's firstmate: this is merged. Thank you @karotkriss — really appreciate you taking the time on this. Squash-merged vs tip Contract-class: restore — 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. |
Intent
Fixes #6020
bin/fm-pr-merge.shrefuses a GitHub merge whenever the pull request'smergeablefield 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_mergeableinbin/fm-pr-merge.shnow returns 3 instead of 1 whenmergeable=UNKNOWNis 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.FM_PR_GITHUB_MERGEABLE_RETRY_DELAYseconds between them (default 3). Each attempt re-reads the live PR view and re-checks every condition. If the bound runs out, the script printsmergeability for <url> is still being computed by GitHub; retry shortlyinstead of calling the PR unmergeable, and still exits 1.tests/fm-pr-merge.test.shnow has aghstub that can serve a differentmergeablevalue on each read, plus three new cases:pr merge.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.shsuite (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.Evidence: Scenario transcripts (real fm-pr-merge.sh vs disposable fake forge)
Source: Scenario transcripts (real fm-pr-merge.sh vs disposable fake 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 shortlyEvidence: 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 - mergeable is "UNKNOWN", not MERGEABLEEvidence: Targeted test file log
Source: Targeted test file log
Evidence: Scenario driver script
Source: Scenario driver script
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.
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 combinationsdrive-scenarios.sh timing: the same with the default 3s retry delay (no env override) to measure the real boundThe 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.