Repository navigation
Shorten waits for Mergify landing and source checks #1425
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
b7f1d94
9e32e37
32a225c
1a3f5c9
f690e5d
7b90ec9
b21c22b
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 |
|---|---|---|
|
|
@@ -1172,6 +1172,7 @@ def _cleanup(wt: Path, pr: github.PR) -> None: | |
|
|
||
| def cmd_ready(args: argparse.Namespace) -> int: | ||
| wt, config = _context(args, pin_checks=True) | ||
| read_started = time.monotonic() | ||
| pr, readiness = _pr_readiness(wt, config, workflow_wait=args.wait is not None) | ||
| assert readiness is not None | ||
| waiting = _draft_checks_waiting(config, pr, readiness) | ||
|
|
@@ -1189,7 +1190,8 @@ def cmd_ready(args: argparse.Namespace) -> int: | |
| ): | ||
| waited = _wait_with_deadline(wt, config, pr, args.wait, kicked=kicked, started=started, | ||
| shown=readiness.reasons if kicked else (), args=args, | ||
| allow_skipped=True, initial=None if kicked else readiness) | ||
| allow_skipped=True, initial=None if kicked else readiness, | ||
| initial_read_time=started - read_started) | ||
| if waited is None: | ||
| return 3 | ||
| pr, readiness, kicked = waited | ||
|
|
@@ -1252,17 +1254,29 @@ 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, | ||
| initial_read_time: float = 0.0, | ||
| ) -> 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. | ||
| remaining = timeout - (time.monotonic() - started) | ||
| 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: | ||
| # Leave part of the final interval for the last observation to complete. | ||
| _sleep(remaining / 2) | ||
| # Reserve time for a complete readiness pass based on observed latency. | ||
| baseline = min(5.0, max(0.5, remaining / 10)) | ||
| allowance = min(remaining / 2, max(baseline, 2 * longest_read)) | ||
| _sleep(remaining - allowance) | ||
| yield | ||
| remaining = timeout - (time.monotonic() - started) | ||
| if remaining > 0: | ||
|
|
@@ -1276,6 +1290,7 @@ def _wait_with_deadline( | |
| wt: Path, config: Config, pr: github.PR, timeout: float, *, kicked: bool, | ||
| started: float | None = None, shown: tuple[str, ...] = (), args: argparse.Namespace, | ||
| allow_merged: bool = False, allow_skipped: bool = False, initial: github.Readiness | None = None, | ||
| initial_read_time: float = 0.0, | ||
| ) -> tuple[github.PR, github.Readiness | None, bool] | None: | ||
| started = time.monotonic() if started is None else started | ||
| if timeout == 0: | ||
|
|
@@ -1291,7 +1306,8 @@ def _wait_with_deadline( | |
| with github.bounded_reads(deadline, token=None, retry=True): | ||
| waited = _wait_for_checks(wt, config, pr, timeout, kicked=kicked, started=started, | ||
| shown=shown, args=args, bounded=True, allow_merged=allow_merged, | ||
| allow_skipped=allow_skipped, initial=initial) | ||
| allow_skipped=allow_skipped, initial=initial, | ||
| initial_read_time=initial_read_time) | ||
| reported_timeout = waited is None | ||
| except github.ReadDeadline: | ||
| if not reported_timeout: | ||
|
|
@@ -1331,13 +1347,14 @@ def _wait_for_checks( | |
| started: float | None = None, shown: tuple[str, ...] = (), | ||
| args: argparse.Namespace | None = None, bounded: bool = False, allow_merged: bool = False, | ||
| allow_skipped: bool = False, initial: github.Readiness | None = None, | ||
| initial_read_time: float = 0.0, | ||
| ) -> tuple[github.PR, github.Readiness | None, bool] | None: | ||
| """Poll the same head until it settles, omitting readiness for an allowed merge.""" | ||
| grace_started = time.monotonic() | ||
| started = grace_started if started is None else started | ||
| current = pr | ||
| stale_notice = False | ||
| for _ in _poll_until(started, timeout, bounded=bounded): | ||
| for _ in _poll_until(started, timeout, bounded=bounded, initial_read_time=initial_read_time): | ||
| if initial is not None: | ||
| readiness = initial | ||
| initial = None | ||
|
|
@@ -1352,7 +1369,7 @@ def _wait_for_checks( | |
| print("marked ready; " + "; ".join(readiness.reasons)) | ||
| return _wait_for_checks(wt, config, pr, timeout, kicked=True, started=started, | ||
| shown=readiness.reasons, args=args, bounded=bounded, | ||
| allow_merged=allow_merged) | ||
| allow_merged=allow_merged, initial_read_time=initial_read_time) | ||
| if kicked and readiness.ready and timeout > 0 and time.monotonic() - started > timeout: | ||
| break # A post-transition read cannot grant success beyond the original deadline. | ||
| pending = _pending_checks( | ||
|
|
@@ -1469,7 +1486,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) | ||
| for _ in polls: | ||
| sha = _landed(config, pr, closed) | ||
| if sha: | ||
| return sha | ||
|
|
@@ -1554,6 +1572,7 @@ def cmd_merge(args: argparse.Namespace) -> int: | |
| mergify.dequeue(config.repo, pr.number) | ||
| print(f"requested removal of PR #{pr.number} from Mergify") | ||
| return 0 | ||
| read_started = time.monotonic() | ||
|
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: Seeded read latency covers more work than a poll read
|
||
| pr, readiness = _pr_readiness( | ||
| wt, config, allow_merged=True, workflow_wait=args.wait is not None | ||
| ) | ||
|
|
@@ -1565,7 +1584,8 @@ def cmd_merge(args: argparse.Namespace) -> int: | |
| # One waiter and one deadline span source checks and landing: a check created | ||
| # by the ready transition must not end the turn between `ready` and the queue. | ||
| waited = _wait_with_deadline(wt, config, pr, args.wait, kicked=False, started=started, | ||
| args=args, allow_merged=True, initial=readiness) | ||
| args=args, allow_merged=True, initial=readiness, | ||
| initial_read_time=started - read_started) | ||
| if waited is None: | ||
| return 3 | ||
| pr, readiness, _ = waited | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.