Skip to content

fix(tests): stop git auto-maintenance from deleting the promote test's new worktree - #4466

Merged
max-sixty merged 1 commit into
mainfrom
fix/issue-4464-promote-maintenance-race
Oct 13, 2026
Merged

max-sixty merged 1 commit into
mainfrom
fix/issue-4464-promote-maintenance-race

Conversation

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

test_promote_bare_repo_with_worktrees failed during setup in nightly run 38353472092. Its plain git worktree add against the bare fixture died with fatal: could not open 'worktrees/worktree/locked' for writing: No such file or directory. This is the second occurrence: #3918 recorded the same failure in August and closed it as a one-off.

The cause is Git's own auto-maintenance. The test's git push into the bare repo makes receive-pack start git maintenance run --auto --quiet --detach in that repo, which keeps running after the push returns. Under Git 2.55, auto-maintenance includes the worktree-prune task, and that task deletes any worktrees/<name> directory without a gitdir file. git worktree add leaves exactly that state for a moment, between creating worktrees/<name> and writing its locked file. If the detached maintenance scans during that moment, it removes the directory, and the write fails with ENOENT.

The test now sets maintenance.auto=false in the bare repo before pushing. It has to be repo config: receive-pack strips GIT_CONFIG_* from its environment for local transports, so the suite's hermetic env never reaches it.

What was verified locally (git 2.55.0)
  • A GIT_TRACE2 trace of the push shows receive-pack spawning git maintenance run --auto --quiet --detach.
  • In a bare repo, git maintenance run --auto deletes a hand-made worktrees/x directory that has no gitdir file.
  • Passing maintenance.auto=false through GIT_CONFIG_COUNT does not stop the push's maintenance child. The same setting in the bare repo's config does: the trace then shows no maintenance child.
  • The timing overlap itself did not reproduce. 300 serial runs of the fixture sequence all passed, so the race needs CI-level load. The fix removes the deleting process rather than narrowing the window.
  • cargo test --test integration step_promote passes.

git commit also spawns detached auto-maintenance, but the suite's hermetic env could turn that off. Every failure seen so far came through the push path, so this PR leaves the commit path alone.

The other failure in the same run, dirs reported unused by udeps, is fixed separately in #4465.

Refs #4464 — automated triage

…tree

Pushing into the bare fixture makes receive-pack start a detached
git maintenance run --auto. Its worktree-prune task deletes a
worktrees/<name> directory that has no gitdir file yet, which is the
state git worktree add leaves between its mkdir and writing the
locked file. When the two overlap, worktree add fails with
"could not open 'worktrees/worktree/locked' for writing".
receive-pack strips GIT_CONFIG_* from its environment, so the bare
repo's own config disables auto-maintenance.

Refs #4464
@worktrunk-bot worktrunk-bot added the automated-fix Automated CI fix label Oct 13, 2026
This was referenced Oct 13, 2026
@max-sixty
max-sixty merged commit a48f470 into main Oct 13, 2026
37 of 47 checks passed
@max-sixty
max-sixty deleted the fix/issue-4464-promote-maintenance-race branch October 13, 2026 20:19
max-sixty pushed a commit that referenced this pull request Oct 13, 2026
After #4436 removed the `dirs::data_dir()` fallbacks, the only remaining
use of `dirs` is `dirs::document_dir()` inside `#[cfg(windows)]` in
`src/shell/paths.rs` (`powershell_profile_paths`). The nightly
`check-unused-dependencies` job runs `cargo udeps --all-targets` on
Linux, and in [run
38353472092](https://github.com/max-sixty/worktrunk/actions/runs/38353472092)
it reports `dirs` as unused. This PR moves `dirs` into a
`[target.'cfg(windows)'.dependencies]` table so Linux and macOS builds
no longer pull it in. `Cargo.lock` is unchanged.

I couldn't run `cargo udeps` locally because it needs a nightly
toolchain. The Windows build in this PR's CI confirms that `dirs` still
resolves where it's used.

The same nightly run had a second, unrelated failure, a race in
`test_promote_bare_repo_with_worktrees`. #4466 fixes it separately.

Refs #4464 — automated triage

Co-authored-by: worktrunk-bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automated-fix Automated CI fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants