Fix three cache LV bugs: cache_size ignored, cache-empty deleted by reconcile, GC threshold never firing#14
Merged
Merged
Conversation
Bug 1 — cleanup deletes cache-empty:
The cleanup loop that removes LVs for roles no longer in config uses the
"cache-" prefix. "cache-empty" matches, its stripped suffix is "empty",
rsplit_once('-') returns None so the role slug becomes "empty", and "empty"
is not in active_roles — so cache-empty gets deleted every reconcile run.
Fix: skip "cache-empty" explicitly since it is the shared template LV, not
a slot LV.
Bug 2 — cache-empty is always 1 GiB regardless of cache_size config:
lvcreate_thin was called with a hardcoded size of 1, so all slot cache LVs
(which are snapshots of cache-empty) were 1 GiB regardless of the
cache_size field in config.toml. Fix: use the maximum cache_size across all
configured roles when creating cache-empty.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
✔️ All good! |
CacheDisk::usage_pct() ran df against the LV device path on the HOST, but the cache LV is only ever mounted inside the guest VM (as /dev/vdb). For an unmounted block device, df reports the filesystem containing the device node -- devtmpfs, ~0% -- and any parse failure fell back to unwrap_or(0). So usage_pct() always returned ~0 and try_clear_cache() never fired: caches were never trimmed regardless of max_cache_pct (observed in production: slot cache LVs at 92-98% data_percent, never cleared). Read the thin LV's data_percent via lvs instead, which the host can always see. It slightly overestimates usage after guest-side deletes (thin blocks aren't returned without discard), which errs on the side of clearing -- acceptable for a cache. Failures now surface as errors (logged as warnings by try_clear_cache) instead of being silently coerced to 0%, which is exactly how this bug stayed hidden.
Contributor
Author
|
@matsimitsu once you have some time, can you please review this PR as well? I would like to get it implemented to resolve some of the issues that I've been investigating for the CI Runners. |
matsimitsu
approved these changes
Jul 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes three bugs in the manager's cache-disk handling. Together they are the root cause of the staging CI disk-space incident of 2026-07-02, where every
appsignal-processor-rsbuild went red withNo space left on deviceon/cache(see appsignal-ansible#796 for the config-side half).Bug 1 —
cache_sizewas ignored:cache-emptyhardcoded to 1 GiBreconcile()created the sharedcache-emptytemplate LV at a fixed 1 GiB, and every slot cache LV is a thin snapshot of it — so the per-rolecache_sizeconfig value never sized anything. Freshly provisioned hosts (ci-hel1, ci-hel2) ended up with 1 GiB cache disks per VM where the config said 20 (and classic runners used to provide 100).Fix: size
cache-emptyfrommax(role.cache_size)across all roles, so any role can snapshot from it and get a sufficient disk.Bug 2 — reconcile deleted its own
cache-emptytemplateThe stale-LV cleanup loop strips the
cache-prefix, derives role slug"empty", finds no such role, and removescache-emptyon every reconcile (i.e. every manager start, right after the slot snapshots are created). After that,CacheDisk::clear()— which re-snapshots fromcache-empty— fails, so full caches can never be cleared.Fix: guard the cleanup loop,
cache-emptyis the shared template, never remove it. (Audited alllvremovecall sites; this loop is the only path that could delete it.)Bug 3 — GC threshold never fired: usage measured with
dfon the hostCacheDisk::usage_pct()randf --output=pcent /dev/<vg>/<lv>on the host, but the cache LV is only ever mounted inside the guest (as/dev/vdb). For an unmounted block device,dfreports the filesystem containing the device node — devtmpfs, ~0% — and any parse failure was silently coerced to 0 (unwrap_or(0)). Sotry_clear_cache()compared ~0% againstmax_cache_pctand never cleared anything, regardless of bugs 1–2. Production evidence: ci-hel3 slot caches sat at 92–98%data_percent, never trimmed.Fix: read the thin LV's
data_percentvialvs, which the host can always see. It slightly overestimates after guest-side deletes (thin blocks aren't returned without discard), erring on the side of clearing, fine for a cache. Failures now propagate as errors (surfaced as warnings bytry_clear_cache) instead of being coerced to 0%, which is how this bug stayed hidden.Deployment notes
reconcile()only creates missing LVs, it does not resize existing ones. Hosts already carrying manually rebuilt 100 GiB caches (ci-hel1/2/3, 2026-07-02) keep them and need nothing. To changecache_sizeon a running host later:lvremovethe slot cache LVs +cache-empty, then restart the manager.ci_actions_runner_manager_versionis bumped.