Repository navigation
Reconcile eligibility dispatch after finding resolution #1754
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 |
|---|---|---|
|
|
@@ -1138,13 +1138,44 @@ def eligibility_dispatch_args(repo: str, number: int, base: str) -> tuple[str, . | |
| "-f", f"ref={base}", "-f", f"inputs[pr]={number}") | ||
|
|
||
|
|
||
| def refresh_eligibility(repo: str, number: int, base: str) -> None: | ||
| args = eligibility_dispatch_args(repo, number, base) | ||
| def _eligibility_dispatched(repo: str, number: int, base: str, since: str) -> bool: | ||
| query = f"event=workflow_dispatch&branch={quote(base, safe='')}&created={quote('>=' + since, safe='')}&per_page=100" | ||
| data = api_get(f"repos/{repo}/actions/workflows/eligibility.yml/runs?{query}") | ||
| runs = data.get("workflow_runs") if isinstance(data, dict) else None | ||
| complete = isinstance(runs, list) and data.get("total_count") == len(runs) | ||
| identified = [run.get("display_title") if isinstance(run, dict) else None for run in runs] if complete else [] | ||
| if f"Refresh eligibility for PR #{number}" in identified: | ||
| return True | ||
| if not complete or any(not isinstance(name, str) or not re.fullmatch(r"Refresh eligibility for PR #[0-9]+", name) for name in identified): | ||
| raise GhError(("refresh Loop-zero Eligibility",), "could not identify all recent refresh runs") | ||
| return False | ||
|
|
||
|
|
||
| def refresh_eligibility(repo: str, pr: PR, branch: str, base: str, publishers: tuple[str, ...]) -> None: | ||
| args = eligibility_dispatch_args(repo, pr.number, base) | ||
| since = datetime.fromtimestamp(time.time(), UTC).isoformat(timespec="seconds") | ||
| try: | ||
| _gh(*args) | ||
| try: | ||
| _gh(*args) | ||
| except (GhUnavailable, ProcTimeout) as exc: | ||
| if isinstance(exc, GhUnavailable) and not _transient_error(exc.tail, False): | ||
|
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 transient check repeats a decision
|
||
| raise | ||
| _retry_sleep(RETRY_DELAY) | ||
| current = pr_for_branch(repo, branch, open_only=True) | ||
| if current is None or (current.number, current.head_sha, current.base_ref) != ( | ||
| pr.number, pr.head_sha, pr.base_ref, | ||
| ): | ||
| raise GhError(("refresh Loop-zero Eligibility",), "the PR or head changed after resolution") from exc | ||
| if _eligibility_dispatched(repo, pr.number, base, since): | ||
| return | ||
| if open_blocking_findings(repo, pr.number, None, publishers): | ||
| raise GhError(("refresh Loop-zero Eligibility",), "blocking findings appeared after resolution") from exc | ||
| _gh(*args) | ||
| except (GhError, ProcTimeout, OSError) as exc: | ||
| retry = shlex.join(("gh", *args)) | ||
| raise GhError(("refresh Loop-zero Eligibility",), f"{exc}\nRun manually: {retry}") from exc | ||
| raise GhError(("refresh Loop-zero Eligibility",), | ||
|
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 final error repeats "refresh Loop-zero Eligibility failed" The head-changed, findings-appeared and could-not-identify errors are raised as |
||
| f"Finding on PR #{pr.number} is resolved. {exc}\n" | ||
| f"Verify the PR head, remaining findings and recent runs before retrying: {retry}") from exc | ||
|
|
||
|
|
||
| def open_blocking_findings( | ||
|
|
||
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 empty run list is treated as proof that no dispatch happened, but it may only mean the run isn't visible yet
sincecomes from the local clock, and the lookup runs only 5 s after the failed POST. If the POST actually went through, two things can hide that run: (1) the local clock is ahead of GitHub's clock by more than the dispatch latency, socreated>=sincefilters the run out; (2) GitHub creates workflow_dispatch runs asynchronously, and listing can lag. That lag is most likely during the same 5xx incidents that trigger this path. In either case_eligibility_dispatchedreturns False and a second dispatch goes out. The duplicate is mostly harmless because the source job's concurrency group queues it withcancel-in-progress: false. Still, it contradicts the note that an observation you can't trust should not authorize a duplicate. Smallest fix: before treating an empty list as absence, either takesincefrom a server-side timestamp (for example theDateheader of the PR read), or subtract a small margin and keep only same-PR runs whosecreated_atis after the resolution. At minimum, document the residual risk.