Skip to content

Fix three cache LV bugs: cache_size ignored, cache-empty deleted by reconcile, GC threshold never firing#14

Merged
guifranchi merged 2 commits into
mainfrom
fix/cache-empty-lv-bugs
Jul 16, 2026
Merged

Fix three cache LV bugs: cache_size ignored, cache-empty deleted by reconcile, GC threshold never firing#14
guifranchi merged 2 commits into
mainfrom
fix/cache-empty-lv-bugs

Conversation

@guifranchi

@guifranchi guifranchi commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

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-rs build went red with No space left on device on /cache (see appsignal-ansible#796 for the config-side half).

Bug 1 — cache_size was ignored: cache-empty hardcoded to 1 GiB

reconcile() created the shared cache-empty template LV at a fixed 1 GiB, and every slot cache LV is a thin snapshot of it — so the per-role cache_size config 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-empty from max(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-empty template

The stale-LV cleanup loop strips the cache- prefix, derives role slug "empty", finds no such role, and removes cache-empty on every reconcile (i.e. every manager start, right after the slot snapshots are created). After that, CacheDisk::clear() — which re-snapshots from cache-empty — fails, so full caches can never be cleared.

Fix: guard the cleanup loop, cache-empty is the shared template, never remove it. (Audited all lvremove call sites; this loop is the only path that could delete it.)

Bug 3 — GC threshold never fired: usage measured with df on the host

CacheDisk::usage_pct() ran df --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, df reports the filesystem containing the device node — devtmpfs, ~0% — and any parse failure was silently coerced to 0 (unwrap_or(0)). So try_clear_cache() compared ~0% against max_cache_pct and 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_percent via lvs, 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 by try_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 change cache_size on a running host later: lvremove the slot cache LVs + cache-empty, then restart the manager.
  • Companion config change (cache_size 20→100, max_cache_pct 75) already merged in appsignal-ansible#796; it takes full effect once this ships (proposed v0.1.12) and ci_actions_runner_manager_version is bumped.

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>
@backlog-helper

backlog-helper Bot commented Jun 1, 2026

Copy link
Copy Markdown

✔️ All good!

New issue guide | Backlog management | Rules | Feedback

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.
@guifranchi
guifranchi requested a review from matsimitsu July 2, 2026 13:03
@guifranchi guifranchi changed the title Fix two cache-empty LV bugs in reconcile() Fix three cache LV bugs: cache_size ignored, cache-empty deleted by reconcile, GC threshold never firing Jul 2, 2026
@guifranchi

Copy link
Copy Markdown
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.

@guifranchi
guifranchi merged commit 78860a9 into main Jul 16, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants