Skip to content

ci: fix the Go build cache never being hit - #1732

Open
u9g wants to merge 1 commit into
mainfrom
ci/fix-go-build-cache
Open

ci: fix the Go build cache never being hit#1732
u9g wants to merge 1 commit into
mainfrom
ci/fix-go-build-cache

Conversation

@u9g

@u9g u9g commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

The Test job compiles the module from scratch on every run, because neither of the two caches configured here has ever produced a hit.

The actions/cache step used a constant key. key: livekit-protocol never changes, and actions/cache does not re-save on a hit, so the entry stayed frozen at whatever it held when first written. The cache API reports it as 364 MB, created 2025-09-08, still being restored today — and because every run reads it, its last-accessed time keeps refreshing, so it never ages out either. Nothing in it could match: it cached all of ~/.cache, whose go-build entries are keyed by compiler build ID, so a newer toolchain misses every one. It cost time on every run and left a GOCACHE full of dead entries that setup-go then re-uploaded.

setup-go's built-in cache cannot close the gap. Its key is setup-go-{os}-{arch}-{linuxver}go-{version}-{go.sum hash}, and it calls restoreCache with no restore keys — a match is exact or nothing, and upstream has declined to add prefix fallback (actions/setup-go#404). So any dependency bump rebuilds everything rather than just the part that changed, and a Go point release rotates the key out from under every open PR at once.

The repo is over its cache budget. It currently holds 12.24 GB against a 10 GB limit, so entries are being evicted continuously. Five refs/pull/N/merge entries of 585–798 MB each are setup-go saves from pull request runs, in a scope no other run can read.

What this changes

  • Drops the dead actions/cache step.
  • Sets cache: false on setup-go and restores via actions/cache/restore, keyed on the go.sum hash with a prefix fallback, so a dependency change reuses the entries that are still valid.
  • Suffixes the key with run_id so it never matches on write. A push therefore always stores a fresh entry, rather than one pinned to the go.sum that first created it.
  • Limits saving to pushes. Pull requests read main's entry and write nothing, which keeps roughly a gigabyte per PR run out of the repo's 10 GB budget.

Narrowing the paths to ~/.cache/go-build and ~/go/pkg/mod drops ~/go/bin. Binaries installed there are re-go installed on every run regardless, and the build cache covers most of that cost.

Follow-up, not in this PR

The stale entries need clearing to get back under budget, including the 364 MB livekit-protocol one this PR stops writing to.

@changeset-bot

changeset-bot Bot commented Aug 21, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 31b2db9

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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.

3 participants