Repository navigation
fix(remove): recheck cleanliness after stopping the fsmonitor daemon - #4456
Conversation
…moval-final-checks # Conflicts: # src/git/remove.rs
…ntity # Conflicts: # src/git/repository/tests.rs # src/git/test.rs
Remove the duplicate per-worktree fsmonitor config reader and early cleanliness check. Force still checks captured registration and locks once after shutdown; non-force full-scans through the canonical CleanCheckMode API and rechecks ownership after status. Disable fsmonitor for direct and detached fallback worktree removal and the submodule cleanliness gate. Drop unsupported operation-state refusal per identity review, and reduce shutdown regressions to untracked-work/force and forced ownership/lock contrasts with exact failure assertions. Non-force removal now pays a full scan to protect writes during shutdown; this tradeoff is proposed for review, not recorded as accepted. Source-only repair. Existing command-builder inline snapshots need Insta regeneration before validation.
…ntity # Conflicts: # src/git/repository/tests.rs
…al-checks # Conflicts: # src/git/remove.rs
…t-registration-identity # Conflicts: # src/git/repository/tests.rs
…al-checks # Conflicts: # src/git/remove.rs
…t-registration-identity # Conflicts: # src/git/repository/tests.rs
worktrunk-bot
left a comment
There was a problem hiding this comment.
The Data Safety section of AGENTS.md still says "core.fsmonitor controls Git's final dirty-worktree gate". After this PR, stage_worktree_removal re-checks without fsmonitor, and every git worktree remove that Worktrunk spawns (the remove_worktree direct fallback and build_remove_command's background command) runs with -c core.fsmonitor=false. So for removal, the sentence now describes the policy this PR replaces, and it's the line an agent reads before touching removal gates. That sentence also covers merge/push target updates, where Git's own gate still follows core.fsmonitor. Consider narrowing it to those paths and stating that removal gates rescan without fsmonitor.
…ntity # Conflicts: # src/git/repository/tests.rs # src/git/repository/worktrees.rs
…t-registration-identity # Conflicts: # src/git/repository/tests.rs # src/git/repository/worktrees.rs
…al-checks # Conflicts: # src/commands/process.rs # src/git/repository/worktrees.rs # tests/integration_tests/remove.rs
…al-checks # Conflicts: # src/commands/process.rs
…n-identity # Conflicts: # src/git/repository/tests.rs # src/git/repository/working_tree.rs # src/git/repository/worktrees.rs # src/git/test.rs
Max chose to keep trusting configured fsmonitor and add only a recheck after the daemon shuts down, with no dependency on #4454. This merge takes main's tree; the next commit adds the recheck. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The fsmonitor-served gate runs before the daemon stop, so a file written while the daemon shuts down reached the rename unchecked. With fsmonitor configured, removal now reruns the gate after the stop with fsmonitor disabled, which rescans without starting a new daemon. The pre-stop gate still trusts the daemon, matching git worktree remove. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
The module docs still justify the gate order with a cost this PR now pays. "Why this order" on stage_worktree_removal says the gate runs before the stop because "stopping first would force a full re-stat, the dominant per-removal cost on a large repo", and "The dirty-worktree gate follows git" says scoping -c core.fsmonitor= to the gate "would make wt stricter than the command it replaces, and would restore the full re-stat the ordering above avoids". With the recheck, every successful removal under fsmonitor runs a -c core.fsmonitor=false status after the stop. So it pays that full re-stat, plus a daemon-served status first, and it is now stricter than git worktree remove.
The first gate's remaining job under fsmonitor is to refuse a dirty worktree early, without stopping its daemon. That is a reasonable thing to keep, but a later reader shouldn't have to work it out against docs that argue the opposite. One option is to keep both gates and rewrite those two paragraphs to say the first gate now only gives a cheap early refusal, while the post-stop rescan is what decides a clean removal. The other is to collapse to stop, then one rescan gate under fsmonitor. That makes clean removals slightly cheaper and makes dirty refusals cost a daemon restart. Which trade to make is the author's call. Either way, the paragraphs that currently argue against the rescan should be updated.
Superseded by the review on a later commit.
…al passes The module and stage_worktree_removal docs still argued against the rescan this branch adds. They now say the first gate gives a cheap early refusal and the post-stop rescan decides a clean removal under fsmonitor. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Keep the daemon-backed dirty check before shutdown and remove the unshipped post-stop full scan from #4456, as requested for this release. Restore cached repository configuration for macOS list pre-start. Writes during shutdown retain the v0.81 race window; the release does not adopt a full-tree rescan to close it. Temporary-index ownership and backup protection remain.
Prepares Worktrunk 0.82.0, including release notes, contributor credits, and the minor version bump required by Rust library API changes. Protects active temporary indexes from concurrent stale-file cleanup with an owner lock, preserving forced-removal backups. Restores v0.81.0's daemon-backed removal check and cached macOS fsmonitor startup configuration, as explicitly [approved by the maintainer](#4716 (comment)): the unshipped post-shutdown full scan from #4456 is removed. The separate fix that spares live submodule daemons during orphan cleanup (#4729) remains. Includes current main through `0df653384`, corrected plugin documentation, and regenerated mirrors. Independent review covered the rollback, all intervening main changes, and all 30 changelog entries. Local validation passed 5,502 tests (one skipped), doctests, documentation checks, and 21 built-site tests. Full cross-platform validation and all PR checks, including patch coverage, passed. Tagging awaits explicit sign-off on the full adjudicated release safety review. > _This was written by Codex on behalf of max-sixty_
Removal's dirty-worktree gate runs before wt stops the fsmonitor daemon, since the daemon answers that
git statuscheaply. A file written while the daemon shuts down therefore reached the rename unchecked. Withcore.fsmonitorconfigured, removal now runs the gate once more after the stop, with fsmonitor disabled, which rescans without starting a new daemon in the worktree about to go.The first gate stays, so a dirty worktree is still refused off the daemon's answer with its daemon left running. Under fsmonitor the post-stop rescan is what a clean removal passes: one full re-stat per removal there, which also makes
wtstricter thangit worktree removeagainst a stale daemon answer. Without fsmonitor nothing changes.--forceskips both gates, as before.This narrows the earlier version of this PR, which bypassed fsmonitor for every removal and stacked on #4454; it now targets
mainon its own.