Skip to content

fix(remove): recheck cleanliness after stopping the fsmonitor daemon - #4456

Merged
max-sixty merged 46 commits into
mainfrom
codex/removal-final-checks
Oct 20, 2026
Merged

max-sixty merged 46 commits into
mainfrom
codex/removal-final-checks

Conversation

@max-sixty

@max-sixty max-sixty commented Oct 12, 2026 •

Copy link
Copy Markdown
Owner

Removal's dirty-worktree gate runs before wt stops the fsmonitor daemon, since the daemon answers that git status cheaply. A file written while the daemon shuts down therefore reached the rename unchecked. With core.fsmonitor configured, 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 wt stricter than git worktree remove against a stale daemon answer. Without fsmonitor nothing changes. --force skips 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 main on its own.

This was written by Claude Code on behalf of max-sixty

…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
…t-registration-identity

# Conflicts:
#	src/git/repository/tests.rs
…t-registration-identity

# Conflicts:
#	src/git/repository/tests.rs

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

worktrunk-bot
worktrunk-bot previously approved these changes Oct 12, 2026
max-sixty and others added 10 commits October 12, 2026 16:43
…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]>
@max-sixty max-sixty changed the title Recheck worktree ownership and cleanliness before removal fix(remove): recheck cleanliness after stopping the fsmonitor daemon Oct 20, 2026
@max-sixty
max-sixty changed the base branch from codex/git-registration-identity to main October 20, 2026 22:24

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@worktrunk-bot
worktrunk-bot dismissed their stale review October 20, 2026 22:28

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]>
@max-sixty
max-sixty merged commit 3ec0bf7 into main Oct 20, 2026
38 checks passed
@max-sixty
max-sixty deleted the codex/removal-final-checks branch October 20, 2026 22:53
max-sixty added a commit that referenced this pull request Nov 14, 2026
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.
@max-sixty max-sixty mentioned this pull request Nov 14, 2026
max-sixty added a commit that referenced this pull request Nov 14, 2026
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_
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