Repository navigation
Improve ccache strategy and statistics reporting in CI builds - #9887
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
Measured results, and the cache-retention questionThe fix worksTwo
The Windows compile step alone went from 99.0 min to 6.9 min. Cache restore costs 0.2 min, save 0.3 min. Run 2 restored exactly what run 1 wrote and then rotated it forward: Two findings worth recording:
Measured sizes confirm the caps rather than guessing at them: Windows 0.9G of 2.0G (46%), all others 0.4G of 1.0G (38–44%). At 1G a single cold Windows build would sit at ~90% and begin self-evicting, so the platform-specific bump was necessary. No further sizing change. On "Bound run-scoped cache retention"The concern is worth taking seriously, but the stated mechanism does not hold. GitHub's eviction policy is:
That is LRU by access, not oldest-created. Stale run-scoped entries from superseded runs are never restored again, so they are precisely the entries with the oldest access date — LRU already evicts exactly the ones that should go, and it does so before touching anything in active use. Explicit cleanup would mostly duplicate that, while requiring One correction to the "crowds out Measured budget, from the five uploads in run 1: So the pressure is real, just not the failure mode described. The genuine risk is write churn: a PR's previous cache could be evicted before its next run, degrading hit rate. The effective lever there is not cache deletion but reducing redundant runs — Generated by Claude Code |
The build cache was restored on every run but written exactly once. actions/cache only saves in its post step when the *primary* key missed, and the key here was static per branch/PR, so after the first successful run the entry was frozen forever. Every later build restored a stale cache and recompiled everything: the last green develop run rebuilt 2881 of 2883 ninja edges, taking 2h08m of the 2h23m Windows job. Split restore/save and make the primary key unique per run so the save always happens, keeping the restore-keys prefix ladder to pick up the most recent cache. Save only outside pull requests -- PR-created caches are visible to that PR alone, so writing them would consume the shared 10 GB repository budget (evicting the ~1.6 GB Windows contrib cache) without benefiting anyone else; PRs restore from develop instead. Raise CCACHE_MAXSIZE to 2G on Windows. A full build produces ~1900 objects and MSVC builds them with /bigobj, so 1G could not hold one build -- the cache evicted itself while still being filled. Also print `ccache --show-stats --verbose` after the build. There was previously no way to tell from a log whether caching worked at all, which is what let this go unnoticed. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TWMCQa5fNDyMCyFpPwx9zU
The previous commit gated the save step on `github.event_name != 'pull_request'`, on the assumption that pull requests could rely on a develop cache refreshed by every push to develop. There is no such refresh: test.yml has push triggers for nightly and release/* only, not for develop. Of the last 30 test.yml runs, 29 were pull_request, one was workflow_dispatch and none were push, so that condition would have meant the cache was practically never written -- a regression rather than a fix. Save on every event instead. A cache written by a pull request run is scoped to that pull request, so it only helps later pushes to the same one, but that is the loop developers actually iterate in. Note the remaining gap in the file while it is fresh: caches created on develop (the default branch) are the only ones every pull request can read, so a first run on a new pull request is fast only when develop's cache is fresh. That needs test.yml to run on develop regularly, via a push trigger or a nightly schedule; adding one changes CI load, so it is left as a documented follow-up rather than done here. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TWMCQa5fNDyMCyFpPwx9zU
Two review findings on the previous commits: Require the cache setup to have succeeded before reporting statistics or saving. `!cancelled()` is also true after a *failed* step, so a failure in "Configure Build Caching" would still reach the save step and upload a practically empty .ccache under this run's unique key. Because the restore-keys ladder picks the most recent prefix match, that empty entry would then shadow a perfectly good older cache. Both steps still run when the build or the tests fail, which is the case worth keeping. Derive the save key from the restore step's cache-primary-key output instead of repeating the whole expression, so the two cannot drift apart. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TWMCQa5fNDyMCyFpPwx9zU
0ac5eef to
fd8ecbd
Compare
The restore-keys already fell back to develop; only the comment above them still said "nightly", which reads as if the nightly branch were a usable cache source. It is not, and the reason is worth stating so the fallback does not get "restored" later. GitHub scopes caches by ref: a run may restore only from its own ref, its base branch and the default branch. nightly is a sibling of develop, the default branch. Its commit is an ancestor of develop, but ancestry is not what the scope is keyed on, so a cache written by a push to nightly can never be read by a pull request. develop is the default branch, which makes its cache the only one every pull request can read, and the daily workflow_dispatch on develop keeps it fresh now that the save step works at all. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TWMCQa5fNDyMCyFpPwx9zU
|
If storage becomes a problem, sccache also supports S3. One could setup a cheap Cloud flare R2 bucket. 10GB free. After that 0.015$ per GB. |
|
@jpfeuffer That is worth doing, and there is already a One nuance on the motivation, from the numbers measured here: storage is not currently the binding constraint. A full run writes 2.31 GB across all five platforms, against a 10 GB budget, and GitHub evicts by last access date — so stale run-scoped entries, which nothing ever restores again, are exactly the first to go. The constraint a bucket would actually lift is scope, not size. GitHub scopes caches by ref: a run may restore only from its own ref, its base branch and the default branch. That is why The thing to weigh is fork pull requests: GitHub does not expose secrets to them, so external contributors would get no cache at all unless the bucket is also readable anonymously. Given how much of this project's traffic is external PRs, that probably decides the design rather than the cost does. Out of scope here — this PR is a plain bug fix, the cache was simply never being written — but a sensible follow-up, and the payoff would land on top of this rather than replacing it. Closing the loop on the control run promised above: Confirmed pre-existing and unrelated to this PR, and already fixed on Two incidental observations from that control run, both arguing for what this PR adds: its Windows job took 2h14m43s against 22–26m here, and it emitted no cache statistics at all — Generated by Claude Code |
|
Yes. A shared pool of hashed cached compiled objects in blob store will actually decrease storage and deduplicate even further since you don't need to download one monolithic tar.gz. |
|
Agreed on the dedup point, and this PR's measurements happen to put a number on it. The warm Windows run compiled 1923 objects with 1920 hits and 3 misses — and then still uploaded a full 867 MB tarball, essentially all of it byte-identical to what it had just downloaded. Per-object addressing would have stored those 3 objects. Across five platforms every run, that is most of the 2.31 GB. On forks I would test rather than assume. The secrets restriction is well established, but I could not find anything in GitHub's OIDC docs stating whether Generated by Claude Code |
| # PR -- but that is precisely the loop developers iterate in, and this | ||
| # workflow has no push trigger for develop (only nightly and release/*), so | ||
| # gating on non-PR events would mean the cache is effectively never written | ||
| # at all. Saved even when the build or the tests failed: the objects that |
There was a problem hiding this comment.
Doesn't make sense. If it fails in the beginning and you upload an empty cache you just successful deleted everything. Good job Claude.
There was a problem hiding this comment.
You're right, and my guard did not cover it — it required the ccache setup steps to have succeeded, and those succeed fine when it's the build that fails.
Spelling out the mechanism, because it is worse than just wasting an upload: the save key shares its prefix with the restore-keys ladder, and that ladder takes the most recent match. So whatever the save step uploads becomes what every later run on the branch restores. After a failed build that is a partial cache, and when the restore had itself missed — a new compiler major, or a new PR before develop has a cache — it is practically empty and then permanently shadows the develop and any-branch rungs below it. The branch stays cold from then on, exactly as you say.
Fixed in bf44dab: the save now requires the build step to have succeeded.
if: ${{ !cancelled() && steps.build.outcome == 'success' }}Build success means the cache is complete; on failure nothing is written and the previous good entry simply stays newest. This also subsumes the old condition, since the build cannot succeed unless the cache setup did, so the guard got simpler rather than more elaborate.
Test failures still save — the build was complete by then, so the cache is too, and a red test says nothing about the objects. That case is not hypothetical here: the earlier runs on this PR hit the pre-existing ProteomicsLFQ MSVC drift, and those had complete builds worth keeping.
I also removed two stale claims from the comment block you were reading. It still said this workflow has no develop trigger so the cache would "effectively never be written", and that keeping develop's cache fresh "needs a push trigger or a nightly schedule". Both wrong — there is already a daily workflow_dispatch on develop (~01:44 UTC) which writes …-ccache-develop once saving works at all.
Generated by Claude Code
Saving after a failed build could permanently degrade a branch's cache, which the previous guard did not prevent: it required the ccache setup steps to have succeeded, and those succeed fine when it is the build that fails. The save key shares its prefix with the restore-keys ladder, and that ladder takes the most recent match, so whatever the save step uploads becomes what every later run on the branch restores. After a failed build that upload is a partial cache. When the restore had itself missed -- a new compiler major, or a new pull request before develop has a cache -- it is practically empty, and it then permanently shadows the develop and any-branch rungs below it, leaving the branch cold from then on. Require the build step to have succeeded instead. That guarantees the cache is complete, and on failure nothing is written so the previous good entry simply stays newest. It also subsumes the old condition, since the build cannot succeed unless the cache setup did. Test failures still save. The build was complete by then, so the cache is too, and a red test says nothing about the objects. Also drops two stale claims from the surrounding comment: this workflow does have a daily workflow_dispatch on develop that keeps that cache fresh, so neither the "cache is effectively never written" nor the "needs a push trigger or nightly schedule" note was accurate. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TWMCQa5fNDyMCyFpPwx9zU
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
.github/actions/build/action.yml (1)
204-207: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick winPrevent statistics reporting from suppressing tests.
If
ccache --show-stats --verbosefails, GitHub Actions applies the implicitsuccess()status check to the followingTeststep and skips it. Make this reporting step best-effort, or add a status-aware condition toTestso test execution follows the build instead of the reporting step.Proposed fix
- name: Report ccache Statistics if: ${{ !cancelled() && steps.ccache-configure.outcome == 'success' && steps.ccache-reset.outcome == 'success' }} shell: bash + continue-on-error: true run: ccache --show-stats --verbose🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In @.github/actions/build/action.yml around lines 204 - 207, Make the “Report ccache Statistics” step best-effort so a failure from `ccache --show-stats --verbose` does not mark the job unsuccessful or suppress the following “Test” step. Preserve the existing ccache outcome conditions and ensure tests continue running based on the build result rather than this reporting step.
🧹 Nitpick comments (1)
.github/actions/build/action.yml (1)
118-130: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winClarify the generic restore cache scope.
Line [118] says “otherwise from any branch,” but GitHub caches are only accessible from the current ref, pull-request base branch, and default branch. That generic prefix only broadens matches inside those accessible scopes. Update the comment to avoid implying sibling-branch access.
Proposed comment fix
- # Restoring: from the current branch/PR, otherwise from develop, otherwise from any branch. + # Restoring: from the current branch/PR, otherwise from develop, otherwise from an accessible matching cache.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In @.github/actions/build/action.yml around lines 118 - 130, Update the restore-keys comment above the cache prefixes to clarify that the generic prefix broadens matches only within GitHub’s accessible cache scopes (the current ref, pull-request base branch, and default branch), rather than restoring from any branch. Keep the existing restore key order and values unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In @.github/actions/build/action.yml:
- Around line 204-207: Make the “Report ccache Statistics” step best-effort so a
failure from `ccache --show-stats --verbose` does not mark the job unsuccessful
or suppress the following “Test” step. Preserve the existing ccache outcome
conditions and ensure tests continue running based on the build result rather
than this reporting step.
---
Nitpick comments:
In @.github/actions/build/action.yml:
- Around line 118-130: Update the restore-keys comment above the cache prefixes
to clarify that the generic prefix broadens matches only within GitHub’s
accessible cache scopes (the current ref, pull-request base branch, and default
branch), rather than restoring from any branch. Keep the existing restore key
order and values unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 17250426-455d-4ba1-9a46-30c09cbe2463
📒 Files selected for processing (1)
.github/actions/build/action.yml
Two review findings on the previous commit. Make the statistics step best-effort. It is a diagnostic and must never decide the fate of the job, but steps without an `if` carry an implicit success(), so a failure there would skip "Test" entirely and report a red job that never ran the suite. Not hypothetical either: --verbose needs ccache >= 4.4, so an older ccache on some runner image would silently swallow the tests. Fix the restore-keys comment, which still said the last rung falls back to "any branch" directly above the paragraph explaining that GitHub scopes caches by ref and sibling branches are unreachable. The generic prefix only widens the match within the scopes already available -- the current ref, the base branch and the default branch. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TWMCQa5fNDyMCyFpPwx9zU
|
All green on 6c23b56 (100% of 2800 tests pass on Windows). One thing worth flagging before anyone reads the CI times the wrong way. windows-2025 took 2h27m on this commit — longer than the 2h23m baseline — and that is not the change misbehaving. The build was fully cold: It did not restore this PR's own cache. It fell through the restore-keys ladder to the last rung and matched That is a useful, if unflattering, observation, and it sharpens the retention question above. When I declined the cleanup suggestion I said LRU-by-access would evict stale run-scoped entries first. This run shows the opposite can happen: the genuinely useful per-PR caches were evicted while the worthless frozen I would still not block this PR on that. The fix itself is unaffected and measured 2h23m17s → 22m03s with a 99.84% hit rate when a usable cache existed, and the reason no usable cache existed here is the very write-once bug being fixed. Merging also repairs the fallback: the daily Worth revisiting afterwards, with real numbers rather than speculation, is whether the bare Generated by Claude Code |
Routine changelog audit of PRs merged since the last CHANGELOG update (#9902, merged 2026-08-11 06:20 UTC). Two PRs merged in that window: #9857 and #9887. - #9887 (ccache strategy/statistics in CI) is workflow-only with no code changes; its own description notes no CHANGELOG entry applies. - #9857 added src/pyOpenMS/THREAD_SAFETY.md, a new pyOpenMS thread-safety/GIL-release contract document (part of #9792). Added a bullet under PyOpenMS: documenting it, consistent with the other #9792-related entries already in that section. Co-authored-by: Claude <[email protected]>
…e fix (#9942) Documents three merged CI-reliability PRs that were missing changelog entries: the ccache build-cache save/restore split (#9887), pinning ruff for doc-validate (#9906), and the Windows nightly test race in TOPP_OpenSwathWorkflow_17_cache (#9937). Co-authored-by: Claude <[email protected]>
Description
The build cache was restored on every run but written only once.
actions/cachesaves in its post step only when the primary key missed, and the key was static per branch/PR — so after the first run the entry froze, and every later build restored a stale cache and recompiled from scratch.On run 31139423809 (green, on
develop): 2881 of 2883 ninja edges rebuilt, and the log ends withCache hit occurred on the primary key Windows-X64-cl.exe-19-ccache-develop, not saving cache.The Windows entry had gone so stale that it restored fine and then delivered 0 hits out of 1923 compiles.Changes
actions/cache/restoreandactions/cache/save, withrun_id/run_attemptin the primary key so it always misses and the save always writes. Therestore-keysladder still finds the newest cache by prefix; trailing dashes were added so the new per-run keys match.CCACHE_MAXSIZE1G → 2G. Measured: a cold Windows build fills 0.9G, so a 1G cap would evict itself while still being filled. Linux/macOS measure 0.4G and stay at 1G.ccache --show-stats --verboseafter the build, with counters zeroed before it. There was previously no way to tell from a log whether caching worked at all. Best-effort, so a failure in the diagnostic cannot skipTest.Result
The Windows compile step alone drops from 99.0 min to 6.9 min, at 99.8% ccache hits. MSVC is 99.02% cacheable (only 19 of 1944 calls hit an unsupported option), so nothing in this build blocks caching. Windows and macOS had both been compiling fully cold on every run.
developis the default branch, so its cache is the only one every pull request can read —nightlyis a sibling ref and its caches are unreachable from a PR. The existing dailyworkflow_dispatchondevelopkeeps that cache fresh now that saving works.Checklist
CI workflow change only — no code changes, so no AUTHORS/CHANGELOG entry and no bindings affected.
https://claude.ai/code/session_01TWMCQa5fNDyMCyFpPwx9zU
Summary by CodeRabbit