Skip to content

Serialize Mergify queue requests and reconcile transient failures - #1951

Merged
mergify[bot] merged 2 commits into
mainfrom
lean178/1327-rate-limit-recovery-r58
Nov 26, 2026
Merged

mergify[bot] merged 2 commits into
mainfrom
lean178/1327-rate-limit-recovery-r58

Conversation

@eowca

@eowca eowca commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Serialize Mergify queue requests and reconcile transient failures

Context and goal

  • Context: Loop Zero records the requested PR head and queue in a marker on its Mergify command comment.
  • Problem: Two merge invocations can both post a command, and a lost response can hide an accepted request.
  • Goal: Serialize admission within a worktree and verify accepted transient requests while preserving exact rate-limit diagnostics.

Closes #1327

Supersedes #1806. The independent fix review approved the rate-limit correction but was unregistered on that PR.

Acceptance

  • Concurrent merges submit one accepted request for the same PR head and queue.
  • If the response is lost after acceptance, reconcile the marker and report success.
  • If no marker exists after a transient failure, allow the next invocation to submit.
  • Skip reconciliation on a confirmed HTTP 429 or rate-limited 403 and retain the diagnostic.
  • Release the existing worktree lock before queue polling.

Base

Base: fef55ed

Validation

Recorded for c540d2216af6

  • uv run --group dev ruff check src tests: exit 0
  • uv run --group dev tach check: exit 0
  • uv run --python 3.14 python scripts/check_architecture_docs.py: exit 0
  • scripts/size_budget.sh: exit 0
  • uv run --group dev pytest -q: exit 0

(filled by loopzero check)

Review

(filled by loopzero review)


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

  • primary, claude, 5240ad6, approve

Architecture-Review: unchanged; admission uses the existing worktree lock and the existing marker proof, with confirmed HTTP rate limits preserving the transport diagnostic.
Co-Authored-By: Codex <noreply@openai.com>

@loopzero-feder-positronics loopzero-feder-positronics 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.

loopzero primary review by claude on 5240ad605d39a80c6d5cee33fbac3a253af85f52, 66.1s: approve (0 critical, 0 important, 4 suggestion)

Settings per native call (launch configuration and CLI claims, not backend attestation):

  • Call 1: requested model claude-opus-5-5 (effort medium); CLI-reported model claude-opus-5-5 (effort unknown); configured model claude-opus-5-5 (effort medium)

Findings without a file location:

  • suggestion: Confirmed-marker writes while polling are still not serialized — The patch serializes the request and the admission-time mark_confirmed. But _wait_for_mergify still calls mergify.mark_confirmed without the lock or a recheck. Two concurrent merge --wait invocations that both started with confirmed=False will each post a CONFIRMED marker comment once membership appears. The comments are harmless but duplicated, and this is the same defect class the change targets. If you want consistency, take the lock and recheck markers()[1] before posting, or document that duplicate confirmed markers are tolerated.

Native Claude output is retained in the restricted local review receipt.

Comment thread src/loopzero/mergify.py
try:
github._api(f"repos/{repo}/issues/{number}/comments", {"body": body})
except (github.GhError, github.ProcTimeout, OSError) as exc:
if getattr(exc, "confirmed_rate_limit", False) or not markers(repo, number, head, queue)[0]:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: A failed reconciliation read hides the original POST error

If the POST fails without a confirmed rate limit (a 5xx, ProcTimeout or OSError) and the follow-up markers() read also fails (for example, it is rate-limited or times out), the read's exception replaces the POST's. The POST error only survives as __context__, and the CLI prints str(exc), so the user sees a GET comments failure instead of the failed queue command. Smallest fix: wrap the reconciliation read in try/except (github.GhError, github.ProcTimeout, OSError): raise exc from None. That way an unverifiable reconciliation re-raises the original POST diagnostic.

Comment thread src/loopzero/cli.py
if not confirmed and confirmed_marker:
closed: list[github.GhError] = []
if sha := _mergify_departure(config, pr, queue, closed, confirmed=True):
with worktree.lock_local_state(wt):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: The admission lock covers slow work, waits a fixed 60s and ignores admit_by

lock_local_state waits a fixed 60 seconds and then raises TimeoutError('task state is busy'). Merge now holds this lock for the whole admission phase: GitHub reads, _mergify_departure, and _prequeue_size_budget. The size budget clones, fetches and runs up to two scripts, each with GIT_TIMEOUT=60s. cmd_check also holds the same lock for an entire check run. As a result, a second merge --wait can fail with 'busy' instead of following the queue the first invocation already joined. A merge started during a check also fails after 60s, where it previously went ahead. The 60s wait also ignores admit_by, so a positive --wait can run past its admission budget. This stays safe (no duplicate POST), but users have to retry. Consider one of these: run _prequeue_size_budget before taking the lock, then recheck markers under the lock; or make the lock wait respect admit_by/deadline when one is set.

Comment thread tests/test_cli.py
else:
assert "queue configuration is unverified" in err

@pytest.mark.parametrize(("accepted", "transient"), [(True, False), (False, False), (True, True)])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: No test covers releasing the lock before queue polling

The new concurrency test only runs merge without --wait, so _wait_for_mergify is never reached. The acceptance item 'Release the existing worktree lock before queue polling' has no test: a later change that moves the with block around the wait would still pass. Add a --wait case that checks the local-state lock can be acquired (for example, with a non-blocking flock) while _wait_for_mergify runs.

@eowca
eowca marked this pull request as ready for review November 26, 2026 14:54
@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@Mergifyio queue

@mergify

mergify Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

✅ Merged into main as c4c8c68 at 14:59 UTC

4 min in the queue, 4 min of it CI.

So far

  • ✅ Entered the queue Thu 26 Nov, 14:55 · rule main · triggered by @eowca with the @mergifyio queue command
  • ✅ Passed · draft #1955
  • ✅ Merged 14:59 · c4c8c68 · squash
3 merge conditions met
  • github-review-approved · required by GitHub repository ruleset rule main: PR only, Mergify queue, existing checks required
  • any of · required by GitHub repository ruleset rule main: PR only, Mergify queue, existing checks required:
    • check-success = checks
    • check-neutral = checks
    • check-skipped = checks
  • any of · required by GitHub repository ruleset rule main: PR only, Mergify queue, existing checks required:
    • check-success = Loop-zero Eligibility
    • check-neutral = Loop-zero Eligibility
    • check-skipped = Loop-zero Eligibility

Times in UTC · dashboard · how the merge queue works

@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

No description provided.

@mergify
mergify Bot merged commit c4c8c68 into main Nov 26, 2026
13 checks passed
@mergify mergify Bot removed the queued label Nov 26, 2026
@eowca
eowca deleted the lean178/1327-rate-limit-recovery-r58 branch November 26, 2026 15:01
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.

Avoid duplicate Mergify queue comments from overlapping merge retries

2 participants