Skip to content

feat(prebuilt): budget-capped disk-cache LRU for extracted trees (#1882) - #2193

Merged
zackees merged 1 commit into
mainfrom
agent/1882-disk-cache-lru
Nov 27, 2026
Merged

zackees merged 1 commit into
mainfrom
agent/1882-disk-cache-lru

Conversation

@zackees

@zackees zackees commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

What this is

Unit 12 of the #1882 track: the disk-cache LRU that the prebuilt plan lists
after staging/partial GC (delivered as #2189) and the identity → tree call site
(#2192). #1882 stays open.

obtain commits one tree per exact identity below {cache}/prebuilt/, and
nothing ever removed them: a client that walks framework versions keeps a full
decompressed framework per fingerprint forever. sweep_staging_tree cannot
help — it reaps abandoned staging attempts and deliberately never touches a
tree carrying the completion marker.

The rule

crates/fbuild-packages-fetch/src/prebuilt/lru.rs

  • Who is a candidate: a directory below {cache}/prebuilt/ holding a
    regular MARKER file. The marker is written only after the whole tree
    verified, so a staging directory, a partial destination or a loose file is
    never a candidate (the sweep owns those), and the prebuilt root itself is
    never one either.
  • Recency: the marker's modification time. obtain now calls touch on
    every reuse, so recency means last use, not creation — a tree that keeps
    being used is never the first evicted. A failed touch never fails the
    resolve (a read-only cache is still a correct cache).
  • Grace period: a tree whose marker is younger than MIN_AGE (1 h, shared
    with the sweep) is kept and counted. There are no leases on this path, so a
    build may be reading it right now.
  • Budget: FBUILD_PREBUILT_BUDGET is the only source. Unset, empty or
    unparseable ⇒ None ⇒ the LRU never runs, so no existing cache is pruned by
    surprise. 0 is a real budget (evict every eligible tree).
  • Bounded and link-free: oldest first, at most MAX_REMOVALS trees per
    pass, stop as soon as the remaining bytes fit, at most MAX_SCAN_DIRS
    directories and MAX_SCAN_DEPTH levels, never a symlinked directory, and a
    removal error is reported rather than hidden.

Wiring: crates/fbuild-daemon/src/bin/entry/prebuilt_gc.rs gains prune_once
and calls it on the same 6 h schedule as the staging sweep, once, only when a
budget is declared.

Tests (real output)

$ soldr cargo test -p fbuild-packages-fetch --lib prebuilt::
test result: ok. 66 passed; 0 failed; 0 ignored; 0 measured; 324 filtered out

$ soldr cargo test -p fbuild-daemon --lib prebuilt_gc
test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured; 348 filtered out

$ soldr cargo fmt --all -- --check        # clean
$ uv run --no-project python ci/enforce_platform_boundary.py --print-totals
rows=0; dylint_rows=0
  • 12 new fixtures in lru_tests.rs: the candidate rule, the root guard, a
    marker that is not a regular file, a symlinked tree, oldest-first eviction
    against a budget, the grace period, the removal ceiling, an absent root, and
    the opt-in budget (including a typo disabling rather than guessing).
  • 1 wiring test through the real entry point: a_reuse_records_itself_as_the_last_use
    downloads once, backdates the marker 24 h, reuses the tree, and asserts the
    marker's last-use time moved forward while the request count stayed at 1.
    Proven RED — deleting the touch call in obtain fails exactly that test.
  • 2 daemon fixtures: a stale tree is pruned by prune_once while a fresh one is
    protected, and a generous budget removes nothing.

Not done

  • No source fallback with one retry and no manual artifact builder — later
    cells of the track.
  • obtain has no production build-path caller yet, so the LRU is exercised by tests and by
    the daemon's opt-in pass only.

CI at open

Formatting, Reject .rs files over 1000 LOC, Reject new workspace crates,
Verify local gate, Dylint policy, Prooft and Validate Board Definitions
passed; Dylint Full (Linux builder, all OS targets) passed in 5m17s, which
is the gate that polices ban_std_pathbuf / ban_std_fs_in_async /
ban_poison_panic on the new files. linux / Check was still running at the
time of writing. (Local clippy could not run: the soldr build route is a remote
forge worker whose build lease was held by another job for the whole tick.)

`obtain` commits one tree per exact identity below `{cache}/prebuilt/` and
nothing ever removed them, so a client that walks framework versions kept a
full decompressed framework per fingerprint forever. `sweep_staging_tree`
cannot help: it reaps abandoned staging attempts and deliberately never
touches a tree carrying the completion marker.

`prebuilt::lru` owns the eviction decision and only that:

- a candidate is a directory below the prebuilt root holding a regular
  `MARKER` file, written only after the whole tree verified; the root itself
  and every staging sibling are never candidates;
- recency is the marker's modification time, and `obtain` bumps it with
  `touch` on every reuse, so a tree that keeps being used is never the first
  to go (proven RED: removing the call fails the reuse test);
- a tree inside the one-hour grace period is kept and counted — there are no
  leases on this path, so a build may be reading it;
- eviction is oldest first, at most `MAX_REMOVALS` per pass, stops as soon as
  the remaining bytes fit the budget, and never follows or removes a symlink.

Opt-in: `FBUILD_PREBUILT_BUDGET` is the only budget source. Unset, empty or
unparseable disables the LRU, so no existing cache is pruned by surprise. The
daemon calls `prune_once` on the same 6 h schedule as the staging sweep.

Tests: prebuilt:: 66 passed (12 new in lru_tests, 1 wiring test through
`obtain`), entry::prebuilt_gc:: 6 passed (2 new), fmt clean, boundary
rows=0; dylint_rows=0.
@zackees
zackees added this pull request to the merge queue Nov 27, 2026
Merged via the queue into main with commit 8ec6b51 Nov 27, 2026
34 checks passed
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Nov 27, 2026
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