Skip to content

rust.sh shares one CARGO_TARGET_DIR across worktrees, so a scratch-copy build poisons the next run #906

Closed

Description

@chappie-daemon

scripts/rust.sh runs every build in one container with CARGO_TARGET_DIR=/target and the source mounted at /work/nostream. A build of a scratch copy of the tree — the shape a reviewer uses to prove a fix by reverting it — writes into that same target directory, and the next worktree run then reads artifacts keyed to the scratch path.

Measured during the 4.0 rewrite (006-nostream-core, round 3): a revert build followed by the worktree suite gave 51 passed / 2 failed; touch-ing the affected sources and re-running gave 53 passed / 0 failed, with no source change. The failures were stale artifacts, not defects.

Two candidate fixes:

  1. Isolate the target for a scratch run: pass CARGO_TARGET_DIR=/target-$(basename "$PWD") (or a caller-supplied CARGO_TARGET_DIR) instead of a single shared /target.
  2. Keep the shared target and document the requirement in the script header: after building anything outside the job worktree, touch the sources before the next worktree run.

(2) is a one-line comment; (1) costs a cold build per distinct path but removes the trap. The reviewer that hit it lost one round-trip and nearly reported a regression that did not exist.

Activity

  1. chappie-daemon commented on Oct 20, 2026

    @chappie-daemon
    CollaboratorAuthor

    Fixed by #914, merged as 6ef609a.

    scripts/rust.sh now derives the target directory from the checkout path — /target-<basename>-<cksum>, mounted from the same key under RUST_CACHE_HOST — so two trees no longer share fingerprints. CARGO_TARGET_DIR still overrides (absolute only; relative exits 64), and RUST_CACHE_VISIBLE names the client-side spelling when the cache root is not visible from the calling shell, in which case a daemon-only root is warned about and left to the daemon rather than refused.

    Measured on a scratch copy with run_transaction reverted: the old script's worktree ran the scratch binary with no Compiling line and failed op 117 (transaction) differs from the TypeScript capture; touch then cleared it. With the fix the two runs wrote target-scratch-906-562595450 and target-906-rust-target-53259279 and neither read the other. Cost: one cold build per checkout, 36 s for cargo test --workspace --all-features --no-run, 21 s for cargo check -p nostream-storage on a second path.

    The same pattern still exists outside this repository in containers/rust-builder/rb-run; filed separately as cameri/phoenix-server#48, since it cannot be fixed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions