Repository navigation
Restart Mergify backoff when admission is confirmed #1709
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 |
|---|---|---|
|
|
@@ -1403,13 +1403,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. | ||
|
|
@@ -1664,7 +1669,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: 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: The admission reset relies on a closure seeing a later rebinding of
confirmed_poll_untilgetslambda: confirmed, checks it before each yield and checks it again after the yield to spot the transition. This works because Python closures capture variables, not values. When_wait_for_mergifysetsconfirmed = Trueinside the loop body, the second call sees the new value. I traced the unconfirmed replay: sleeps come out as [30, 60, 120] while unconfirmed. At t=210, membership is confirmed anddelayresets to 30. The landing read at t=240 then sees the merge. Without the fix the sleeps would be [..., 120, 120], so the test does catch the regression. The steady-state, bounded and deadline paths are unchanged for callers that don't passadmitted.The weak point is that the coupling is implicit. If someone later moves the confirmation into a helper that returns a new value without rebinding the local
confirmed, the reset stops firing and nothing complains. A simpler alternative is to have_poll_untilaccept a value sent back by the caller (gen.send(...)), or to have the caller signal "reset now" directly. Either one makes the transition explicit and removes the secondadmitted()call. This is not blocking.