Repository navigation
fix(tooling): key the rust build directory to the checkout - #914
Conversation
Every checkout is mounted at /work/nostream, so cargo could not distinguish one tree's artifacts from another's in the shared cache/target: a scratch build left a test binary compiled from reverted sources, and the next worktree run executed it without recompiling. Derive the target directory from the checkout's basename and a checksum of its full path; keep CARGO_TARGET_DIR as the override. Refs #906.
[Medium impact] The PR appears safe to merge; the earlier remote-cache refusal is fixed.
|
A cache root this shell cannot see is owned by the Docker host (a remote daemon, or the sandbox seeing the same tree at /workspace). Refusing that case would break a cache that works. Create the keyed directory only when one of the two spellings exists, and keep the loud refusal for a visible root that is not writable.
🦋 Changeset detectedLatest commit: ab3ab63 The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
A remote daemon keeps the cache on its own host, where this shell cannot create the per-checkout directory and the daemon would create it as root. RUST_CACHE_VISIBLE names the spelling this shell sees, so the directory is still created with the right owner; when no spelling is visible the script says which path must exist on the daemon and carries on instead of refusing.
|
@greptile-apps review — the P1 you raised was fixed in 12077ff and the check still carries the pre-fix verdict. |
|
The remote-cache gap is closed in A cache root the client cannot see can no longer fail the run. Measured on this head:
The remote path cannot be exercised end to end from here — the sandbox exposes no second daemon — so the first of those warning cases is the one that needs a real remote host's confirmation. |
scripts/rust.shgave every checkout the same build directory. This keys it to the checkout instead. Refs #906, part of #871.The failure
Every tree is mounted at
/work/nostream, so cargo's fingerprints for a scratch copy and for a worktree are identical. Onecache/target, mounted at/target, is therefore shared without any way to tell which sources produced an artifact.Reproduced on a fresh worktree of
rewrite/main(a3eee6a), with a scratch copy made bycp -a(mtimes preserved) and one source reverted in it —run_transactionback to&mut HashMap::new(), the #912 bug:No
Compilingline: the worktree ran the scratch copy's binary.touch crates/nostream-storage/tests/parity.rsthen producedCompiling nostream-storage … ok. 2 passed— the workaround this PR removes, not a step to follow.The fix
The container gets
CARGO_TARGET_DIR=/target-<basename>-<checksum>and that path is bind-mounted from$RUST_CACHE_HOST/target-<basename>-<checksum>. Readable, and two trees that share a basename stay apart.CARGO_TARGET_DIRstill overrides the derived name (absolute only; a relative value exits 64), and, when the cache root is visible to this shell, the script creates the directory first (the daemon would create a missing bind source as root, which uid 1000 then cannot write). A root that exists only on the daemon's side is left to the daemon, so a remote-Docker cachekeeps working:
RUST_CACHE_VISIBLEnames where this shell sees the cache (a remote daemon, or anymount other than the
/workspace↔/home/cameri/Workspacepair), and when no spelling is visiblethe script prints the exact path the daemon host must provide, once, instead of refusing a cache it
cannot check.
For a remote Docker host the per-checkout directory has to exist before the first run, because the
daemon creates a missing bind source as root and uid 1000 then cannot write it:
Toolchain and registry under
RUST_CACHE_HOSTstay shared. The trade: one cold build per checkout, measured at 36 s forcargo test --workspace --all-features --no-runinto an empty keyed directory on this machine, and 21 s forcargo check -p nostream-storageon a second path.Same sequence with the fix
The two runs wrote
cache/target-scratch-906-562595450andcache/target-906-rust-target-53259279; neither read the other.What else referenced
/targetscripts/rust.shis the only in-repo reference;RUST_CACHE_VISIBLEis new..gitignorehas/target/, which is a local target directory, unrelated.containers/rust-builder/rb-run:45,134,138carries the same pattern (CACHE_TARGET=$STACK/cache/target,CARGO_TARGET_DIR=/target) and the same hazard for anyone building two trees through it. It is outside this repository, so this PR does not touch it — it needs its own change.cache/targetis left in place: it may still serverb-runor a stale checkout. This script no longer uses it, and deleting it is safe whenever someone wants the disk back.cache/target-r3secalready exists, which suggests someone had keyed a target directory by hand before this.A changeset is included. CI's
Rust Checksruns on this PR becausescripts/rust.shis in its path filter; the TypeScript jobs skip.