Skip to content

[CI] Stop expensive checks when an unmerged PR closes - #25829

Merged
nwparker merged 3 commits into
mainfrom
nwparker/ci-closed-pr-cancellation
Oct 6, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/ci-closed-pr-cancellation

Conversation

@nwparker

@nwparker nwparker commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Closing a PR without merging should stop its expensive checks. Today, checks can keep using runners after the work has been abandoned.

What Changed

Extend the existing trusted closed-PR cleanup workflow to request cancellation of active PR Checks, headless Node, Windows SSH, hostile-host SSH, mobile and computer E2E runs. Identify runs through GitHub's exact PR concurrency groups, then verify the workflow, event and creation time before cancelling. Recheck that the same unmerged closure is still current before every cancellation.

Cache cleanup still runs after a cancellation error. There is no PR checkout in this privileged workflow. Merged, reopened, unrelated, manual and release runs are retained. Test assignments, worker counts and platform coverage stay as they are.

Why

In the October 5–6 demand sample, unmerged PR #25726 closed at 00:36:40 UTC, but its headless run consumed another 2,203 runner-seconds (36.7 minutes) after closure. An additional historical Windows serve run used 170 seconds, but that removed workflow is outside this patch's scope. This is an observed waste example, not a daily savings estimate.

GitHub clears the closed PR association from some run/check-suite responses. Exact concurrency groups provide positive PR identity without guessing from branch names or commit IDs. Reusing the current no-checkout cleanup workflow avoids adding a runner job to every CI workflow. Only six high-cost workflows are queried, with inactive groups treated as normal.

Linked Issue

Maintainer CI efficiency follow-up; no new issue needed.

Visual Proof

N/A — GitHub Actions cleanup only; no application UI changes.

Testing

  • Local workflow-script and cache-cleanup tests: 2 files, 20 cases pass. Cases cover reopened/merged PRs, later closures, unrelated/manual/release runs, post-close runs, job-level leases, identity mismatches and API permission failures.
  • Formatting, lint and actionlint pass.
  • Live unmerged-close qualification: the exact production inline script requested cancellation of queued PR run 37431125293 at 07:44:27 UTC; GitHub reports completed/cancelled at 07:44:28. The qualification job occupied eight runner-seconds. This proves queued-run cancellation with the actual token, group API and PR identity; it does not measure active-run cancellation latency or daily savings.
  • Merged-PR control retained merged PR Document Apple Git ref recovery retirement condition #25822.
  • Delayed close event against an open PR passed and retained PR [CI] Build SSH host compatibility slots in parallel #25821's active checks. This control supplies the closed event identity, then reads the real current open state through the production script. An initial harness supplied a null closure time and was rejected; it is excluded from qualification evidence.
  • Local targeted checks and all live controls pass. The normal preflight run failed on the unchanged main-branch src/shared/protocol-version.ts max-lines violation (301 code lines), before unit fan-out. GitHub reports no required branch checks; merging uses normal repository policy, without an administrator override. The temporary qualification workflow is absent from this review diff.

Review

Review the exact group/workflow allowlist and the current-closure check before mutation. The existing Actions write permission is retained; Pull requests read is added for that check. Cancellation uses the normal API, preserving runner cleanup. API failures remain visible and cache cleanup still proceeds.

Agent skill upstream boundary

  • Not applicable; no upstream skill-installer material is copied.

Notes

All six skill areas were audited against current workflow code, documented validation commitments and the October 5–6 demand report (415 sampled runs out of 6,810):

Area Finding and decision
Dependency caching pnpm verification, native artifacts, Electron archives and TypeScript state already have scoped caches and fallback validation. Root PR installs deliberately use direct downloads after measured archive overhead. Sampled pinned Pi installs take roughly 4–26 seconds; another cache has no demonstrated net benefit. Retain the current policy.
Concurrency cancellation Superseded updates already cancel. Unmerged closure leaves a demonstrated gap; this PR addresses it.
Duplicate coverage Separate real-shell, headless, platform and scheduled compatibility checks protect different behavior. Source-only checks already run once. No safe further removal identified.
Narrow triggers PR job classifiers, dependency-aware headless routing and workflow path filters already preserve unknown-input fallbacks and required aggregate checks. No supported extra narrowing identified.
Matrix scope Windows inbox/preview × x64/ARM, Mac architectures, Linux libc floors, supported Node versions and skill installation modes have explicit compatibility purposes. Retain them.
Critical-path parallelism PR #25821 runs independent SSH build slots in parallel; two hosted pairs reduced its Linux chain by 33.0% and 17.5%, with smaller whole-workflow gains and no runner-cost saving claimed. Broader compiler/lint overlap was rejected because the compiler already reserves memory by project and the heavy node/web pair exceeds the hosted runner's safe budget.

The report estimates 696.5 daily runner-hours for PR Checks, 92.8 for Windows SSH and 87.2 for headless Node. These are sampled full-run durations, not billing totals. Closing obsolete work frees capacity; it does not establish lower whole-PR percentiles.

Checklist

  • Small and focused; explains the behavior, mechanism and reason.
  • Visual proof is N/A with reason.
  • Self-reviewed security, platform and SSH boundaries; runtime behavior is unchanged.
  • Live qualification passes; the unrelated main-branch preflight failure is disclosed above.

@nwparker
nwparker marked this pull request as ready for review October 6, 2026 08:02
@nwparker
nwparker merged commit 13ea359 into main Oct 6, 2026
25 of 27 checks passed
@nwparker nwparker changed the title Stop expensive checks when an unmerged PR closes [CI] Stop expensive checks when an unmerged PR closes Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant