Skip to content

ci: restore the race test cache by prefix and save it only from main - #2437

Merged
rdimitrov merged 1 commit into
mainfrom
ci/race-test-cache
Oct 20, 2026
Merged

rdimitrov merged 1 commit into
mainfrom
ci/race-test-cache

Conversation

@rdimitrov

@rdimitrov rdimitrov commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Why Test (race) takes 17-23 min on most runs

It comes down to a cache hit versus a cache miss, not slow packages or runner variance.

Run (job) setup-go cache Packages run / cached Test modules step
118586993750 hit 48 / 145 6.5 min
118562512820 hit 48 / 145 6.5 min
118513660250 hit 48 / 145 5.3 min
118586642248 miss 193 / 0 16.0 min
118570499382 miss 193 / 0 20.2 min
118562772980 miss 193 / 0 21.7 min
118552479761 miss 193 / 0 16.8 min

On a hit, 145 of 193 packages reuse cached -race test results and compiles are warm. On a miss, every package is recompiled with -race and retested on 4 vCPUs.

Two reasons for the misses:

  • No fallback key. setup-go keys its cache on a hash of every go.sum and has no restore-keys. Any Renovate bump anywhere in the module set produces a new key and a fully cold run, until a main run saves one.
  • Quota thrash. Every PR run saves its own ~1.8 GB entry into a PR-scoped cache that no other PR can read. The repository holds about 17.8 GB of caches against a 10 GB quota, so the main entry, the only one all PRs share, gets evicted.

Slowest packages on a cold run (job 118586642248, under 4-way contention):

Package Time
cmd/mecatui/ui 397 s
deploy/helm/mecatl-execution 166 s
internal/app 162 s
deploy/mecatl-execution-kind 142 s
internal/adapter/server 127 s
deploy/helm/mecak8s 96 s
engine/governance 74 s
environment/microvm 63 s
cmd/mecatui (two test binaries) 52 s each
internal/apicheck 48 s

cmd/mecatui/ui runs 360-560 s even when warm, so the job can't drop much below about 6 min without sharding. That isn't needed to reach the ~9 min target, so this PR leaves it alone.

Change

In the Test (race) job only:

  • setup-go with cache: false.
  • actions/cache/restore keyed go-race-<os>-<arch>-go<version>-<sha>, with restore-keys on the prefix, so a run always gets the newest entry. Go's build and test caches are content-addressed, so an entry from a nearby commit is still almost entirely valid.
  • actions/cache/save only after a green push to main. PR runs no longer write entries, which also means fork PRs can't seed cache entries. Every PR restore marks the main entry as recently used, so LRU eviction keeps it.

The Test (race) check name and every other job are unchanged.

Before / after

Measured on this PR, with a temporary commit that let it seed its own entry (since dropped). A stacked PR reads its base branch's cache scope, not main's.

Run Cache Packages run / cached Restore Test modules Job total
cold, job 118596442519 none (first entry) 193 / 0 — 15.8 min 16.9 min
warm, job 118603729931 prefix restore of the cold run's entry (different SHA) 48 / 145 25 s, 1.7 GB 6.4 min 8.0 min

The warm job includes a 20 s save step that PR runs won't have once the TEMP commit is gone, so a PR job should take about 7.7 min.

Caveat: the cache is saved only from main, so PRs opened right after this merges stay cold (~17 min) until a push to main has saved the first go-race- entry. That main run is itself cold. Every later main push refreshes the entry.

Verification

  • actionlint (pinned v1.7.7), lint:action-templates, test:docs-only-classifier, deslop and noindex workflow tests: pass.
  • task lint fails locally only on a gosec finding in environment/microvm/launch_ownership_darwin.go. That file is darwin-only, outside this diff, and not linted on CI's Linux runner.

🤖 Generated with Claude Code

Base automatically changed from claude/festive-mclean-7dc29f to main October 20, 2026 11:35
The Test (race) job took 5-7 minutes when setup-go restored its Go build
and test cache, and 16-23 minutes when it did not. setup-go keys that cache
on a hash of every go.sum with no fallback, so any dependency bump or
evicted entry made the next run fully cold. Every PR run also saved its
own ~1.8 GB entry, which pushed the repository past its cache quota and
evicted the main entry that other PRs could have shared.

Restore the newest main entry by key prefix instead, and save a fresh
entry only after a green push to main. Go's caches are content-addressed,
so an entry from a nearby commit is still almost entirely valid.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@rdimitrov
rdimitrov merged commit 0a2f257 into main Oct 20, 2026
43 checks passed
@rdimitrov
rdimitrov deleted the ci/race-test-cache branch October 20, 2026 11:58
@toolhive-release-app toolhive-release-app Bot mentioned this pull request Oct 23, 2026
2 tasks
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