Skip to content

fix(queue): retry a transient GitHub mergeable_state read before deferring to the next sweep#8560

Merged
JSONbored merged 1 commit into
mainfrom
fix/merge-state-unknown-retry
Jul 24, 2026
Merged

fix(queue): retry a transient GitHub mergeable_state read before deferring to the next sweep#8560
JSONbored merged 1 commit into
mainfrom
fix/merge-state-unknown-retry

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Summary

Live incident: metagraphed#8037 (and others) sat unmerged for ~6 minutes after being approved, gate-passing, and fully-autonomous-merge-configured (autonomy.merge: auto, requireApprovals: 0). GitHub computes mergeable_state asynchronously after a push/review and can return "unknown" (still computing) even on the forced live re-fetch taken moments after posting the approving review — the disposition correctly refused to merge into an unconfirmed state, but simply deferred to the next scheduled regate sweep (~6 minutes later) instead of retrying. That multi-minute window is exactly where an overlapping sibling PR can land first and base-conflict the original PR out from under it — metagraphed#8037's own review panel had already flagged 2 such overlapping siblings (#8040, #8036).

refreshLiveMergeState now retries a short, bounded number of times (2) specifically on "unknown""dirty"/"blocked"/"behind" are real, stable, non-computing states and are never retried — before falling through to the same defer-to-sweep behavior as before. Mirrors the identical GitHub-lag pattern already used for diff/files computation (fetchAndStorePullRequestFilesForReview).

Validation

  • New regression tests in ci-resolution.test.ts: retries once and resolves to "clean" within the same pass; gives up after the retry cap and still returns "unknown" (unchanged fallback behavior); does not retry a real "dirty" state; does not retry an outright fetch failure.
  • All 4 existing test files that mock fetchLivePullRequestMergeState directly (not through refreshLiveMergeState) are unaffected — confirmed by running them.
  • npm run typecheck clean; npm run test:coverage (full, unsharded): 21,486 passed / 0 failed.
  • Test-only delay override via the shared test/helpers/vitest-setup.ts default (from perf(test): eliminate SQLite fsync and real rate-limit backoff wait in tests #8553), so the retry's own logic is exercised without adding real wall-clock time to the suite.

…rring to the next sweep

Live incident: metagraphed#8037 (and others) sat unmerged for ~6 minutes
after being approved, gate-passing, and fully-autonomous-merge-configured
(autonomy.merge: auto, requireApprovals: 0). GitHub computes mergeable_state
ASYNCHRONOUSLY after a push/review and can return "unknown" (still
computing) even on the forced live re-fetch taken moments after posting the
approving review -- the disposition correctly refused to merge into an
unconfirmed state, but simply deferred to the next scheduled regate sweep
(~6 minutes later) instead of retrying. That multi-minute window is exactly
where an overlapping sibling PR can land first and base-conflict the
original PR out from under it.

refreshLiveMergeState now retries a short, bounded number of times (2)
SPECIFICALLY on "unknown" -- "dirty"/"blocked"/"behind" are real, stable,
non-computing states and are never retried -- before falling through to the
same defer-to-sweep behavior as before. Mirrors the identical GitHub-lag
pattern already used for diff/files computation
(fetchAndStorePullRequestFilesForReview).

Test-only delay override via the same vitest-setup.ts suite default this
session's other perf fixes use, so the retry's own logic is exercised
without adding real wall-clock time to the suite.
@JSONbored JSONbored self-assigned this Jul 24, 2026
@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@JSONbored
JSONbored merged commit bd273c1 into main Jul 24, 2026
5 checks passed
@JSONbored
JSONbored deleted the fix/merge-state-unknown-retry branch July 24, 2026 21:10
@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 92.50%. Comparing base (12aa3e6) to head (5a42c5a).
⚠️ Report is 4 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/queue/ci-resolution.ts 88.88% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8560      +/-   ##
==========================================
- Coverage   92.51%   92.50%   -0.01%     
==========================================
  Files         795      795              
  Lines       79613    79622       +9     
  Branches    24056    24058       +2     
==========================================
+ Hits        73653    73657       +4     
  Misses       4800     4800              
- Partials     1160     1165       +5     
Flag Coverage Δ
backend 93.67% <88.88%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/queue/ci-resolution.ts 97.59% <88.88%> (-1.06%) ⬇️

... and 1 file with indirect coverage changes

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.

1 participant