Repository navigation
Warn when known queue predecessors put a PR over the size budget #1781
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 |
|---|---|---|
|
|
@@ -16,7 +16,7 @@ | |
| from pathlib import Path | ||
| from urllib.parse import quote | ||
|
|
||
| from . import github | ||
| from . import candidate, github | ||
| from .types import LoopZeroError | ||
|
|
||
| API = "https://api.mergify.com/v1" | ||
|
|
@@ -147,6 +147,43 @@ def membership(repo: str, number: int, queue: str) -> Membership | None: | |
| raise MergifyError("invalid Mergify queue membership response") from exc | ||
|
|
||
|
|
||
| def queue_predecessors(repo: str, branch: str, queue: str, number: int) -> tuple[int, ...]: | ||
|
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 CLI test covers only the ordered, empty, two-roots-ambiguous and unavailable snapshots. It does not exercise these reject branches: a multi-PR batch, a batch with a different |
||
| """Identify a single chain of one-PR batches ahead of a new request.""" | ||
| status = api_get(repo, f"/merge-queue/status?branch={quote(branch, safe='')}") | ||
| if (not isinstance(status, dict) or status.get("mode") != "serial" | ||
|
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 new reader depends on status keys that no existing fixture contains Admission depends on |
||
| or status.get("waiting_pull_requests") != [] or status.get("forming_batches") != []): | ||
| return () | ||
| try: | ||
| batches = candidate.flatten_batches(status) | ||
| successors: dict[str | None, tuple[str, int]] = {} | ||
| for batch_id, batch in batches.items(): | ||
| pulls, parents = batch["pull_requests"], batch["parent_ids"] | ||
| if pulls == [] and batch.get("sub_batches"): | ||
| continue # Container batches carry no direct source. | ||
| if (batch.get("queue_rule_name") != queue or not isinstance(pulls, list) | ||
| or len(pulls) != 1 or not isinstance(parents, list) or len(parents) > 1): | ||
| return () | ||
| source = pulls[0]["number"] | ||
| parent = next(iter(parents), None) | ||
| if type(source) is not int or source <= 0 or source == number or parent in successors: | ||
| return () | ||
| successors[parent] = batch_id, source | ||
| return _ordered_sources(successors) | ||
| except (candidate.CandidateError, KeyError, TypeError, RecursionError): | ||
| return () | ||
|
|
||
|
|
||
| def _ordered_sources(successors: dict[str | None, tuple[str, int]]) -> tuple[int, ...]: | ||
| if len(successors) > 32: | ||
| return () | ||
| sources = [] | ||
| cursor = None | ||
| while cursor in successors: | ||
| cursor, source = successors.pop(cursor) | ||
| sources.append(source) | ||
| return tuple(sources) if not successors and len(sources) == len(set(sources)) else () | ||
|
|
||
|
|
||
| def _preserves_source_heads(repo: str, branch: str, queue: str) -> bool: | ||
| """Read the vendor's canonical input, not a deprecated raw queue-rule default.""" | ||
| import yaml | ||
|
|
||
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: An advisory snapshot read can stall
readyfor up to about 97 seconds_warn_queue_sizecallsmergify.queue_predecessors, which goes throughapi_get. That function makes three attempts, each with a 30s urlopen timeout, and sleeps 2s and then 5s between them (mergify.py:95-111). A Mergify outage or throttling can therefore block the warning for about 97 seconds before it gives up silently. Admission is unchanged, butreadystalls during that time.ready --wait=Nalso projects (cli.py:1343 passes the defaultproject=True), so the stall uses up the same wait budget that the later_wait_with_deadlineat cli.py:1347 needs aftermark_ready. Smallest fix: give the snapshot read a single attempt with a short timeout, for example anapi_get(..., retries=False)variant or aproject=args.wait is Noneguard incmd_ready. That would also match the ARCHITECTURE wording "without an admission deadline".