Skip to content

perf(ci): stop duplicating shared Linux download caches - #23578

Merged
nwparker merged 5 commits into
mainfrom
nwparker/ci-shared-download-caches
Sep 28, 2026
Merged

nwparker merged 5 commits into
mainfrom
nwparker/ci-shared-download-caches

Conversation

@nwparker

@nwparker nwparker commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

CI keeps uploading copies of downloads that other PRs cannot use. Share the Linux downloads from main and remove disposable PR caches when the PR closes, freeing space for reusable caches.

What Changed

  • Existing x64 and ARM main warmups populate Electron's archive using the existing binary installer, while preserving the Node native-module ABI. Linux PRs restore the same archive without saving their own copy; macOS and Windows retain their current behavior.
  • Linux packaging restores electron-builder's existing shared cache and fallback prefix without a post-job upload. Missing tool versions still download normally. Release builds remain the shared writer.
  • A closed-PR workflow deletes only caches under that PR's merge ref. It runs trusted default-branch code without checkout, validates each returned ref, and tolerates cache eviction races. It cannot delete main caches through PR-controlled code.

Why

A 193-entry snapshot on 2026-09-28 totaled 10.86 GB. The main pnpm stores accounted for 4.19 GB and were actively reused, so they are retained. The avoidable duplicates were:

Cache PR-scoped footprint Finding
Linux ARM Electron archives 2.81 GB / 22 copies No matching main archive was being produced
Linux electron-builder downloads 1.80 GB / 22 copies Same cache format as the existing main archive; fallback restores still triggered PR uploads
All caches on already-closed PRs 1.48 GB / 34 entries Removed during the audit; overlaps the categories above

The completed Linux package job restored the shared 78 MiB builder archive in two seconds, then spent three seconds uploading another PR copy. This change removes that upload and duplicate storage, rather than removing useful caching. Native builds, package checks, and tests remain intact. The audit also found 334 MB of Ruby caches and 294 MB of xterm inputs; those are not blanket-deleted while PRs are open.

Linked Issue

N/A — maintainer-requested CI capacity work. Follows #23568.

Visual Proof

N/A — CI and cache lifecycle only.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated

366 workflow tests passed across 21 files; 35 relevant tests passed again after limiting archive sharing to Linux. Actionlint passes for the warmup and cleanup workflows. Existing PR workflow extensions (background/wait) are covered by repository tests because the installed actionlint does not support them. Cleanup tests cover the exact PR ref, refusal to delete a main cache, 404 races, and non-404 errors. Hosted warmup run: both Linux warmups passed. Populating the Electron archive took 2 seconds on x64 and 3 seconds on ARM in the existing jobs; the ARM job also passed its Node native-cache probe afterward. Main saves are not enabled on this PR validation run. Hosted Linux packaging job passed: shared archive restore took 1 second, with no post-job archive upload (baseline: 2-second restore + 3-second duplicate save). All normal CI checks passed before merge (full run).

Review

Compared the merge result against main after #23568 merged: only the nine intended cache/workflow/test files change, and those files are byte-identical to the tested PR head. The parent commits may still appear in GitHub’s comparison because the parent was squash-merged.

Confirmed main and PR electron-builder entries have the same cache version (path/archive format), not merely similar keys. Archive keys remain platform/architecture/version-specific. The new cleanup token has only actions: write; the workflow never checks out or executes PR source. No native ABI, runtime behavior, test coverage, SSH, folder-workspace, or mobile protocol changes.

Agent skill upstream boundary

  • Not applicable; no skill content copied.

Checklist

  • Focused on shared download caches and PR-cache lifecycle
  • Before/after, mechanism, alternatives, and measurements explained
  • Visual proof N/A
  • Self-reviewed permissions and cache scope
  • Cross-platform and remote impact considered
  • Focused tests pass; full CI required before merge

Post-merge verification

Both Linux jobs in the main warmup passed. The missing main ARM Electron archive was published with the same key and cache-format version as the redundant PR copies. The production closed-PR cleanup passed and removed 11 caches for this PR.

Manual cleanup deleted 53 entries totaling 3,910,742,622 bytes (3.91 GB): 34 closed-PR entries, then 19 duplicate Electron archives only after the matching main archive existed. The active main pnpm stores and useful native caches were retained. Concurrent jobs can add entries, so this is the size deleted, not a claim that the live usage counter fell by exactly that amount.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Shared Electron archive for Linux PRs — install-node-dependencies splits the archive cache into a saving actions/cache@v5 step (non-PR, or non-Linux) and a restore-only actions/cache/restore@v5 step for Linux pull requests, so PRs reuse the archive warmed on main without uploading their own copy.
  • Warmup seeds the shared archive — ci-cache-warmup.yml's warm and warm-linux-arm jobs opt into cache-electron-package and run install-electron-package-binary.mjs, producing the x64 and ARM64 keys.
  • Linux electron-builder PR cache is restore-only — pr.yml's package job now restores electron-builder-linux-* with no post-job save; release-cut stays the writer.
  • Closed-PR cleanup workflow — new pull_request_target: closed job deletes only caches scoped to refs/pull/<n>/merge, runs trusted default-branch code without checkout, validates every returned ref, and tolerates 404 eviction races.
  • Contract tests updated — pinned if:/uses assertions across four existing tests plus a new ci-closed-pr-caches.test.mjs that exercises exact-ref, default-branch-refusal, 404, and 403 cases.

I read the full diff, traced the touched actions/workflows, and ran the affected config/scripts contracts (41 files / 599 tests) — all pass. The security posture checks out: the cleanup never checks out or executes PR source, and deleting by refs/pull/<n>/merge cannot reach main caches. The Dependabot read-only token restriction applies to pull_request/push/review events, not pull_request_target, so the cleanup retains actions: write for fork and Dependabot closes.

ℹ️ Closed-PR cleanup is best-effort under in-flight runs

The cleanup runs at closed, but closing a PR does not cancel its running workflows. A run still finishing can execute its post-job cache save (the native-modules cache is still saved on PRs) after the deletion loop completes, leaving a fresh orphan under the same merge ref. I don't think this needs a change — the 7-day eviction catches it, and the strict ref check already favors safety over completeness — but it's worth knowing the cleanup is not a hard guarantee.

Technical details
# Closed-PR cleanup can be undone by an in-flight PR run

## Affected sites

- `.github/workflows/ci-closed-pr-caches.yml:16-33` — the deletion loop runs once, on the `closed` event.
- `.github/actions/install-node-dependencies/action.yml:218-227` — `Restore compiled native modules` (`actions/cache@v5`, `native-cache-restore`) still registers a post-job save for PR events (`persist-native-cache` defaults to `true`), so a mid-flight PR job can save after cleanup.

## Required outcome

- None required for this PR; documenting the race so future maintenance does not assume the sweep is exhaustive.

## Open questions for the human

- Is a follow-up sweep (or the existing 7-day eviction) considered sufficient for any residual merge-ref caches?

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker changed the base branch from nwparker/ci-pnpm-cache-pilot to main September 28, 2026 08:50
@nwparker
nwparker merged commit d050801 into main Sep 28, 2026
50 checks passed
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