← Back to Pull requests

fix(incremental): compile tests and binaries whose link bypasses the cache incrementally #1041

Closed
unknown closed this pull request without merging on Nov 29, 2026 20:54 UTC
View on GitHub
unknown unknown commented on Nov 29, 2026 20:18 UTC
Author

A workspace test binary, binary, example, or proc macro whose native link mbx cannot cache used to recompile from scratch on every edit. mbx turns off Cargo's own incremental mode, and learned incremental state was only given to units the cache could key, or to staticlib/cdylib/dylib libraries (#695). So a link bypass also turned off incremental compilation.

Reported in #1039: inside a nixpkgs dev shell on macOS, SDKROOT points at the Nix apple-sdk, xcrun cannot describe it, and every native link bypasses as unportable-native-link. The reporter's library-test binary took about 9.4 s per edit there, against 2–3 s with the Xcode SDK, where the same unit is cacheable and gets learned incremental state.

Such units now keep private incremental state when the cache declined them only because of the link. That covers these bypass reasons:

  • unportable-native-link: an unidentified linker or SDK, or an option such as -C rpath or -C split-debuginfo=packed

  • unmodeled-link-argument

  • native-library, missing-native-library, and custom-target-native-library
  • rustc's front end and code generation for these units are the same as for a cacheable unit, and the link always runs again, so incremental state is as safe here as it is in plain Cargo. The result still stays out of the shared store, and mbx explain still reports the bypass. As with bypassed libraries, the state is keyed on the full rustc argument list, it covers only workspace sources, and build scripts are left out. learned_incremental = false (MBX_LEARNED_INCREMENTAL=0), MBX_VERIFY, an explicit -C incremental, and an optimized build with local ThinLTO each turn it off.

    Example:

    RUSTFLAGS=-Crpath mbx build   # the binary's link bypasses; it starts its own incremental state
    # edit src/main.rs
    RUSTFLAGS=-Crpath mbx build   # recompiles the binary incrementally
    

    This does not make links against the Nix Apple SDK cacheable. That would need mbx to identify the SDK without xcrun and is not part of this PR.

    Validation. A new end-to-end test builds a binary with -C rpath, edits it, and checks that the binary keeps its own incremental state and reuses it. It fails without the change and passes with it. A unit test covers which bypassed units get state. mise run ci passes. I did not test on macOS in a Nix dev shell or re-measure the reporter's build.

    Refs #1039

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

    🤖 Generated with Claude Code

    <!-- CURSOR_SUMMARY -->
    ---

    [!NOTE]

    Medium Risk

    Changes when bypassed compiles receive -Cincremental= and private state dirs, which affects edit-loop performance and correctness boundaries; scope is narrowed to link-only bypasses with existing opt-out flags, but the transparent-rustc path is user-facing on every such unit.

    > Overview

    Expands learned incremental beyond uncacheable workspace libraries (staticlib/cdylib/dylib) to tests, binaries, examples, and proc macros when mbx bypasses the shared cache only because the native link cannot be keyed (e.g. unidentified SDK, -Crpath, unmodeled link args). Compiler output still stays out of the store; edits should recompile incrementally instead of cold every time.

    > Introduces a Bypass::LinkOnly vs Bypass::Other classification: the session records the bypass reason from BypassReason and passes it into bypassed_library_incremental, which now gates private incremental via bypassed_unit_keeps_incremental_state (uncacheable libs always; link-only for non–build-script units). Build scripts remain excluded.

    > Adds unit and end-to-end tests (-Crpath binary) and docs/limits.md notes on eligibility and MBX_LEARNED_INCREMENTAL=0.

    > <sup>Reviewed by Cursor Bugbot for commit a6c5d1a6390d2b1a18a94279179bf9f8bc0c2efd. 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
    Incremental compilation state is now retained for eligible binaries, tests, examples, and procedural macros when only their linking bypasses caching. Linking for these units remains uncached.
    Documentation
    Clarified which units can use incremental state when linking bypasses caching, and noted that build scripts are excluded and the behavior can be disabled with learned_incremental.

    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 591 lines (+443 / -148) across 7 files Reviewer: jdx Review duration: 36m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 591 lines diff across 7 files
    0.50
    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%
    60%
    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.382
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1041"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 50.0% (MEDIUM) · Higher = larger blast radius
    50.0%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 19.7% · Safe to merge
    19.7%