Repository navigation
Restart Mergify backoff when admission is confirmed #1813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1407,18 +1407,22 @@ def _merge_check_hint(config: Config, pr: github.PR, readiness: github.Readiness | |
|
|
||
|
|
||
| def _poll_until( | ||
| started: float, timeout: float, *, bounded: bool = False, initial_read_time: float = 0.0, | ||
| started: float, timeout: float, *, bounded: bool = False, | ||
| initial_read_time: float = 0.0, admitted: Callable[[], bool] | None = None, | ||
| ) -> Iterator[None]: | ||
| delay = WAIT_INTERVAL | ||
| longest_read = initial_read_time | ||
| while True: | ||
| was_admitted = admitted is not None and admitted() | ||
| read_started = time.monotonic() | ||
| yield # Observe immediately, including --wait=0. | ||
| now = time.monotonic() | ||
| longest_read = max(longest_read, now - read_started) | ||
| remaining = timeout - (now - 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: | ||
| # Poll late enough to see a settled check while reserving time to read it. | ||
|
|
@@ -1676,7 +1680,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): | ||
| polls = _poll_until(started, timeout, admitted=lambda: confirmed) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Unneeded The |
||
| for _ in polls: | ||
| sha = _landed(config, pr, closed) | ||
| if sha: | ||
| return sha | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Admission is checked twice per tick through a closure
_poll_untilcallsadmitted()before and after each yield to detect the transition. This works because the lambda reads the reassignedconfirmedlocal of_wait_for_mergify. However, the reset depends on a side effect inside the loop body, and the generic poller now carries Mergify-specific state. A one-line comment at the call site would help, saying the lambda deliberately reads the liveconfirmed. Another option is to have the loop body tell the generator to reset, for example withpolls.send(...). That would remove the double evaluation. The current code is correct and every existing_poll_untilcaller and monkeypatch still works: line 1545 passesbounded=..., line 1611 uses positional arguments only, and thelambda *_stub at tests/test_cli.py:4752 is only used through_wait_for_merge.