ci: add safe stale run janitor
Merged
TE
2mo ago+322+322+012345678901234567890123456789-0-0-0123456789
Problem
Queued and in-progress Actions runs can remain after their pull request is merged or closed. They consume queue capacity and make the live backlog hard to distinguish from useful work.
Change
- Add a scheduled, report-only janitor that inspects queued and in-progress runs every 30 minutes.
- Resolve each run's commit to its associated pull requests through the GitHub API.
- Consider only runs older than 24 hours whose PRs are all closed or merged.
- Preserve runs with no PR, an open PR, or a reused branch with an open PR.
- Add an explicit
workflow_dispatchcleanup mode, capped at 25 actions. Queued runs are deleted; in-progress runs are cancelled. - Run the control plane on the fixed GitHub-hosted runner with narrowly scoped
actions: writepermission.
Scheduled runs are always dry runs, so rollout starts with an auditable inventory. Manual cleanup is opt-in and bounded.
Validation
python3 -m unittest -v tests/test_cleanup_stale_runs.pypython3 -m py_compile scripts/ci/cleanup-stale-runs.py./tests/test_ci_self_hosted_guard.shgit diff --check
Summary by cubic
Adds a scheduled janitor that reports queued and in-progress Actions runs stranded by closed or merged pull requests, so stale runs stop hiding useful work in the backlog (addresses #13117, #13128). Scheduled runs are always dry runs, so rollout starts with an auditable inventory.
- Runs every 30 minutes; manual
workflow_dispatchwithcleanup=truedeletes queued runs and cancels in-progress ones, capped at 25 actions. - Only
pull_requestruns older than 24 hours whose pull requests are all closed or merged are eligible; runs with no PR, any open PR, or non-PR events are preserved. - Cleanup rechecks each run and its PRs right before acting, so completed runs and reopened PRs are skipped.
- Runs on the fixed GitHub-hosted runner with
actions: writescoped to this workflow only. - Manual cleanup rejects non-positive age/action limits and any
max_actionsabove 25.