Fix false-positives with the caches and improve hit-ratio - #4971
Conversation
|
Claude finished @naanselmo's task in 1m 58s —— View job Review: Fix false-positives with the cachesThe change flips This looks correct. Reasoning:
No blocking issues. One thing worth being aware of (already an inherent consequence of the fix, not a request to change): deploy builds will now always recompile all workspace crates, so expect longer build times than before — the dependency cache still helps, but the incremental workspace speedup is gone. That's the correct call for a job whose output ships to production. The rest of the caching setup ( LGTM ✅ — verifying via CI (as the PR suggests) is the right final check.
|
|
Claude finished @naanselmo's task in 3m 15s —— View job PR Review: Fix false-positives with the cachesI traced the correctness of the new caching scheme end-to-end and it holds up — this is a solid fix. Why the mtime approach is correct (the core of the PR):
Ordering is also right: Other changes look good: Two non-blocking suggestions (posted inline):
No correctness or blocking issues found. Agree with the PR's own advice that CI is the right final validation.
|
Description
Fixes the false-positives in the caches in the deploy job, caused by a cached crate from "the future" being incorrectly used.
Example timeline to show the bug being reproduced:
main-1, builds cachemain-1.main-2, built on top ofmain-1, pulls the freshest cache,main-1, and builds cachemain-2.hotfix-1, built on top ofmain-1, pulls the freshest cache...main-2. Things will now go wrong.For files we changed in a given PR, everything is OK, because
git-restore-mtimeruns, the files are more recent than the caches themselves, so the caches are invalidated and things are rebuilt from scratch.The real problem comes from changes that
main-2made: they show up in themain-2cache. However, when git-restore-mtime runs, the files get the older timestamp. So what does cargo see? Well, a fresh cache, and the supposed source files for it are older. So the cache is considered valid.This PR iterates on this, to build a solution that 1) keeps cache on for workspace crates and 2) keeps a high hit-rate on the cache but 3) doesn't have false-positives.
It also adds
sccache, another tool that improves caching when the main cache hit misses, as it can cache certain build artifacts, but only at therustclevel (so after cargo has already determined it needs to rebuild a crate). This is the least impactful change, and it might end up being removed in the future.PS: This PR is actually a +64/-63, but the mtime-cache that we use is used in https://github.com/denoland/deno but never made usable as an action. We could reference it to use it but it'd require pulling the entire repo on every execution.
Changes
git-restore-mtime: it stamps based on the commit time, which is exactly what we don't want due to the "cache from the future" problem;mtime-cache: stamps based on the content hash, so the cache will contain the hashes of the files as they were when the cache was built, meaning it can invalidate partially (by not updating the timestamp) when they are different (warning: it is MIT-licensed but I believe it is OK since we include the license);sccache: should improve cache hit ratio on anything that the previous caching tools miss, accuracy remains to be tested (it outputs metrics so we can validate over time);--lockedto cargo arguments, where absent.How to test