Scripts: keep triage labels while a gate runs, rerun when it completes #3686

Merged
tiagonleal merged 1 commit from upstream-pr/3686 into main 2026-12-02 18:22:23 +00:00
tiagonleal commented 2026-12-02 10:16:54 +00:00 (Migrated from github.com)

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 edited event restarts the PR description check, triage reads it as IN_PROGRESS, and compute_managed_labels only 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 remove ready-to-merge the same way.

What is in it

One commit with two parts:

  • Keep labels while a gate runs. In scripts/triage_pr.py the state-label logic moves into merge_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 and duplicate remove them as before.
  • Rerun triage when the gate completes. .github/workflows/auto-triage.yml also runs on workflow_run completion of CI and PR checks, skipping push runs. Fork PRs have no PR number in that event, so triage-one --head-sha looks up the open PRs whose head is that commit. It uses issue search, which finds fork PRs, plus commits/{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 through env:.
  • Concurrency group: the PR number, then 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.py and py -m unittest scripts/test_triage_pr.py: 20 tests each, OK. Without the triage_pr.py change, the keep test fails.

Not tested

  • The workflow_run path has not run live. It only takes effect from the default branch after merge.
  • The YAML was not parsed: there is no PyYAML here and no local workflow lint.
  • #3038 needs a new triage run (or a merge-check comment) to get its labels back.

AI use

  • Claude Code with Claude Fable 5.2 and Anthropic subagents (Claude Opus 5.5) helped developing.
<!-- greyfinch-sync:ivall/xcl:issue:5604400533 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3686). Originally posted by [tiagonleal](https://github.com/tiagonleal) on 2026-12-02T10:16:54Z. --- Editing a PR description makes Auto triage drop the merge-check labels. The `edited` event restarts the PR description check, triage reads it as IN_PROGRESS, and `compute_managed_labels` only 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 remove `ready-to-merge` the same way. **What is in it** One commit with two parts: - Keep labels while a gate runs. In `scripts/triage_pr.py` the state-label logic moves into `merge_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 and `duplicate` remove them as before. - Rerun triage when the gate completes. `.github/workflows/auto-triage.yml` also runs on `workflow_run` completion of `CI` and `PR checks`, skipping push runs. Fork PRs have no PR number in that event, so `triage-one --head-sha` looks up the open PRs whose head is that commit. It uses issue search, which finds fork PRs, plus `commits/{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 through `env:`. - Concurrency group: the PR number, then `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.py` and `py -m unittest scripts/test_triage_pr.py`: 20 tests each, OK. Without the triage_pr.py change, the keep test fails. **Not tested** - The `workflow_run` path has not run live. It only takes effect from the default branch after merge. - The YAML was not parsed: there is no PyYAML here and no local workflow lint. - #3038 needs a new triage run (or a merge-check comment) to get its labels back. **AI use** - Claude Code with Claude Fable 5.2 and Anthropic subagents (Claude Opus 5.5) helped developing.
Foniass commented 2026-12-02 10:20:40 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T10:20:40Z.


Review (head aa64a0cc, diff read, not a merge-check):

  • A kept label can outlive a failed gate. While a gate is pending, compute_managed_labels (scripts/triage_pr.py ~404-415) now keeps ready-to-merge / needs-2nd-check / needs:*-test, but auto-triage.yml runs only on PR events and merge-check comments, 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 leaves ready-to-merge on a PR with a red gate and no needs-pr-check; before, the label was dropped. ready-to-merge also exempts the PR from stale.yml. testing-feed.yml (~14-15) does run on workflow_run completion of CI and PR checks, but build-feed skips PRs that are not green (~776) and syncs labels only on workflow_dispatch, so it does not clear the label either. A workflow_run trigger for triage, or not keeping ready-to-merge while pending, would close this. A push is safe, since parse_merge_checks filters by head SHA.

Fine: the state-label logic moves into merge_check_state_labels unchanged; intersecting with existing_labels keeps 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.

<!-- greyfinch-sync:ivall/xcl:comment:7342330361 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3686#issuecomment-7342330361). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T10:20:40Z. --- Review (head aa64a0cc, diff read, not a merge-check): - **A kept label can outlive a failed gate.** While a gate is pending, `compute_managed_labels` (`scripts/triage_pr.py` ~404-415) now keeps `ready-to-merge` / `needs-2nd-check` / `needs:*-test`, but `auto-triage.yml` runs only on PR events and `merge-check` comments, 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 leaves `ready-to-merge` on a PR with a red gate and no `needs-pr-check`; before, the label was dropped. `ready-to-merge` also exempts the PR from `stale.yml`. `testing-feed.yml` (~14-15) does run on `workflow_run` completion of `CI` and `PR checks`, but `build-feed` skips PRs that are not green (~776) and syncs labels only on `workflow_dispatch`, so it does not clear the label either. A `workflow_run` trigger for triage, or not keeping `ready-to-merge` while pending, would close this. A push is safe, since `parse_merge_checks` filters by head SHA. Fine: the state-label logic moves into `merge_check_state_labels` unchanged; intersecting with `existing_labels` keeps 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.
tiagonleal commented 2026-12-02 10:25:03 +00:00 (Migrated from github.com)

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. 433d6a24 adds the workflow_run trigger: triage runs again when CI or PR checks completes, 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}/pulls returns 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.

  • Tiago
<!-- greyfinch-sync:ivall/xcl:comment:7342437876 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3686#issuecomment-7342437876). Originally posted by [tiagonleal](https://github.com/tiagonleal) on 2026-12-02T10:25:03Z. --- @Foniass you are right, a kept label could outlive a gate that then fails. 433d6a24 adds the `workflow_run` trigger: triage runs again when `CI` or `PR checks` completes, 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}/pulls` returns 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. - Tiago
Foniass commented 2026-12-02 10:26:15 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T10:26:15Z.


Follow-up review (head 433d6a24, since aa64a0cc, diff read, not a merge-check):

  • A kept label can outlive a failed gate: fixed. 433d6a24 re-runs auto triage on workflow_run completion of CI and PR checks (auto-triage.yml), and triage-one --head-sha triages 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:

  • The PR lookup relies on the search index. find_open_prs_for_sha uses search/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 to commits/{sha}/pulls for same-repo PRs, would cover it.
  • The workflow_run and PR-event runs for one PR do not share a concurrency group. The new group key is github.event.workflow_run.head_sha, the PR events use the PR number, so a completion triage and an edited triage of the same PR can run at once and race on its labels.
  • The new tests do not run as a script. TestFindOpenPrsForSha is defined after if __name__ == "__main__": unittest.main() (scripts/test_triage_pr.py ~195), which exits before reaching it, so python scripts/test_triage_pr.py skips the four new tests; python -m unittest still finds them. Moving the class above the __main__ block fixes it.
  • Two commits for one change. 433d6a24 completes aa64a0cc (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.

<!-- greyfinch-sync:ivall/xcl:comment:7342467609 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3686#issuecomment-7342467609). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T10:26:15Z. --- Follow-up review (head 433d6a24, since aa64a0cc, diff read, not a merge-check): - **A kept label can outlive a failed gate:** fixed. `433d6a24` re-runs auto triage on `workflow_run` completion of `CI` and `PR checks` (`auto-triage.yml`), and `triage-one --head-sha` triages 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: - **The PR lookup relies on the search index.** `find_open_prs_for_sha` uses `search/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 to `commits/{sha}/pulls` for same-repo PRs, would cover it. - **The `workflow_run` and PR-event runs for one PR do not share a concurrency group.** The new group key is `github.event.workflow_run.head_sha`, the PR events use the PR number, so a completion triage and an `edited` triage of the same PR can run at once and race on its labels. - **The new tests do not run as a script.** `TestFindOpenPrsForSha` is defined after `if __name__ == "__main__": unittest.main()` (`scripts/test_triage_pr.py` ~195), which exits before reaching it, so `python scripts/test_triage_pr.py` skips the four new tests; `python -m unittest` still finds them. Moving the class above the `__main__` block fixes it. - **Two commits for one change.** `433d6a24` completes `aa64a0cc` (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.
tiagonleal commented 2026-12-02 10:30:36 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by tiagonleal on 2026-12-02T10:30:36Z.


All four are in d570eda8, now one commit with a Scripts: subject.

The lookup skips workflow_run events that came from a push, retries the search up to 3 times 10 s apart, and also asks commits/{sha}/pulls for 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].number when 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.

  • Tiago
<!-- greyfinch-sync:ivall/xcl:comment:7342573979 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3686#issuecomment-7342573979). Originally posted by [tiagonleal](https://github.com/tiagonleal) on 2026-12-02T10:30:36Z. --- All four are in d570eda8, now one commit with a `Scripts:` subject. The lookup skips `workflow_run` events that came from a push, retries the search up to 3 times 10 s apart, and also asks `commits/{sha}/pulls` for 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].number` when 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. - Tiago
Foniass commented 2026-12-02 10:32:16 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T10:32:16Z.


Follow-up review (head d570eda8, since 433d6a24, diff read, not a merge-check):

  • The PR lookup relies on the search index: fixed. find_open_prs_for_sha (triage_pr.py ~542) retries the search three times 10 s apart and also asks commits/{sha}/pulls, with tests for the lag and the same-repo case.
  • The new tests do not run as a script: fixed; the __main__ block is back at the end.
  • Two commits for one change: fixed; one Scripts: commit.
  • Completion and PR-event runs do not share a concurrency group: partly fixed. The group now uses github.event.workflow_run.pull_requests[0].number, but GitHub leaves workflow_run.pull_requests empty 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 an edited triage of the same PR.

New: none. Skipping workflow_run events from push keeps branch CI runs from triggering triage.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7342615245 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3686#issuecomment-7342615245). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T10:32:16Z. --- Follow-up review (head d570eda8, since 433d6a24, diff read, not a merge-check): - **The PR lookup relies on the search index:** fixed. `find_open_prs_for_sha` (`triage_pr.py` ~542) retries the search three times 10 s apart and also asks `commits/{sha}/pulls`, with tests for the lag and the same-repo case. - **The new tests do not run as a script:** fixed; the `__main__` block is back at the end. - **Two commits for one change:** fixed; one `Scripts:` commit. - **Completion and PR-event runs do not share a concurrency group:** partly fixed. The group now uses `github.event.workflow_run.pull_requests[0].number`, but GitHub leaves `workflow_run.pull_requests` empty 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 an `edited` triage of the same PR. New: none. Skipping `workflow_run` events from `push` keeps branch CI runs from triggering triage. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
tiagonleal commented 2026-12-02 15:06:29 +00:00 (Migrated from github.com)

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 description check restarted (run 46896187790), and ready-to-merge was removed at 13:52:37 although its three safe checks on 8b9d8dfe still stand. It has not come back, since nothing reruns triage when the check passes.

  • Tiago
<!-- greyfinch-sync:ivall/xcl:comment:7349731809 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3686#issuecomment-7349731809). Originally posted by [tiagonleal](https://github.com/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 description` check restarted (run 46896187790), and `ready-to-merge` was removed at 13:52:37 although its three safe checks on 8b9d8dfe still stand. It has not come back, since nothing reruns triage when the check passes. - Tiago
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!3686
No description provided.