Scripts: keep triage labels while a gate runs, rerun when it completes #3686
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3686"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by tiagonleal on 2026-12-02T10:16:54Z.
Editing a PR description makes Auto triage drop the merge-check labels. The
editedevent restarts the PR description check, triage reads it as IN_PROGRESS, andcompute_managed_labelsonly sets the state labels when both gates are SUCCESS. Nothing reruns triage when the check finishes, so the labels stay gone until someone posts a merge-check comment.Seen on #3038 on 2026-12-02 at 09:42 UTC. The body was edited with no push, and run 46853698988 logged
removed=['needs-2nd-check', 'needs:amd-test'] ci=SUCCESS pr_check=IN_PROGRESS safe=1. The PR still has one safe merge-check. A typo fix in the description would removeready-to-mergethe same way.What is in it
One commit with two parts:
scripts/triage_pr.pythe state-label logic moves intomerge_check_state_labels. While a gate is queued or in progress and none has failed, triage keeps the state labels the merge checks still support and adds none. Failures, drafts, conflicts andduplicateremove them as before..github/workflows/auto-triage.ymlalso runs onworkflow_runcompletion ofCIandPR checks, skipping push runs. Fork PRs have no PR number in that event, sotriage-one --head-shalooks up the open PRs whose head is that commit. It uses issue search, which finds fork PRs, pluscommits/{sha}/pulls, which returns nothing for fork commits (checked on #3686) but covers same-repo PRs. It retries up to 3 times, 10 s apart, in case the search index lags, then confirms each hit's head SHA. No match exits quietly. The job still checks out only the default branch's script, and the SHA goes throughenv:.workflow_run.pull_requests[0].number(filled for same-repo PRs), then the head SHA. For a fork PR, a completion run and a PR-event run can overlap. Each run reads the labels fresh and only adds or removes the difference from what it read, and a run that sees a pending gate adds no state labels. The worst case needs a check rerun to turn from green to red on the same commit while an older run that read it green is still in flight. That run could then re-add a state label until the next triage event. I left this alone because the window is a few seconds.scripts/test_triage_pr.py: tests for pending gates and for the SHA lookup with a fake client. All test classes are now above the__main__block.Tested
py scripts/test_triage_pr.pyandpy -m unittest scripts/test_triage_pr.py: 20 tests each, OK. Without the triage_pr.py change, the keep test fails.Not tested
workflow_runpath has not run live. It only takes effect from the default branch after merge.AI use
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T10:20:40Z.
Review (head
aa64a0cc, diff read, not a merge-check):compute_managed_labels(scripts/triage_pr.py~404-415) now keepsready-to-merge/needs-2nd-check/needs:*-test, butauto-triage.ymlruns only on PR events andmerge-checkcomments, so nothing re-runs triage when the gate finishes. A description edit that breaks the description check (e.g. removing Regression run), or a reopen whose CI rerun fails, then leavesready-to-mergeon a PR with a red gate and noneeds-pr-check; before, the label was dropped.ready-to-mergealso exempts the PR fromstale.yml.testing-feed.yml(~14-15) does run onworkflow_runcompletion ofCIandPR checks, butbuild-feedskips PRs that are not green (~776) and syncs labels only onworkflow_dispatch, so it does not clear the label either. Aworkflow_runtrigger for triage, or not keepingready-to-mergewhile pending, would close this. A push is safe, sinceparse_merge_checksfilters by head SHA.Fine: the state-label logic moves into
merge_check_state_labelsunchanged; intersecting withexisting_labelskeeps a pending gate from adding labels or keeping ones the head's merge checks no longer support; the four new tests cover keep, add-none, drop and failure.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by tiagonleal on 2026-12-02T10:25:03Z.
@Foniass you are right, a kept label could outlive a gate that then fails.
433d6a24adds theworkflow_runtrigger: triage runs again whenCIorPR checkscompletes, so the label is confirmed or removed when the gate finishes. Fork PRs have no PR number in that event, so the script finds the PR from the head SHA through issue search (commits/{sha}/pullsreturns nothing for fork commits) and then checks each hit's head. That path has not run live; it only takes effect from the default branch.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T10:26:15Z.
Follow-up review (head
433d6a24, sinceaa64a0cc, diff read, not a merge-check):433d6a24re-runs auto triage onworkflow_runcompletion ofCIandPR checks(auto-triage.yml), andtriage-one --head-shatriages every open PR whose head is that commit (find_open_prs_for_sha,triage_pr.py~541), so a label kept while a gate ran is re-evaluated when it finishes.New:
find_open_prs_for_shausessearch/issues?q=…+<sha>, which is not updated at once and is rate-limited (30 requests a minute); if a just-pushed head is not indexed yet when its CI finishes, triage prints "No open PR has head …" and the kept label stays until the next PR event. A retry, or falling back tocommits/{sha}/pullsfor same-repo PRs, would cover it.workflow_runand PR-event runs for one PR do not share a concurrency group. The new group key isgithub.event.workflow_run.head_sha, the PR events use the PR number, so a completion triage and aneditedtriage of the same PR can run at once and race on its labels.TestFindOpenPrsForShais defined afterif __name__ == "__main__": unittest.main()(scripts/test_triage_pr.py~195), which exits before reaching it, sopython scripts/test_triage_pr.pyskips the four new tests;python -m unitteststill finds them. Moving the class above the__main__block fixes it.433d6a24completesaa64a0cc(the kept labels need the completion trigger to be safe), so they read as one change;CI:is also not one of the subject prefixes CONTRIBUTING.md lists (Scripts:fits).Fine: the SHA is validated against
[0-9a-f]{40}before any request, every search hit is checked for being open and having that head, the workflow still checks out only the default branch's scripts, and the new tests cover a fork PR, no match, stale hits and a malformed SHA.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by tiagonleal on 2026-12-02T10:30:36Z.
All four are in
d570eda8, now one commit with aScripts:subject.The lookup skips
workflow_runevents that came from a push, retries the search up to 3 times 10 s apart, and also askscommits/{sha}/pullsfor same-repo PRs. The test classes are above the__main__block, so both ways of running the file run all 20.On concurrency: the PR number is not known when the group is evaluated for a fork PR, so the group uses
workflow_run.pull_requests[0].numberwhen it is filled and the head SHA otherwise. Two runs for one fork PR can still overlap. Each one reads the labels fresh and only applies the difference, and a run that sees a pending gate adds no state label, so the bad case needs a check rerun going from green to red on the same commit while an older run is still in flight. I left that alone and wrote it in the description.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T10:32:16Z.
Follow-up review (head
d570eda8, since433d6a24, diff read, not a merge-check):find_open_prs_for_sha(triage_pr.py~542) retries the search three times 10 s apart and also askscommits/{sha}/pulls, with tests for the lag and the same-repo case.__main__block is back at the end.Scripts:commit.github.event.workflow_run.pull_requests[0].number, but GitHub leavesworkflow_run.pull_requestsempty for PRs from forks, so for those (most PRs here) the key falls back to the head SHA and a completion triage can still run alongside aneditedtriage of the same PR.New: none. Skipping
workflow_runevents frompushkeeps branch CI runs from triggering triage.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by tiagonleal on 2026-12-02T15:06:29Z.
A second case today, on #3528: Kalmarv edited the description at 13:52 UTC with no push, the
PR descriptioncheck restarted (run 46896187790), andready-to-mergewas removed at 13:52:37 although its three safe checks on8b9d8dfestill stand. It has not come back, since nothing reruns triage when the check passes.