Skip to content

fix(copy-ignored): stamp copied files with one mtime so cargo keeps its cache - #4319

Merged
max-sixty merged 1 commit into
mainfrom
fix/copy-ignored-uniform-mtime
Sep 29, 2026
Merged

max-sixty merged 1 commit into
mainfrom
fix/copy-ignored-uniform-mtime

Conversation

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

On Linux, wt step copy-ignored gives each copied file the time its copy happened to finish. Leaves are copied in parallel, so inside target/ a dependency's .rlib can 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 ffbfcaf7b on ext4:

Seeding the new worktree Units cargo build recompiles
wt step copy-ignored on main 203
cp -a (source mtimes preserved) 2
wt step copy-ignored with this PR 2

With CARGO_LOG=cargo::core::compiler::fingerprint=info, main's rebuild starts from StaleDependency { dep_mtime, max_mtime } entries a few hundred ms apart, and StaleDepFingerprint carries them up the graph. With this PR, the only dirty item left is MissingFile { .git/HEAD }: worktrunk's build script watches that path, and in a linked worktree .git is 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 add writes the tracked files before copy-ignored runs. Preserved outputs therefore end up older than those sources. In the cp -a row, worktrunk's build script reran because the checked-out build.rs was newer than its dep-info, and the thread's earlier measurements found the same with cargo, make and tsc -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:

  • The stamp covers regular files only. Symlinks keep their copy-time mtime, because std can't set a link's own times without following it. Directories keep theirs too.
  • A failure to set the time is logged at debug and doesn't fail the copy.
  • Copy time didn't change: 2.1s for 3.3 GiB / 3759 files, warm, before and after.
  • wt step promote's cross-device fallback passes None, 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_modified call 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.

…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
max-sixty merged commit 7c94d69 into main Sep 29, 2026
37 checks passed
@max-sixty
max-sixty deleted the fix/copy-ignored-uniform-mtime branch September 29, 2026 04:32
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants