feat(cache): seed incremental state across checkouts by default #766
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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 #766"
general
weight: 0.35
jbellis
mbx can already start a new checkout's incremental state from another checkout (#754), so the first edit in a new worktree compiles incrementally. Today that needs the user to add an unstable rustc flag and, on stable Rust, set
RUSTC_BOOTSTRAP=1for the whole build. Few users will find it. This PR turns seeding on by default with rustc 1.98 or later. Nobody has to configure anything.What changes for users
When a crate gets mbx's private incremental state, mbx now adds
-Zremap-cwd-prefix=.to that one compiler command. The first edit to that crate in a fresh worktree then reuses another checkout's state.On our build host, we measured mbx's own workspace (commit 5ee4195, rustc 1.99.1, dev profile). We timed the first edit to the
mbxcrate in three fresh clones for each condition:| First edit in a fresh clone | Runs (s) | Median (s) |
|---|---|---|
| Without seeding | 50.6, 15.4, 18.0 | 18.0 |
| With seeding | 5.8, 6.2, 23.2 | 6.2 |
| Later edits in a warm checkout, for reference | 4.0 to 5.8 | about 5 |
The machine was busy during these runs, with a load average between 30 and 130, so the ratio is approximate. The measurement used the existing opt-in flag, which works by the same mechanism this PR applies automatically. After we installed this branch on the same host, mbx seeded state for 148 crate units in about 2.4 hours of normal work, with no failed compiles caused by the flag.
To turn it off:
A user-supplied
-Zremap-cwd-prefixstill enables seeding, as before.Visible effects, only for crates compiled with private state:
.as the working directory../src/lib.rsinstead of an absolute path. This is the same as a normal build run from the checkout.file!()and panic locations become relative.Why this design
rustc rejects incremental state recorded under a different working directory. The fix has to make every checkout look the same to rustc. We checked the options with plain rustc 1.97.1, 1.98.0 and 1.99.1 by copying state from one directory to another and asserting whether rustc loaded it:
| Option | State reused in another checkout? |
|---|---|
| No flag | No, on every version |
|
--remap-path-prefix=<checkout>=.(stable) | No, on every version, even with--remap-path-scope=all||
-Zremap-cwd-prefix=.| Yes, on 1.98.0 and 1.99.1; no on 1.97.1 |The stable flag fails because rustc tracks its explicit path list, which names a different checkout each time. Passing one identical list that names every checkout works, but the list changes whenever a worktree is added, which defeats the purpose. Since rust-lang/rust#157348, merged for 1.98,
-Zremap-cwd-prefixis the only option that removes the real directory from what rustc checks.Alternatives we rejected:
RUSTC_BOOTSTRAP=1for all of Cargo, which exposes unstable features to every crate and build script. SettingRUSTFLAGSto add the flag also makes Cargo ignore a project's configuredrustflags.RUSTC_BOOTSTRAP, but most users build on stable.Safeguards
On stable and beta, mbx sets
RUSTC_BOOTSTRAP=1only on that one rustc child process. It appends-Zallow-features=, so#![feature]is still rejected as on stable. mbx already does the same for rustdoc inrustdoc.rs, from #226. Cargo, build scripts, and every other compilation are unaffected. In addition:RUSTC_BOOTSTRAPis already set to any value, including-1.-Zflag of its own. Response files are expanded first. Without bootstrap such a build fails on stable, and mbx should not change that.RUSTC_BOOTSTRAPthroughenv!oroption_env!, mbx discards that attempt and compiles once more without the flag. It then stops adding the flag for that crate. This also happens when the first attempt fails, for example on aconstassertion. A genuine compile error does not trigger a retry.One exposure remains. A proc macro running inside that rustc process can read
RUSTC_BOOTSTRAPfrom its environment and see1. We found no proc macro that does this among the crates on our build host. The flag has been unstable since 2021, tracked in rust-lang/rust#87325. If you would rather ship this off by default first, that is a one-line change to the default.Validation
New unit tests cover the injection policy on each channel, existing user flags and bootstrap values, the
MBX_SEED_INCREMENTALspellings, build scripts including@argfilecompiles, rewritten response files, the bootstrap retry on success and failure, and the state-directory marker. Integration tests intests/build.rscover seeding from a donor checkout by default, also through Cargo's response files, a build script that reads an absolutefile!(), and the retry cases. An independent review traced every path to the action cache and the build-script execution cache. The branch has been running on our build host since 2026-10-19T20:06Z. It overlaps #753 in five files, and whichever PR merges second will be rebased.AI-assisted — Tool: Claude Code via Mjolnir; model: anthropic/claude-opus-5-5, openai/gpt-6.1-sol.
🤖 Generated with Claude Code
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
Summary by CodeRabbit
New Features
Private incremental build state can be reused across checkouts automatically with rustc 1.98 or later, helping new checkouts start with warm build caches.
Automatic seeding is enabled by default and can be disabled with
seed_incrementalorMBX_SEED_INCREMENTAL=0. A custom-Zremap-cwd-prefixcan still enable seeding.Private-state compilations may show relative paths in debug information, backtraces, and panic locations.
Stable and beta builds preserve feature-gate checks while supporting private-state seeding.
Documentation
* Updated configuration and incremental-build guidance with setup details and debugger source-mapping examples.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->