← Back to Pull requests

perf(cache): evict replaced dependency versions from the store first #1081

Closed
unknown closed this pull request without merging on Dec 04, 2026 03:39 UTC
View on GitHub
unknown unknown commented on Dec 04, 2026 02:49 UTC
Author

After cargo update, the dependency versions you just replaced stayed protected from store eviction. The old lockfile's checkout claim lasts 30 days, and the manifest for the new lockfile starts from the previous one, so it keeps predicting the old versions beyond that. When the store went over budget, mbx evicted least recently used first among everything, which could remove long-unchanged dependencies you still build while keeping versions nothing asked for.

mbx now reads the Cargo.lock of every live checkout during a sweep that has to evict. Compilations of a registry package version that none of them names count as unreachable and are evicted before the rest.

  • Only the order changes. Nothing is removed while the store fits its budget, and switching back to an earlier lockfile still restores whatever has not been evicted.

  • A version that any live checkout locks stays protected.

  • A checkout whose Cargo.lock is missing or unreadable keeps everything its builds recorded.

  • Rust and C/C++ compilations of registry sources are covered. Workspace crates, path and Git dependencies, and build-script run results rank as before. So does anything that also reads workspace or path-dependency files, a C/C++ file compiled from outside the registry (such as one generated into target/), and a crate that only links a library a replaced package ships.

  • There is no new setting and no format change; existing stores benefit on their next over-budget sweep.
  • Measurements

    macOS on Apple silicon. I built this repository's last 20 lockfile commits in order, with mbx build in one checkout and an isolated cache, which left a 5.16 GiB store. Under the current rules 100% of its object bytes were protected, and the newest manifest still held 96 predictions (of 1183) for replaced versions. With this change 0.40 GiB (8%) becomes unprotected.

    I then collected a copy of that store with mbx 1.32.0 or with this branch, and rebuilt the newest lockfile from an empty target directory with mbx 1.32.0. Without any collection that rebuild gets 713 hits and 9 misses.

    | Store budget | Evicted | 1.32.0: hits / misses | This change: hits / misses |
    | --- | ---: | ---: | ---: |
    | 5200 MiB | ~90 MiB | 603 / 119 | 713 / 9 |
    | 5100 MiB | ~190 MiB | 145 / 578 | 713 / 9 |
    | 5000 MiB | ~290 MiB | 136 / 587 | 713 / 9 |
    | 4900 MiB | ~390 MiB | 136 / 587 | 713 / 9 |
    | 4700 MiB | ~590 MiB | 136 / 587 | 136 / 587 |
    | 4 GiB | | 106 / 617 | 136 / 587 |
    | 3 GiB | | 106 / 617 | 106 / 617 |
    | 2 GiB | | 69 / 654 | 68 / 655 |

    The benefit lasts while the replaced versions cover what has to be evicted. Past that point the two behave about the same.

    Limits of this measurement: it is one project with one trial per row, the 20 builds ran within minutes of each other rather than over weeks, and the sources were replayed without Git history. A project that updates its lockfile less will have less to reclaim.

    mbx gc --dry-run on this store took 0.66–0.75 s with this change and 0.62–0.67 s with 1.32.0 over five alternating runs.

    Validation

    New store tests cover replaced versions (including compacted and C include inputs), a version another live checkout still locks, missing or unparsable lockfiles, and compilations that only touch a replaced version. mbx-cache-store gains a dependency on toml.

    The lint, docs, link, Rust, end-to-end and release-diagnostics gates were run individually and pass locally. test:pretty does not pass on this machine: it times out at cargo test --test custom and then hangs, as it also does on unrelated branches.

    AI-assisted — Tool: Claude Code; model: anthropic/claude-sonnet-5-5; version: unavailable.

    🤖 Generated with Claude Code

    <!-- CURSOR_SUMMARY -->
    ---

    [!NOTE]

    Medium Risk

    Changes cache eviction reachability for over-budget GC by interpreting Cargo.lock and prediction payloads; incorrect classification could evict still-needed registry builds (recoverable by recompile) or retain obsolete cache longer.

    > Overview

    Cache garbage collection now treats registry dependency compilations as unprotected when no live checkout's Cargo.lock still names that version, so after cargo update those cached objects are evicted before still-needed dependency builds during over-budget sweeps.

    > The sweep reads each live checkout's workspace Cargo.lock (new LockedPackages in locked.rs, toml dependency), inspects rustc/C compilation prediction payloads for registry source paths, and skips rooting when every referenced package directory is absent from all readable lockfiles. Unreadable or missing lockfiles keep the full manifest rooted; workspace, path/git, build-script, and edge cases (link-only native dirs, C sources outside the registry) stay protected as before.

    > Reachability switches from action-only manifest reads to full predictions with a supersedes filter. Docs describe the new eviction ordering. Tests cover replaced versions, multi-checkout locks, compacted inputs, and bad lockfiles.

    > <sup>Reviewed by Cursor Bugbot for commit 99dad36da957d7e65e19076e5c18e2772eb82996. Bugbot is set up for automated code reviews on this repo. Configure here.</sup>

    <!-- /CURSOR_SUMMARY -->

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->
    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

    Bug Fixes
    Cache cleanup now identifies registry dependency versions no longer referenced by any live checkout’s lockfile and removes their cached compilations first.
    If a live checkout’s lockfile is missing or unreadable, its recorded compilations are preserved.
    Other compilations remain eligible for cleanup when needed to meet the cache budget or free disk space.

    Documentation
    Clarified cache cleanup order and noted that returning to an earlier lockfile can restore compilations that have not yet been evicted.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: jdx Review duration: 49m
    All Vouch review confidence checks passed
    Residual risk 0.25 = Change Risk (0.57) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.57 · 650 lines diff across 8 files
    0.57
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #1081"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 57% (MEDIUM) · Higher = larger blast radius
    57%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 24.7% · Safe to merge
    24.7%