From 2156b3119513ac2db0c1934a9402403a857fd4e3 Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 09:26:48 +0100 Subject: [PATCH 1/2] Restart Mergify poll backoff at queue admission Architecture-Review: unchanged; the initial interval resumes after confirmed admission with the same timeout and queue verdicts. Co-Authored-By: Codex --- src/loopzero/cli.py | 9 +++++++-- tests/test_cli.py | 30 +++++++++++++++--------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/loopzero/cli.py b/src/loopzero/cli.py index 6279887d..ee4dc3af 100644 --- a/src/loopzero/cli.py +++ b/src/loopzero/cli.py @@ -1302,13 +1302,18 @@ def _merge_check_hint(config: Config, pr: github.PR, readiness: github.Readiness return "" -def _poll_until(started: float, timeout: float, *, bounded: bool = False) -> Iterator[None]: +def _poll_until( + started: float, timeout: float, *, bounded: bool = False, admitted: Callable[[], bool] | None = None, +) -> Iterator[None]: delay = WAIT_INTERVAL while True: + was_admitted = admitted is not None and admitted() yield # Observe immediately, including --wait=0. remaining = timeout - (time.monotonic() - started) if remaining <= 0: return + if admitted is not None and not was_admitted and admitted(): + delay = WAIT_INTERVAL pause = delay * random.uniform(0.9, 1.0) if bounded and remaining <= pause: # Leave part of the final interval for the last observation to complete. @@ -1553,7 +1558,7 @@ def _wait_for_mergify( state = None deferred_landing_read = False print(f"PR #{pr.number} following Mergify queue {queue}; head {pr.head_sha[:12]}; waiting up to {timeout:g}s") - for _ in _poll_until(started, timeout): + for _ in _poll_until(started, timeout, admitted=lambda: confirmed): sha = _landed(config, pr, closed) if sha: return sha diff --git a/tests/test_cli.py b/tests/test_cli.py index e8d5bbeb..9c2df4a4 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -4334,7 +4334,8 @@ def test_ready_pins_review_publishers_to_base(wt, gh, capsys, publisher, head): assert run(capsys, "ready")[0] == (0 if publisher == LOGIN else 1) -def test_mergify_confirmed_wait_reads_pr_once_per_steady_poll(wt, gh, monkeypatch): +@pytest.mark.parametrize("confirmed", [True, False]) +def test_mergify_confirmed_wait_reads_pr_once_per_steady_poll(wt, gh, monkeypatch, confirmed): head = commit_mergify_configuration(wt) config = cli.config_mod.load_trusted(wt) pr = github.PR(7, URL, head, "main", False, "OPEN", "MERGEABLE") @@ -4346,25 +4347,24 @@ def test_mergify_confirmed_wait_reads_pr_once_per_steady_poll(wt, gh, monkeypatc def membership(*_): reads_at_membership.append(len(gh.calls)) - if sum(sleeps) == 60: + if confirmed and sum(sleeps) == 60: gh.respond(" ".join(detail), merge_json(state="MERGED", head=head, sha="e" * 40)) - return mergify.Membership() - - def configured(*args): - configurations.append(args) - return True + return mergify.Membership() if confirmed or sum(sleeps) >= 210 else None - monkeypatch.setattr(mergify, "configured", configured) + monkeypatch.setattr(mergify, "configured", lambda *args: configurations.append(args) or True) + monkeypatch.setattr(mergify, "mark_confirmed", lambda *_: gh.respond( + " ".join(detail), merge_json(state="MERGED", head=head, sha="e" * 40))) monkeypatch.setattr(mergify, "membership", membership) monkeypatch.setattr(cli.time, "monotonic", lambda: sum(sleeps)) monkeypatch.setattr(cli.random, "uniform", lambda *_: 1.0) monkeypatch.setattr(cli, "_sleep", sleeps.append) - assert cli._wait_for_mergify(config, pr, 60, confirmed=True) == "e" * 40 - assert sleeps == [30, 30] - assert configurations == [(REPO, "main", "main")] * 3 - assert reads_at_membership == [1, 2, 3] - assert [c["argv"][:2] for c in gh.calls] == [detail] * 4 + assert cli._wait_for_mergify(config, pr, 60 if confirmed else 360, confirmed=confirmed) == "e" * 40 + assert sleeps == ([30, 30] if confirmed else [30, 60, 120, 30]) + assert configurations == [(REPO, "main", "main")] * (3 if confirmed else 4) + assert reads_at_membership == ([1, 2, 3] if confirmed else [1, 4, 7, 10]) + assert sum(c["argv"][:2] == detail for c in gh.calls) == (4 if confirmed else 9) + assert len(gh.calls) == (4 if confirmed else 12) @pytest.mark.parametrize("outcome,jitter", [ @@ -4441,9 +4441,9 @@ def membership(*_): if outcome == "worktree_removed": poll_until = cli._poll_until - def remove_worktree_then_poll(*args): + def remove_worktree_then_poll(*args, **kwargs): git(repo, "worktree", "remove", "--force", str(wt)) - return poll_until(*args) + return poll_until(*args, **kwargs) monkeypatch.setattr(cli, "_poll_until", remove_worktree_then_poll) try: From 6af5ebf5dcee8dffde9c1bd7bdcbfae0ae8233fd Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 09:42:34 +0100 Subject: [PATCH 2/2] Construct the admission poll iterator before its loop Architecture-Review: unchanged; the iterator reads the same confirmation transition and wait budget. Co-Authored-By: Codex --- src/loopzero/cli.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/loopzero/cli.py b/src/loopzero/cli.py index ee4dc3af..e94db985 100644 --- a/src/loopzero/cli.py +++ b/src/loopzero/cli.py @@ -1558,7 +1558,8 @@ def _wait_for_mergify( state = None deferred_landing_read = False print(f"PR #{pr.number} following Mergify queue {queue}; head {pr.head_sha[:12]}; waiting up to {timeout:g}s") - for _ in _poll_until(started, timeout, admitted=lambda: confirmed): + polls = _poll_until(started, timeout, admitted=lambda: confirmed) + for _ in polls: sha = _landed(config, pr, closed) if sha: return sha