Skip to content

CI: prune superseded ccache generations so the repo stays under the cache limit - #84

Merged
danielhanchen merged 1 commit into
masterfrom
ci/prune-superseded-ccache
Aug 8, 2026
Merged

danielhanchen merged 1 commit into
masterfrom
ci/prune-superseded-ccache

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Adds a second step to the reclaim job that deletes ccache generations restore-keys can no longer select. This is a build-time change, not housekeeping.

Why it affects compile time

ccache entries are immutable, so every run writes a new cache per (cuda, os, profile) and finds the previous one by restore-keys prefix. restore-keys returns only the most recent match, so older generations can never be selected again.

Measured on this repo before the change: 122 caches / 31.72 GiB, of which only 40 / 9.13 GiB were reachable. 71% of the budget was unreachable.

That matters because the repo cache limit is 50 GB across ~40 prefixes. Once the total reaches the limit GitHub evicts by its own LRU, which can take a live cache, and a partial cache is far worse than a cold one.

Measured locally over 513 real translation units:

cache size vs what the build needs direct preprocessed hit rate
100% 513 0 100%
60% 201 104 59.5%
30% 13 60 14.2%

A preprocessed-dominant split is the fingerprint of a truncated cache: manifests are evicted, some objects survive, and lookups fall through to the slow path. CI showed exactly that (3 direct / 52 preprocessed) while the cap was 500 MB, and that run took 204 minutes against 54 for the same job with a healthy cache.

Projection now that 4a03725 has stopped the truncation and caches can reach full size:

CUDA cache size keep 1 keep 2
0.8 GiB 17.7 GB 35.4 GB
1.2 GiB 23.3 GB 46.6 GB
1.5 GiB 27.5 GB 55.0 GB, over

So without pruning the repo grows into GitHub-side LRU eviction, which reintroduces the truncation that cost those 150 minutes.

What it does

Groups caches by their restore-keys prefix (the key minus its -<tag>- suffix), sorts newest first, and deletes everything past KEEP: 2. Keeping 2 rather than 1 because the second generation is the fallback when a job dies before saving, precisely the hole that forces a cold build.

It also emits a job summary and raises a ::warning:: above 40 GiB, so the squeeze is visible before it bites.

Safety

  • Lives in the existing reclaim job, which already holds actions: write and only runs when this run published (needs.assemble.outputs.published == true).
  • continue-on-error: true, so cache housekeeping can never fail a published release.
  • Worst case if it were ever wrong is a slower build, never a wrong or missing artifact.

Testing

The step was extracted from the YAML and run against the real 122-cache list from this repo with a stubbed gh: it selected exactly 60 caches / 16 GiB, identical to the manual prune performed today, and left the newest 2 per prefix. bash -n clean, all workflows parse.

Follow-up, not in this PR

Install CUDA toolkit costs 7.1-8.8 min on every cuda12 leg via Jimver, against 0.8-1.1 min on the cuda13 legs which use the NVIDIA redist method already present in this workflow. Moving cuda12 to redist looks worth about 7 min x 4 jobs per run, but it needs the 12.8 component list pinned and tested before it goes near the release path.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 628dbc3846

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

freed=0; deleted=0
while IFS=$'\t' read -r id created size key; do
[ -z "${id:-}" ] && continue
pre="$(printf '%s' "$key" | sed -E 's/-b[0-9]+-mix-[0-9a-f]+-?$//')"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Handle vanilla tags when deriving the cache prefix

When resolve produces a supported plain tag such as b1234 (the empty-PR-set path), saved keys end in -b1234-, but this substitution only strips -b1234-mix-<hash>-. Each vanilla generation therefore retains a unique pre, never exceeds KEEP, and is never pruned, allowing daily plain builds to reach the repository cache limit that this step is intended to prevent.

Useful? React with 👍 / 👎.

Comment on lines +1053 to +1057
# ── Keep the ccache budget inside the repo limit ──
#
# ccache entries are immutable, so every run writes a NEW cache per
# (cuda, os, profile) and finds the previous one by restore-keys prefix.
# restore-keys returns only the MOST RECENT match, so older generations can

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Condense the non-ASCII cache commentary

This new 19-line comment block uses Unicode box-drawing characters and hard-wraps explanatory sentences across many lines. The repository's root instructions explicitly require ASCII-only text, concise comments, and avoiding fixed-column wrapping, so this should be reduced to a short ASCII comment while leaving detailed measurements outside the workflow.

AGENTS.md reference: AGENTS.md:L73-L77

Useful? React with 👍 / 👎.

#
# Keeping 2 rather than 1: the second generation is the fallback when a job
# dies before saving, which is precisely the hole that forces a cold build.
- name: Prune superseded ccache generations

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Run cache pruning after non-publishing builds

In the inspected unsloth-prebuilt.yml, this step is nested in reclaim, whose job-level condition at line 967 requires a successful publication. Failed builds still save their partial ccache generations through the reusable workflows' if: ${{ always() }} save steps, and publish:false dispatches also build and save caches, but neither path ever reaches this pruning step. A few consecutive failures or artifact-only test runs can therefore fill the cache budget before any successful release is available to clean it up, causing the eviction and cold-build behavior this change is meant to prevent.

Useful? React with 👍 / 👎.

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