Skip to content

feat(cache): add fbuild cache reclaim — on-demand, ordered cache eviction (#1750 item 3) - #1772

Merged
zackees merged 1 commit into
mainfrom
agent/cache-reclaim
Oct 28, 2026
Merged

zackees merged 1 commit into
mainfrom
agent/cache-reclaim

Conversation

@zackees

@zackees zackees commented Oct 28, 2026

Copy link
Copy Markdown
Member

What

fbuild cache reclaim — the on-demand, budgeted reclaim half of #1750 (item 3).

A full disk now has an explicit remedy that is never a build side effect. #1341 is the
reason this is a command and not a policy: the daemon's background GC evicted a warm
toolchain under a running build and the link step died on ENOENT.

fbuild cache reclaim                      # free the cache root's pre-flight shortfall
fbuild cache reclaim --needed 2G --dry-run
fbuild cache reclaim --needed 2G --cache-dir /mnt/big/fbuild

Behaviour

  • Fixed eviction order, cheapest-to-refetch first (exactly what feat(esp32): make ESP builds survive low-disk hosts — pre-flight free-space check, on-demand cache reclaim, actionable ENOSPC #1750 asks for):
    toolchains → packages → platforms → libraries → frameworks → lnk-blobs.
    Within a kind the extracted install goes before its archive — reinstalling is cheaper
    than re-downloading.
  • Budgeted: it stops the moment the requested byte count is free. Entries are evicted
    whole (a target smaller than the next entry frees that entry, not part of it), and the
    report states the real number.
  • Never mid-build: it refuses while daemon_status.json reports an operation in progress,
    and names the operation. A missing or unparseable status never blocks (no daemon = nothing
    to evict out from under). This is the ci(esp32): daemon background GC evicts warm esptool install mid-build — elf2image ENOENT #1341 guard.
  • Two-phase disk cache (archives + installed) with LRU GC, sized budgets, and crash-safe SQLite index #20's safety model reused, not reinvented: both LRU queries filter pinned = 0, so a
    leased/pinned entry (one a build is holding) is invisible to reclaim. No new budgets and no
    new policy — the target is a byte count, and the watermarks stay the background GC's job.
  • Honest about the last step: the zccache object cache is the final step of the order and
    the one fbuild cannot drive from the CLI — its LRU budget lives inside the embedded zccache
    service in fbuild-daemon, with no cross-process trim API. A short run says so and points
    at fbuild purge instead of half-doing it.
  • Exit 1 when the target could not be met, 0 when it was.
  • --needed accepts 2G / 512M / 1048576 (reuses disk_cache::budget::parse_human_size).

Changes

  • crates/fbuild-packages-fetch/src/disk_cache/reclaim.rs (+reclaim_tests.rs) — new module:
    RECLAIM_ORDER, ReclaimStep, ReclaimReport, reclaim(); the dry run shares the walk.
  • disk_cache/index/queries.rs — kind-filtered LRU queries (lru_installed_entries_of_kind,
    lru_archive_entries_of_kind). The four LRU queries now share one private lru_entries
    helper, so the pinned = 0 filter cannot be dropped by a future caller. Existing public
    queries and SQL semantics are unchanged.
  • disk_cache/mod.rs — DiskCache::reclaim(needed_bytes, dry_run) facade.
  • crates/fbuild-cli/src/cli/cache.rs (+cache_reclaim_tests.rs) — the reclaim subcommand,
    the mid-build guard (busy_reason), the default target (the pre-flight shortfall, measured
    through disk_preflight::measure — the same seam the build enforces) and the renderer.
  • disk_cache/README.md — a gc-vs-reclaim table (trigger, target, order, mid-build).

Tests

fbuild-packages-fetch (9, real files under a rooted tempdir_in): the order contract; stop
before the next kind; stop inside a kind; install before archive; dry run reports the same
numbers and deletes nothing; pinned entries invisible; zero target is a no-op; an
unsatisfiable target evicts everything and reports the remaining bytes; a vanished path still
clears its row instead of failing.

fbuild-cli (9): mid-build refusal naming the operation; an idle daemon does not block; a
missing or non-boolean status never blocks; ordered rendering with a satisfied verdict; the
SHORT verdict naming the daemon-owned zccache step; the dry-run label; the empty report;
human-size parsing.

Scope

This lands #1750 item 3 only. Items 1 (per-stage measured footprint) and the zccache budget
hookup stay open on the issue.

…on (#1750 item 3)

A full disk now has an explicit remedy that is never a build side effect.
#1341 is why this is a command and not a policy: the daemon's background GC
evicted a warm toolchain under a running build and the link step died on
ENOENT.

`fbuild cache reclaim [--needed 2G] [--dry-run] [--cache-dir DIR]` evicts
disposable caches in a fixed order (toolchains -> packages -> platforms ->
libraries -> frameworks -> lnk-blobs, install before archive within a kind)
and stops the moment the requested byte count is free. It refuses to run
while daemon_status.json reports an operation in progress, and names the
operation. A missing or unparseable status never blocks: no daemon means
nothing to evict out from under.

The #20 safety model is reused rather than reinvented: the LRU queries filter
`pinned = 0`, so a leased entry is invisible to reclaim. No new budgets and no
new watermarks - the target is a byte count, and the watermarks stay the
background GC's job. The four LRU queries now share one private helper so a
new caller cannot drop the pin filter.

The zccache object cache is the last step of #1750's order and the one fbuild
cannot drive from the CLI (its LRU budget lives inside the embedded zccache
service in fbuild-daemon, no cross-process trim API). A short run says so and
points at `fbuild purge` instead of pretending.

Tests: 9 in fbuild-packages-fetch against real files under a rooted
tempdir_in (order, stop-before-next-kind, stop-inside-kind, install before
archive, dry-run parity, pinned invisible, zero target, unsatisfiable target,
vanished path) and 9 in fbuild-cli (mid-build refusal, idle/missing status,
ordered rendering, SHORT verdict, dry-run label, empty report, size parsing).

Refs #1750
@coderabbitai

coderabbitai Bot commented Oct 28, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

1 participant