← Back to Pull requests

feat(targets): remove build units of replaced dependency versions sooner #1079

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:41 UTC
Author

Updating dependencies leaves the old versions' build units in a managed target directory, along with the units of everything built against them. Until now they stayed for target.max_age (30 days), and on filesystems that do not record access times, such as APFS on macOS, unit cleanup never ran at all. mbx now uses Cargo.lock to remove them a few days after the checkout moves on.

On by default. A unit built from a registry version that the lockfile now lists only at other versions, and every unit built against it, is removed once:

  • a successful build, check, test, run, bench, clippy, doc, rustc, or nextest through mbx used the lockfile as it is, without Cargo.lock changing during the run (aliases of those commands count, unless they add their own target directory, manifest, or configuration; nextest runs that reuse an archive or prebuilt binaries, and nextest subcommands that build nothing, do not);

  • that lockfile has been the one built for a day (switching branches within a day removes nothing); and

  • the unit has gone untouched for two days (a day, plus a day of access-time slack).
  • Removal happens in the usual target collection, including mbx gc (--dry-run previews it). It needs Cargo 1.100 or later. To keep every unit until it ages out:

    [target]
    prune_outdated_dependencies = false
    

    or set MBX_TARGET_PRUNE_OUTDATED_DEPENDENCIES=false.

    Left alone: git and path packages, packages the lockfile no longer names at all, targets mbx does not manage, kept targets (target.keep), and targets no mbx build has succeeded in since upgrading or since the lockfile last changed.

    Measured

    On macOS (APFS, Cargo 1.101.0-beta.4), I built this repository's workspace (dev profile) into one managed target at six commits spanning 2026-10-22 to 2026-12-03, with an isolated cache, then moved file times back three days to stand in for the wait and ran mbx gc.

    | | without removal | with removal |
    | --- | --- | --- |
    | Target size (du) | 4272 MiB, 771 units | 1280 MiB, 316 units |
    | Next build at the current lockfile | 5.6–7.5 s, 26 hits, 1 miss | 5.7–6.2 s, 26 hits, 1 miss |
    | Switch back to the previous lockfile commit measured (affef4f7) | 1.8 s, 19 hits, 0 misses | 2.7 s, 76 hits, 0 misses |
    | Switch back to the oldest (25e20153) | 1.4 s, 26 hits, 0 misses | 2.7 s, 188 hits, 0 misses |

    mbx gc reported 455 units and 3.1 GB of logical bytes removed. Sizes are logical; blocks shared with the cache by reflink free less physical space. Each timing is a single run on one machine. The switch-back cost is small here because the local cache still held everything; if the cache has since evicted those results, they compile again.

    Limitations

  • Where access times are not recorded, only writes count as touching a unit. If a second workspace with its own lockfile builds into the same target directory, its older versions of shared packages can be removed and then restored or rebuilt.

  • Cargo's fingerprint JSON and per-unit dep-info are internal formats. If they change, units stop being recognized and age out as before.

  • The time-based conditions were simulated by editing file times, not by waiting. Linux and Windows were not exercised by hand.
  • Validation

    On macOS, the lint, build, Rust test, end-to-end, release-diagnostics, and docs tasks of mise run ci passed, including new unit tests for the lockfile judgement and a collection test covering the unrecorded, just-recorded, and settled states. test:pretty did not pass locally: it timed out at its cargo test --test custom step and then hung, which also happens on unrelated branches on this machine.

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

    🤖 Generated with Claude Code

    <!-- CURSOR_SUMMARY -->
    ---

    [!NOTE]

    Medium Risk

    Changes managed-target GC and records lockfile state on every successful build; incorrect eligibility could delete still-needed units, though grace periods and strict recording guards limit that.

    > Overview

    Adds early cleanup of managed target/ units for registry dependency versions that Cargo.lock no longer references, enabled by default via target.prune_outdated_dependencies (MBX_TARGET_PRUNE_OUTDATED_DEPENDENCIES).

    > After a successful mbx compile command, the CLI snapshots the lockfile digest before Cargo runs and only records .mbx-built-lockfile in the managed view if the digest is unchanged at the end, the command actually compiles, and aliases did not redirect the build (moves_the_build). Collection then prunes “replaced” units (and dependents) once that lockfile has been stable for a day and units meet the existing superseded grace, including on filesystems without access times.

    > GC wiring switches from passing only target_max_executable_builds to an EarlyRemoval bundle (max_executable_builds + outdated dependency pruning). New target_outdated module implements lockfile parsing, dep-info version detection, and fingerprint dependency closure. Docs describe behavior and opt-out.

    > <sup>Reviewed by Cursor Bugbot for commit 4fc48617b48b48ca3b165f514d8b150506ac8a6b. 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

    New Features
    Managed target cleanup can remove cached build units for registry dependency versions no longer present in the lockfile, along with units built against them. This is enabled by default and can be disabled with target.prune_outdated_dependencies.
    Cleanup waits until a successful mbx build uses an unchanged lockfile for a day and affected units have been untouched for the required retention period. Cargo 1.100 or later is required.
    Bug Fixes
    Builds invoked through Cargo aliases update lockfile tracking only when they succeed and use the managed target.
    Documentation
    * Added configuration and managed-target cleanup details, including eligibility and retention behavior.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: jdx Review duration: 57m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.52) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    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
    Real PR Conversation Timeline
    1 comments
    "Review active on #1079"
    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: 52% (MEDIUM) · Higher = larger blast radius
    52%
    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: 22.5% · Safe to merge
    22.5%