← Back to Pull requests

feat: record why compilations skip the cache and where incremental state comes from #911

Closed
unknown closed this pull request without merging on Nov 06, 2026 15:31 UTC
View on GitHub
unknown unknown commented on Nov 05, 2026 16:17 UTC
Author

When several checkouts of one project build in parallel, as agent worktrees do, much of the compiler time shows up as unconsulted: the compiler ran without a cache lookup. The session history could not say why. It couldn't tell whether a crate was edited, whether it linked another crate's private incremental output, or whether its incremental state had been seeded from another checkout. As a result, mbx analyze reported many of these crates as a "first build", even when they were rebuilding after an edit to a crate they depend on.

This PR records those facts and uses them in mbx analyze and mbx stats.

What mbx analyze shows now

Take two checkouts of a workspace where app depends on mid, which depends on core. Checkout A edits core and builds, so all three keep private incremental state. Then checkout B edits core and builds. Before, mbx analyze in checkout B said:

131.6ms  first build of these compilations (2)
         app 110.6ms and mid 21.0ms
 24.7ms  misses with no earlier recording (1)
         core 24.7ms

Now the crates that rebuilt because they link core's private output are charged to core. A new section says where their incremental state came from:

154.4ms  misses with no earlier recording (3)
         core 25.9ms
         then 2 crates that depend on it rebuilt: app 104.5ms and mid 23.9ms

private incremental state for 3 compilations
154.4ms  seeded from another checkout, copying 417.3 KiB in 101.6ms (3)

The other sources are started from this checkout's earlier state, started empty, and seeding failed. started empty comes with a reason: no other checkout had the state, a one-time discard of older state is pending, the state can't be shared between checkouts, or the checkout's state directory held no finished session. Bypassed workspace libraries that mbx gives private state are included too. Recordings from older versions don't have these fields, and mbx analyze reports them as before.

Lifetime totals in mbx stats

mbx stats now shows compilations by outcome, for example 7 hits, 2 misses, 3 not looked up, 1 bypassed since 2026-11-05, adding N rebuilt to verify when verification sampling is on. mbx stats --json adds savings.compilations, with raw counts and compiler time per outcome. No hit rate is computed, because which outcomes belong in the denominator depends on the question. Counting starts with the first build recorded by this version; earlier history isn't backfilled. While an older mbx shares the store, the totals for that period are low.

Session event rows

Rows in sessions/v1 gain optional fields. They stay version 1, and older rows still parse. Session streams remain an implementation detail (see docs/stability.md).

{"type":"action","v":1,"outcome":{"kind":"unconsulted"},"crate_name":"mid","duration_ns":23916681,
 "unit_kind":"lib","skip_reason":"private-dependency","private_dependencies":["core"],
 "incremental_state":{"source":"seeded","donor":"/work/lane-a","files":12,"bytes":78339,"copy_ns":89872871},
 "incremental":true}

| Field | On which rows | Meaning |
|---|---|---|
| unit_kind | every row, when known | lib, bin, test, proc-macro, build-script |
| incremental | rows where the compiler ran | whether the compilation kept private incremental state |
| skip_reason | unconsulted rows | private-dependency, eager, unshareable-key, hot-reuse, prediction-error, no-prediction, other |
| private_dependencies | compilations that link private artifacts | up to four producing crates, then private_dependencies_more |
| incremental_state | private incremental compilations | existing (a finished session was there), seeded (donor, files, bytes, copy time), cold (reason), failed |

To support this:

  • incremental::seed now reports what it copied instead of discarding it.

  • Private-artifact markers now name the crate that produced them. Markers from older versions still mark an artifact as private.

  • The session agent wire protocol moves to version 12. Mixed wrapper and agent versions were already rejected at the handshake.
  • Validation

    mise isn't installed on the host where this was developed, so I ran the steps of mise run ci by hand on Linux:

  • cargo fmt --check, plus debug and release workspace clippy with -D warnings.

  • mbx test --workspace and the release diagnostics test.

  • The full bats suite. Four tests fail, and they fail the same way with a main-based binary on that host: three C-object and gdb tests, plus the mise postinstall test, which needs mise.
  • An isolated end-to-end run, with its own store and two scratch checkouts, produced the rows and reports above. That run was where seeding from checkout A into checkout B was observed.

    Two things this PR does not do:

  • Incremental-miss rows still carry no key diagnostic. That is unchanged from main, and it is why core above is reported as "no earlier recording".

  • Retention of session history is not configurable yet; that will be a separate PR.
  • AI-assisted — Tool: Claude Code; model: anthropic/claude-opus-5-5; version: unavailable.

    🤖 Generated with Claude Code

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

    Summary by CodeRabbit

    New Features
    Compilation statistics now track cache hits, misses, bypasses, unconsulted compilations, verifications, incremental compilations, and compiler time, with a separate tracking start date.
    Analysis reports can show private incremental-state sources, including reused, seeded, or empty state, and attribute dependent compilations to the crate whose changes made them necessary. This section is omitted when state details are unavailable.
    Compilation records now include additional context, such as compiler unit type, incremental status, and incremental-state details.
    Incremental-state seeding reports copied file and byte counts and elapsed time.
    Documentation
    * Updated the statistics and analysis guides to explain the new reporting and tracking behavior.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: jbellis Review duration: 1393m
    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
    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%
    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.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #911"
    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: 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: 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: 20.5% · Safe to merge
    20.5%