← Back to Pull requests

fix(build-script): run build scripts after CI restores target/ at another path #1046

Closed
unknown closed this pull request without merging on Nov 30, 2026 03:12 UTC
View on GitHub
unknown unknown commented on Nov 30, 2026 02:27 UTC
Author

A CI job that restores target/ at a different checkout path than the job that saved it failed as soon as Cargo reran a build script it did not recompile:

error: failed to run custom build command for `zstd-sys v2.1.3+zstd.1.5.7`

Caused by:
  could not execute process `/tmp/claude-1000/mbx-moved-target/b/app/target/debug/build/zstd-sys/e8dfcc3956bf299c/out/build_script_build` (never executed)

Caused by:
  No such file or directory (os error 2)

mbx now repairs the build-script launchers of a moved target directory it does not manage, so that build succeeds. This affects Unix. A fork, a renamed repository, or a cache shared between jobs that check out at different paths all restore target/ at a new path. It was hit in CI jobs that mounted a target/ saved by jobs with another checkout path, where aws-lc-sys failed this way.

What went wrong

After compiling a build script, mbx replaces Cargo's executable with a small launcher and keeps the real program beside it. When the path is short enough for a shebang, the launcher is one line naming mbx by absolute path:

#!/tmp/claude-1000/mbx-moved-target/a/app/target/debug/.mbx-build-script-shims/76259ded01ab104d/mbx

Restore that target/ under another checkout path and the file is still there, but its interpreter is not, so execve reports ENOENT for a file that exists. That is Cargo's "(never executed) / No such file or directory".

mbx already rewrote the launchers of a profile that had moved, but only for a target directory it manages. In CI it builds into the target/ the job's cache step restored and leaves it unmanaged, so the repair never ran in the one place a target/ routinely arrives from another path.

Cargo runs the stale launcher when a build script's run is out of date while its compilation is not. For cc-using dependencies such as aws-lc-sys and zstd-sys that happens on every such job when the mbx binary lives inside the checkout: mbx sets HOST_CC to a shim directory named for the mbx binary's own path, and those build scripts declare rerun-if-env-changed=HOST_CC.

The fix

When mbx does not place the target directory, it now runs the same repair on the directory Cargo will build into (the build directory when Cargo keeps one apart from the target directory). A profile that has not moved costs one small read of its .mbx-launcher-root marker, as before.

Both this repair and the existing one for a managed target now read the profile from the alias-expanded command. The repair waits for Cargo's lock only on the profile the command builds, so with an alias such as ci-build = "build --release" it used to wait on debug and could skip a release profile that another Cargo held at that moment.

Validation

  • New test a_ci_target_restored_at_another_path_still_runs_its_build_scripts in crates/mbx/tests/build.rs: builds under CI=true into an existing target/, renames the checkout, and builds again with an empty store and the build script's rerun trigger changed. It failed with the "(never executed)" error before the fix and passes with it.

  • The real trigger, by hand on Linux: a fixture depending on zstd-sys, with the mbx binary inside the checkout and no explicit trigger. Released mbx 1.31.0 fails the second build after the move with the error at the top; with this change the build finishes, and the launchers and the marker name the new path.

  • cargo test -p mbx --test build and cargo test -p mbx --lib pass on Linux. Not run on macOS.
  • AI-assisted — Tool: Claude Code; model: anthropic/claude-fable-5-2; version: 2.1.332.

    🤖 Generated with Claude Code

    <!-- CURSOR_SUMMARY -->
    ---

    [!NOTE]

    Medium Risk

    Touches the Cargo startup path on Unix when target placement is skipped; behavior change is localized to launcher rewrite but runs on every such build.

    > Overview

    On Unix, build-script launchers are now repaired when mbx does not manage target/ — the usual CI case where a cached target/ is restored under a different checkout path. Launchers embed mbx by absolute path, so they break after a move until rewritten.

    > When target placement is declined, mbx now runs the same repair_all_launchers path used for managed views against the directory Cargo will actually use (build_dir if separate, otherwise target_dir), keyed off expanded Cargo invocation arguments for profile directories. The managed-placement path also switches from raw arguments to &expanded for that profile list.

    > A new integration test builds with CI=true, renames the checkout to simulate a restored cache at another path, and asserts build scripts still run and launchers no longer reference the old path.

    > <sup>Reviewed by Cursor Bugbot for commit c997599201f5272bac33ce1e1c4c86d80e75f675. 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
    On Unix, launchers are repaired when managed target placement is unavailable, using the selected build profile’s directories. If no separate build directory is resolved, the target directory is used.
    Launcher repairs now account for effective profiles selected through Cargo aliases.
    Builds restored from a different checkout path no longer leave launchers pointing to the original location, helping projects work after build artifacts are moved.

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

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: jdx Review duration: 45m
    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 #1046"
    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%