Repository navigation
fix(copy-ignored): stamp copied files with one mtime so cargo keeps its cache - #4319
Merged
Merged
Conversation
…ts cache On Linux, `wt step copy-ignored` left each copied file with the time its parallel copy happened to write it, so within `target/` a dependency's rlib could land newer than a dependent's dep-info. Cargo reads that as a stale dependency: seeding a worktrunk worktree this way recompiled 203 units. Every file the step copies now gets one mtime taken before the copy starts, which drops that rebuild to the 2 units worktrunk's build script reruns for `.git/HEAD`. A single stamp rather than preserving source times: preserved outputs come out older than the sources `git worktree add` just wrote, which reruns build scripts and recompiles workspace members. Refs #4248 Co-Authored-By: Claude <[email protected]>
max-sixty
added a commit
that referenced
this pull request
Oct 20, 2026
Since v0.80.0, `wt step copy-ignored` produces stale cargo builds. #4319 stamps every copied file with one time taken after `git worktree add`, so a copied `target/` looks newer than the sources that checkout just wrote, and cargo treats it as up to date. Repro: build v1 in main, commit v2 without rebuilding, `wt switch --create feat`, `wt step copy-ignored`, `cargo build`. On main cargo finishes in 0.00s and the binary prints v1; v0.80.0 (which kept source mtimes through clonefile on macOS) recompiles and prints v2. This gives each copied regular file its source's mtime, as `cp -a` does, on every platform, and removes the stamp parameter. That still covers #4248's Linux case, where parallel copies ordered files by scheduling: #4319's own table shows `cp -a` recompiles the same two units as the stamp. `wt step promote`'s cross-device fallback shares the helper, so it now keeps mtimes too, like `mv` across filesystems. Symlinks and directories keep the copy time, as in v0.80.0. Verified on macOS: the repro above now recompiles and prints v2, and a tree with 2020-dated ignored files keeps the same mtimes as v0.80.0. The new integration test copies files with distinct past mtimes through a directory entry and a top-level entry; it fails on main and passes here. The read-only unit test now asserts the source mtime. Not covered, on v0.80.0 either: copying into an existing worktree whose sources were checked out before the source worktree's build still leaves outputs newer than those sources, so cargo reuses them. > _This was written by Claude Code on behalf of max-sixty_ Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Linux,
wt step copy-ignoredgives each copied file the time its copy happened to finish. Leaves are copied in parallel, so insidetarget/a dependency's.rlibcan end up newer than the dep-info of a crate that depends on it, and cargo marks that crate dirty. This PR gives every file the step copies a single mtime, taken before the copy starts. @max-sixty asked in #4248 for a repro where this matters before adding it, and @paul-hansen supplied one.Their repro, run against this repo at
ffbfcaf7bon ext4:cargo buildrecompileswt step copy-ignoredon maincp -a(source mtimes preserved)wt step copy-ignoredwith this PRWith
CARGO_LOG=cargo::core::compiler::fingerprint=info, main's rebuild starts fromStaleDependency { dep_mtime, max_mtime }entries a few hundred ms apart, andStaleDepFingerprintcarries them up the graph. With this PR, the only dirty item left isMissingFile { .git/HEAD }: worktrunk's build script watches that path, and in a linked worktree.gitis a file. So the 2 remaining units are worktrunk and wt-perf, unrelated to the copy.Why one stamp instead of the source mtimes.
git worktree addwrites the tracked files beforecopy-ignoredruns. Preserved outputs therefore end up older than those sources. In thecp -arow, worktrunk's build script reran because the checked-outbuild.rswas newer than its dep-info, and the thread's earlier measurements found the same with cargo, make andtsc -b. A stamp taken after the checkout keeps the copied outputs newer than the sources, and makes files inside the copied tree compare as equal.Details:
stdcan't set a link's own times without following it. Directories keep theirs too.wt step promote's cross-device fallback passesNone, so its behavior is unchanged.New unit tests check that every copied file in a tree gets the stamp, and that a read-only (0o444) file gets it and stays 0o444. Both fail with the
set_modifiedcall removed.Refs #4248. The Mix case in that issue isn't fixed by this: @dmy-gh tested a single stamp there and Mix still recompiled.