Skip to content

fix(build-cache): save a new generation when a warm hit still compiles (#682) - #685

Merged
zackees merged 1 commit into
mainfrom
fix/682-buildcache-generations
Nov 20, 2026
Merged

zackees merged 1 commit into
mainfrom
fix/682-buildcache-generations

Conversation

@zackees

@zackees zackees commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

Fixes #682.

Problem

The build-cache key is commit-free (#237), so saveOne returned exact-hit-skip on every exact hit. The first writer's zccache store stayed frozen until the lockfile, toolchain or soldr changed. Every crate edited since then missed on every run: FastLED/fbuild's Dylint missed 62/33/33 units per pass even though post reported an exact hit.

Change

  • Restore (src/main.ts, buildCacheRestoreRequest): the primary key is now <exact-key>-g, followed by the bare key and the job fallback. The primary never exists literally, so GitHub prefix-matches it and returns the newest generation. The bare key is also a prefix of every generation, so the newest one still wins if the primary is not prefix-matched.
  • Warm: a match on the exact key or on one of its generations (isWarmBuildCacheMatch) counts as a hit (build-cache-hit: true).
  • Save (src/post.ts, planBuildCacheSaveKey): a warm store whose session compiled at least max(1, build-cache-save-min-compiles) units saves <exact-key>-g<GITHUB_RUN_ID>[-<attempt>]. Zero compiles, an unknown count, or no run id keep exact-hit-skip. Cold and fallback restores still save the bare key. decideBuildCacheSave runs first, so the fix(cache): apply the Dylint thin-store skip only when the layer was not restored #681 rule still refuses a thin cold seed.
  • Eviction (sweepSupersededBuildCacheGenerations in cache-supersede.ts): after a generation saves, older <exact-key>-g* entries are deleted with the cook layer's existing deleteSupersededFamilyEntries. Only that prefix is swept. The bare key is kept as the fallback, so a key holds at most the bare entry plus one generation. A sweep that cannot list or delete (no actions: write) becomes a warning. NO_CACHE_SUPERSEDE=1 turns it off.

dylint-output-cache

It has the same exact-hit freeze (post.ts: "exact hit - skipping save"). I left it alone because the same mechanism doesn't apply cleanly: that layer has no compile-delta signal to gate a generation on, so it would re-upload on every exact hit. With the build-cache now refreshing, the units cargo re-checks under a stale output tree hit zccache, which limits the remaining cost. A follow-up could gate it on output files newer than the restore.

S3 remote-cache keys are unchanged.

Tests

Written first and confirmed failing: __tests__/cache-keys.test.ts (key and restore-key shape, generation recognition), __tests__/compile-cache-stats.test.ts (exact hit with compiles vs without, generation restore gating, cold/fallback, no run id, #681 thin seed), and __tests__/cache-supersede.test.ts (sweep prefix and targets, actions: write warning, non-generation keep key). npm run typecheck, npm run lint, npm run test:select-check and npm test pass (1166 pass, 1 skipped watchdog). dist/ was rebuilt and the local gate stamped HEAD.

#682)

The build-cache key is commit-free (#237), so `saveOne` returned
`exact-hit-skip` on every exact hit and the first writer's zccache store
stayed frozen until the lockfile, toolchain or soldr changed. Every crate
edited since then missed on every run; FastLED/fbuild's Dylint missed
62/33/33 units per pass for this reason.

- Restore asks for `<exact-key>-g` first, then the bare key, then the job
  fallback. The primary never exists literally, so GitHub returns the newest
  generation; the bare key also prefix-matches it if needed.
- A restore of the exact key or one of its generations is warm
  (`build-cache-hit: true`).
- A warm store whose session compiled at least
  `max(1, build-cache-save-min-compiles)` units saves
  `<exact-key>-g<GITHUB_RUN_ID>[-<attempt>]`; otherwise it is still an
  `exact-hit-skip`. Cold and fallback restores save the bare key, and the
  #681 thin-store gate runs first, so a thin cold seed never wins.
- After a generation saves, older generations of that key are deleted with
  the cook layer's supersede sweep (`deleteSupersededFamilyEntries`). The
  bare key is kept as the fallback. A sweep that cannot list or delete
  (no `actions: write`) becomes a warning.

dylint-output-cache has the same exact-hit freeze but no compile-delta
signal to gate a generation on, so it is left as is.

Local-Gate: v1 tree=2c361884e24f1838f1b17c1ddd36dd1587590f1e secs=114 lanes=lint:run,typecheck:run,tests:run
Ci-Attestation: {"at":1795160452,"gate":"general/all/lint","host":"linux-x86_64","key":"ecc148cf8e96","lane":"lint","parents":["21e4d0b66b0093a790e15cb4e4acc25a29af84c1"],"secs":0,"stamp":"399b1a317f9b36bc76a6898b96b770ba","tree":"2c361884e24f1838f1b17c1ddd36dd1587590f1e","v":1,"via":"run"}
Ci-Attestation: {"at":1795160452,"gate":"general/all/typecheck","host":"linux-x86_64","key":"38aaf1d9c65f","lane":"typecheck","parents":["21e4d0b66b0093a790e15cb4e4acc25a29af84c1"],"secs":4,"stamp":"72bb4553b4ca12b6673a93fea7951ee5","tree":"2c361884e24f1838f1b17c1ddd36dd1587590f1e","v":1,"via":"run"}
Ci-Attestation: {"at":1795160452,"gate":"general/linux-x86_64/test","host":"linux-x86_64","key":"06da1c109f53","lane":"tests","parents":["21e4d0b66b0093a790e15cb4e4acc25a29af84c1"],"secs":109,"stamp":"141f4a527fbb761153c3ecf0a5bcdb27","tree":"2c361884e24f1838f1b17c1ddd36dd1587590f1e","v":1,"via":"run"}
@zackees
zackees added this pull request to the merge queue Nov 20, 2026
Merged via the queue into main with commit b52b021 Nov 20, 2026
56 of 57 checks passed
zackees added a commit that referenced this pull request Nov 20, 2026
GitHub's cache lookup exact-matches the primary key and every restore key
before it tries any prefix. #686's single request, [`<exact>-g`, `<exact>`,
...fallbacks], therefore still exact-hit the bare entry: FastLED/fbuild run
44790566297 restored `...-s57d57d7814452b77` while generation
`...-g44767084261` existed, and missed 64/30/30 units again.

Restore now makes up to two lookups (`buildCacheRestoreRequests`):
1. `<exact>-g` only. Nothing is saved under that literal name, so the exact
   pass misses and the prefix pass returns the newest generation.
2. Only on a miss: the pre-#685 request, bare `<exact>` plus the job
   fallback. It exact-hits this lockfile's bare entry, which is warm.

Dropping the bare key and relying on the job prefix alone would let a newer
generation of another lockfile beat this lockfile's bare entry; that donor
restore is not warm, so the run would never start its own generation.

The simulation tests now model GitHub's real order (exact pass over all
keys, then prefix per restore key, newest first) as well as the documented
order, and include the bare + g1 regression and the other-lockfile case.

Local-Gate: v1 tree=cb1a7ccac16dd739fba43be6e9d8c25b94ea4ba9 secs=182 lanes=lint:run,typecheck:run,tests:run
Ci-Attestation: {"at":1795206848,"gate":"general/all/lint","host":"linux-x86_64","key":"47a9b02285f9","lane":"lint","parents":["1e1ae41b04c5a0b050e637d0a4d3f8cd30bfb83e"],"secs":0,"stamp":"0cf6a1d079c03e2e4952d6cfb22db7c2","tree":"cb1a7ccac16dd739fba43be6e9d8c25b94ea4ba9","v":1,"via":"run"}
Ci-Attestation: {"at":1795206848,"gate":"general/all/typecheck","host":"linux-x86_64","key":"f05ee26cef42","lane":"typecheck","parents":["1e1ae41b04c5a0b050e637d0a4d3f8cd30bfb83e"],"secs":6,"stamp":"235d7b0ea75500b50cde5575fdcefbef","tree":"cb1a7ccac16dd739fba43be6e9d8c25b94ea4ba9","v":1,"via":"run"}
Ci-Attestation: {"at":1795206848,"gate":"general/linux-x86_64/test","host":"linux-x86_64","key":"34676ca279e3","lane":"tests","parents":["1e1ae41b04c5a0b050e637d0a4d3f8cd30bfb83e"],"secs":174,"stamp":"23e60f65d68bd73dfc11afe501e6c5a8","tree":"cb1a7ccac16dd739fba43be6e9d8c25b94ea4ba9","v":1,"via":"run"}
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.

build-cache: exact hit is never re-saved, so recurring zccache misses persist until the key changes

1 participant