Skip to content

fix(worktrees): keep an unregistered task directory's content without --force - #1986

Merged
yyhhyyyyyy merged 10 commits into
mainfrom
hui/worktree-remove-unregistered
Nov 24, 2026
Merged

yyhhyyyyyy merged 10 commits into
mainfrom
hui/worktree-remove-unregistered

Conversation

@yyhhyyyyyy

@yyhhyyyyyy yyhhyyyyyy commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

dimcode worktree remove TASK_ID deletes an unregistered task directory below the managed root. Without --force, ordinary files and symlinks in that directory were removed with it, although the CLI contract removes such a directory only when it has no .git entry and is empty, or when --force is given. The refusal ran only for plain subdirectories and was checked while earlier subdirectories had already been deleted, the final deletion dropped its error and still reported removed: true, and a Session whose cwd is the task directory itself was not checked at all because the Session check ran per child. See #1981.

The removal now refuses with worktree_in_use when a stored Session workspace is at or under the task directory, checked once for the directory itself before it inspects children and again in the store's removal operation, with and without --force. It then checks every child before deleting anything, and refuses a non-directory child (files, symlinks) or a non-empty plain subdirectory without --force with worktree_in_use. An empty <repo-name> subdirectory under the task directory is still cleaned without --force, which is what worktree.list reports for a failed creation. A .git entry anywhere in the tree the removal deletes, whether directly in the task directory or deeper, as a directory, a gitdir file or a symlink including a dangling one, refuses even with --force and names the path, as the removal contract requires. Without --force, the deletion then removes only those checked empty directories one by one without recursion, so content that appears after the check makes the removal fail with worktree_in_use instead of being deleted. With --force the directory is removed recursively as before, and a failed deletion returns worktree_store_failed instead of removed: true. worktree.prune --apply still records each failure in failed and continues with the remaining candidates, and its selection still never includes unregistered entries.

The final directory-record and Session checks and the deletion run in the same critical section as Session creation and worktree association. The SessionStore owner's removeUnregisteredDirectory operation holds the ownership mutex that createOwnedSession and associate_worktree use, refuses with worktree_in_use when a directory record's root is at or under the task directory, re-checks for a stored Session workspace at or under it, and runs the removal before releasing the mutex; an unregistered directory needs no worktree record of its own. The removal repeats the pre-check's filesystem facts under the same mutex before it deletes: the task directory is a plain directory without a .git entry, each immediate child is a plain directory at its own canonical path under the managed root without a .git entry, and every directory in the tree has no .git entry in any form (a directory, a gitdir file or a symlink, including a dangling one). The tree walk uses symlink_metadata, does not follow symlinks and stays inside the task directory. These are filesystem checks only, so no Git subprocess runs under the mutex. The mutex has no time limit: the tree walk and a --force deletion recurse inside it, and while it runs Session creation, fork and deletion and worktree association or removal wait for it. A Session created first makes the removal fail with worktree_in_use; a removal that wins makes the creation's existing workspace check fail with the Session workspace ... no longer exists. Neither ordering leaves a Session pointing at a deleted workspace. Dropping the caller does not release the mutex while the deletion still runs. The content check runs before the mutex; without --force the lock-time recheck repeats it, and content that appeared in a checked child makes the removal fail with worktree_in_use. The operation takes {root}, rejects a root that is not absolute and normal, and answers {removed}; a removal whose directory another removal already deleted answers worktree_not_found instead of a storage failure.

Tests in crates/dim-app-server/tests/transport_flow/worktrees.rs cover an ordinary file refused without --force, the same directory removed with --force, an empty repository subdirectory cleaned without --force, two children rejected together with both intact, a failed deletion reported as worktree_store_failed, a symlink refused with its target untouched, a task directory with a .git entry refused even with --force, a dangling .git symlink refused with the link intact, a .git directory, a gitdir file and a dangling .git symlink below a direct child each refusing with --force and leaving the tree intact, a deep tree without Git metadata removed with --force, a Session at the task root keeping an empty directory without --force and a filled one with --force, a Session created after the content check keeping the directory, a worktree associated after the content check keeping the task directory and the worktree, a .git entry added after the content check keeping the directory, a recorded directory refused before the removal callback runs, a creation queued behind a removal failing its own workspace check without leaving a Session row, a relative or .. root refused with the directory intact, a second concurrent removal answering worktree_not_found after the first one deleted the directory, and a dropped caller keeping the mutex held until the deletion finishes. Unit tests in crates/dim-app-server/src/worktrees.rs place content in the task directory and in a checked subdirectory after the check and assert that the removal returns worktree_in_use with the content intact. The cross-language store fixture covers the operation's refusal while a Session uses the directory and a creation blocked while the callback holds the mutex. The nested Git-metadata tests fail without the tree walk and pass with it; the associated-worktree, added-.git and recorded-directory tests fail without the lock-time record and Git rechecks and pass with them. On main, the file, all-children, deletion-failure, symlink, .git, dangling .git, nested Git-metadata, path-shape, concurrent-not-found and dropped-caller tests fail; the force, empty-subdirectory and deep-tree tests pass there and remain as regression protection.

Fixes #1981

… --force

An unregistered task directory was deleted with `remove_dir_all` even
without `--force`, so ordinary files and symlinks inside it were removed
too. The "not empty" refusal covered only plain subdirectories, and it
ran after earlier subdirectories had already been deleted. The final
deletion dropped its error and still reported `removed: true`.

Without `--force`, refuse any child that is not a plain directory, and
any plain subdirectory that is not empty, with `worktree_in_use`. An
empty `<repo-name>` subdirectory that `worktree.list` reports as
unregistered is still cleaned. The first pass only checks every child;
the directory is deleted once, only when all checks pass, and a failed
deletion reports `worktree_store_failed`.

A `.git` entry directly in the task directory now refuses even with
`--force`, as the managed-worktree contract requires; the message names
the path and leaves it to `git worktree remove`.

Add flow tests for the file, empty-subdirectory, all-children,
deletion-failure, symlink and `.git` cases.

Fixes #1981
The removal checked every child and then deleted the task directory
recursively, so content written after the check was also deleted without
`--force`. Without `--force`, remove only the empty subdirectories the
check recorded and the task directory itself, each with a non-recursive
delete, so content that appears after the check returns
`worktree_in_use` instead of being deleted. A `.git` entry is detected
with `symlink_metadata`, so a dangling symlink also refuses the removal.

Cover the deletion step directly with unit tests for content that
appears after the check, restore the permission of the failed-deletion
test on panic and skip it where file permissions do not bind the test
user, and refuse a dangling `.git` symlink with `--force`.

Fixes #1981

@eric8810 eric8810 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 preflight and non-recursive no-force deletion address the original file-loss case. The new tests also cover dangling .git and make a failed deletion visible to callers.

[P2] Refuse deletion when a stored Session uses the task directory itself. crates/dim-app-server/src/worktrees.rs:857–866 checks sessions_under_workspace once per plain child, but the directory removed at :884–885 is the parent entry. A Session with cwd exactly <managed-root>/<task-id> is not under any child, so an empty task directory can still be removed under that Session, even without --force. This also violates the worktree removal contract, which requires the directory to have no Session workspace and treats force as a content override only. Query sessions_under_workspace(&entry) once to cover the root and all descendants; ideally use the same store ownership exclusion as the recorded path so a new Session cannot appear between the check and removal. Add a fixture that creates a Session at the task root and checks that both ordinary and forced removal leave it intact.

This is a source finding; I did not run the Rust fixtures locally. Exact CI was in progress.

The removal checked `sessions_under_workspace` once per plain child but
then deleted the parent task directory, so a Session whose cwd is the
task directory itself was not under any child and an empty task
directory could still be removed under it, with or without `--force`.

Query the task directory once before inspecting any child, which covers
the root and every descendant, and refuse with `worktree_in_use` for
both the ordinary and the forced removal. The check is a store read
rather than the ownership-locked removal that the recorded path uses,
because an unregistered directory has no record to remove; a Session
created between the check and the deletion is therefore not excluded.

Add a flow test that places a Session at the task root and checks that
both removals fail and leave the directory and its content intact.

Fixes #1981
@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

#1986 (review)

Fixed in a79a2b2. remove_unregistered now queries sessions_under_workspace(&entry) once for the task directory itself, before it inspects any child, so the query covers the root and every descendant. A Session whose cwd is <managed-root>/<task-id> refuses the removal with worktree_in_use with and without --force; the per-child query is gone because the single query covers it.

The check is a SessionStore read, not the ownership-locked removal that the recorded path uses: an unregistered directory has no directory record, and that removal requires one. A Session created between the read and the deletion is therefore not excluded by it; without --force the deletion still only removes directories that were empty at the check.

The new test worktrees::unregistered_remove_refuses_a_task_directory_a_session_uses in crates/dim-app-server/tests/transport_flow/worktrees.rs creates a Session at the task root, once in an empty directory and once with a file, and asserts that both the ordinary and the forced removal return worktree_in_use with the directory and its content intact. It fails before the change and passes with it.

@yyhhyyyyyy
yyhhyyyyyy requested a review from eric8810 November 21, 2026 20:32

@eric8810 eric8810 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 task-root lookup fixes the previous sequential case, and the new fixture covers ordinary and forced removal.

[P2] Serialize unregistered removal with Session creation. worktrees.rs:819–831,885–887 snapshots Session ownership before the asynchronous directory preflight, then deletes outside the ownership lock. A normal session.create can validate this cwd and commit a Session in between (storage/timeline.rs:1524–1557). The remove then reports success and leaves the new Session pointing at a deleted workspace. Nonrecursive removal protects files, not an empty workspace; --force can also remove its contents. The new task-wide lookup means every descendant is now checked before the entire preflight, rather than immediately before handling that child.

Please add an unregistered-removal operation to the SessionStore owner that performs the final cwd check and the removal under the same ownership lock as creation, without requiring a worktree record. That lets either creation win and block removal, or removal win and make creation's existing cwd recheck fail. A gated test for both orderings would complement the new sequential fixture.

Source review only. Exact CI was still running.

The removal checked stored Session workspaces before its asynchronous
content preflight and deleted after that check, outside the ownership
lock that `createOwnedSession` takes. A Session creation could validate
the same cwd and commit between the two, and the removal then reported
success while the new Session pointed at a deleted workspace.

Add `SessionStore::remove_unregistered_directory`, exposed on the store
face: it holds the ownership lock from the final session-workspace
check through the caller's removal, so creation that commits first
makes the removal fail with `worktree_in_use`, and a removal that runs
first makes creation's existing workspace check fail. An unregistered
directory needs no worktree record. The content preflight and the
stored empty children stay outside the lock.

Add two flow tests: one holds the removal after its content check and
creates a Session at the task root, the other holds the removal while
it owns the lock and queues a creation for the same cwd.

Fixes #1981
The hold has no dependency on the connection holds; keeping it before
them leaves the neighboring insertion points free for other testing
hooks.

Fixes #1981
…ed removal

The store operation behind an unregistered removal accepted relative
paths and paths with `..`, which compare lexically against stored
Session workspaces while the filesystem resolves them. Reject any path
that is not absolute and normal before taking the ownership lock.

A second concurrent `--force` removal that passed its content check
re-entered the lock after the first one deleted the directory and
reported a storage failure from the missing path. Re-check under the
lock and answer not found when another removal already finished.

Dropping the caller of a removal released the lock while the deletion
still ran. Run the check and the removal in a task that owns the lock,
so the lock is held until the deletion finishes, and report the
owner's removed flag on the store face.

Fixes #1981
@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

#1986 (review)

Fixed in 99586c0.

The unregistered removal runs under the ownership mutex that createOwnedSession uses, from the final stored-workspace check through the caller's deletion. With --force that deletion is recursive, and the mutex has no time limit: while it runs, Session creation, fork and deletion and worktree association or removal wait for it. §5 of docs/design/worktree-management.md now states this, including that a registered worktree's in-lock git worktree remove and the unregistered-root cleanup are likewise not bounded by one Git timeout.

The store operation now rejects a root that is not absolute and normal, so a relative path or one with .. can no longer compare lexically against stored workspaces while the filesystem resolves it. It re-checks the directory under the mutex and answers not found when another removal already deleted it. The check and the deletion run in a task that owns the mutex, so dropping the caller does not release the lock while the deletion still runs. Its request is {root} and its reply {removed}, matching the other removal operation.

New tests in crates/dim-app-server/tests/transport_flow/worktrees.rs: worktrees::unregistered_removal_refuses_a_path_that_is_not_absolute_and_normal, worktrees::unregistered_remove_reports_not_found_when_another_removal_won, and worktrees::dropping_the_caller_keeps_the_removal_lock_until_the_deletion_finishes. All three fail on bc6be88: the first runs the deletion callback, the second answers worktree_store_failed, and the third lets a queued Session creation succeed. runtime/fixtures/store.ts covers the cross-language call, its refusal while a Session uses the directory, and a creation blocked while the callback holds the mutex. The earlier tests are unchanged and pass.

@yyhhyyyyyy
yyhhyyyyyy requested a review from eric8810 November 22, 2026 02:31

@eric8810 eric8810 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.

Re-reviewed 99586c0a. The final Session workspace check and removal now share the ownership mutex with normal Session creation, and the detached removal keeps that exclusion after caller cancellation. That addresses the previous finding.

[P2] Revalidate that this is still an unregistered directory under the ownership lock. crates/dim-app-server/src/worktrees.rs:706–724 selects the unregistered path from a directory-record snapshot before the lock. Its Git checks are also before the lock (:835–892). The locked owner method only rechecks existence and Session cwd (storage/timeline.rs:1815–1833); the forced deletion does not repeat registration/Git checks (worktrees.rs:916–925,1144–1160). A normal association can register an existing sibling worktree while the Session's cwd remains in its source checkout (file_access.rs:425–501), so an association can take effect before removal acquires the lock without the cwd check detecting it. The removal would delete the worktree while retaining its records, although force only overrides the content check.

Under the same ownership exclusion, reject a newly recorded/associated directory at or beneath the task root, and recheck that the task directory meets the unregistered Git and path conditions before deletion. The non-destructive regression can gate removal before lock acquisition, commit an association, and assert the removal callback never runs. Static finding; exact CI was still running.

An unregistered removal took its task directory from a
directory-record snapshot and checked its Git facts before it
acquired the store's ownership lock. An association committed in
between recorded a worktree under the task root while its
Session's cwd stayed in the source checkout, so the final cwd
check passed and a forced removal deleted the worktree but kept
its records.

The store now refuses a directory record at or under the task root
inside the ownership lock. The removal step repeats the pre-check's
filesystem facts under the same lock before it deletes: the task
directory is a plain directory without a `.git` entry, and every
immediate child is a plain directory at its own canonical path
under the managed root without a `.git` entry. Only filesystem
checks run under the lock; no Git subprocess starts.

Three regression tests gate the removal before the lock and then
commit an association, add a `.git` entry, or associate a recorded
directory: each is refused with `worktree_in_use` and leaves the
directory, its file and the associated worktree intact. A
store-level test asserts the removal callback never runs for a
recorded directory.

Fixes #1981
@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

#1986 (review)

Fixed in 52defcf.

store.removeUnregisteredDirectory now reads the directory records under the ownership mutex and refuses with worktree_in_use when a record's root is at or under the task directory, naming the recorded path. The removal step it runs repeats the pre-check's filesystem facts under the same mutex before it deletes anything: the task directory is a plain directory without a .git entry, and every immediate child is a plain directory at its own canonical path under the managed root without a .git entry. No Git subprocess runs under the mutex, and --force still only skips the content checks.

Regression tests in crates/dim-app-server/tests/transport_flow/worktrees.rs: unregistered_remove_refuses_a_directory_associated_after_the_content_check gates the removal before it takes the mutex, associates a fresh worktree under the task root from a Session whose cwd is the source checkout, and asserts the call is refused with worktree_in_use while the task directory, its file and the associated worktree stay intact. unregistered_remove_refuses_a_git_entry_added_after_the_content_check adds a .git entry at the same point and asserts the same refusal with the directory intact. unregistered_removal_refuses_a_recorded_directory_before_the_callback asserts the removal callback never runs for a recorded directory. All three fail on 99586c0 and pass on this head.

@yyhhyyyyyy
yyhhyyyyyy requested a review from eric8810 November 22, 2026 04:33

@eric8810 eric8810 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.

Reviewed at head 52defcf.

This fixes three real holes in one path, and fixes them where the state lives. The Session check moved from per-child to once for the directory itself, so a Session whose cwd is the task directory is now seen; every child is inspected before anything is deleted, so a refusal no longer leaves earlier subdirectories already gone; and the final deletion's error is no longer dropped while reporting removed: true. Checking again inside the store's removal operation is the right second gate rather than a duplicated one — the first check is about what the tree looks like, the second about what the store knows, and they can disagree by the time the delete runs.

The face change is handled the way §2 asks: sessions_under_workspace on the storage face delegates to the owner, resource-faces.md and the generated catalog move with it, and the design page states the refusal. The testing-gated removal_hold is the part I would have reached for too — a check/delete race that only shows up under load needs a way to be stopped at the boundary, and gating it behind a feature keeps it out of the product.

verify (linux) and ci-ok failed on this head, outside this PR's path:

staged_update::tui_update::update_now_refuses_a_busy_daemon_and_prints_manual_command
228 passed; 1 failed

The update_now cluster has been red on many heads this week (fifteen cases, then one, now this), and it is a TUI frame assertion against the updater, not worktree removal. Not approving while a required check is red.

Non-blocking: none.

Verification: not run — I read the worktrees.rs delta, the file list and one failing test name; I did not read the storage face body, the new flow tests, or the docs deltas.

@zerob13 zerob13 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.

Re-reviewed 52defcf724ca4cfed494d2220a47997b33750f60. The SessionStore registration check now runs under the ownership lock and its targeted CI regression passes.

[P2] Match the repository protection check to the deletion scope. The design says the unregistered directory must not contain Git metadata. The final guard in crates/dim-app-server/src/worktrees.rs:1078–1186 does not cover the full tree that forced removal may delete. Force should waive the ordinary-content check, not the repository protection. Preserve that protection for the full deletion scope, or narrow what the operation removes. This inherited mismatch is a source finding; no destructive probe was run.

Linux CI passed the worktree cases but failed the separate update prompt test. It ran against the prior main, not the current combined tree.

The final unregistered-removal check looked only at the task directory
and its immediate children, while --force deletes the entire tree, so
a deeper .git directory, gitdir file or symlink was deleted with it.

The removal now walks every directory in the tree it is about to delete,
under the same ownership lock and before any deletion. A .git entry in
any form refuses the whole removal with worktree_in_use; the walk uses
symlink_metadata, does not follow symlinks and stays inside the task
directory. --force still skips only the ordinary-content checks, and the
non-force path is unchanged.

The design records that the traversal and the recursive deletion both
run under the lock with no time limit.

Fixes #1981
@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

#1986 (review)

Fixed in fe6738f.

The removal step that runs under the ownership mutex now walks every directory in the tree it is about to delete before deleting anything. A .git entry in any form, whether a directory, a gitdir file or a symlink including a dangling one, refuses the whole removal with worktree_in_use. The walk reads entries with symlink_metadata, does not follow symlinks and stays inside the task directory. --force continues to skip only the ordinary-content checks, and the non-force path is unchanged. The design now states that the traversal and the recursive --force deletion both run under the lock with no time limit.

New tests in crates/dim-app-server/tests/transport_flow/worktrees.rs: unregistered_remove_refuses_a_nested_git_directory_even_with_force, unregistered_remove_refuses_a_nested_gitdir_file_even_with_force and unregistered_remove_refuses_a_nested_dangling_git_symlink_even_with_force each assert worktree_in_use with the whole tree intact. unregistered_remove_with_force_deletes_a_deep_tree_without_git_metadata keeps the ordinary deep-tree deletion. The first three fail on 52defcf and pass on this head.

@eric8810 eric8810 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.

Reviewed at head fe6738f.

The head carries 77 commits since the one I read, almost all of it main merged in; this PR's own delta is one addition, and it strengthens the same rule. check_unregistered_tree walks the whole task directory before anything is deleted, refusing when any directory in it holds a .git entry in any form — directory, gitdir file or dangling link — and it reads with symlink_metadata so the walk cannot follow a link out of the task directory. That matches the CLI contract's "no .git entry and empty" more literally than the earlier per-child check: a nested worktree used to be caught (or not) child by child, and is now refused as a whole before the first deletion. My earlier reading of the ordering fix and the store-side second gate still applies unchanged.

verify (linux) and ci-ok failed on this head, outside this PR's path:

crates/dim-app-server/tests/storage_flow.rs:8379
storage_flow::a_slow_store_upgrade_reports_progress_and_keeps_the_opening_alive
  reported progress keeps the opening inside its inactivity bound:
  Build("initialization timed out: SqliteStorage Loading []")
486 passed; 1 failed

That is the store-upgrade opening path, in the inactivity-bound and progress-reporting machinery — the area #1997 and its rutis change touch, not worktree removal. Because 77 commits of main arrived with this head, I cannot tell from here whether this failure came in with main or with this branch; a check against main would settle it. Not approving while a required check is red.

Non-blocking: none.

Verification: not run — I read the worktrees.rs addition, the stat of the delta and the failure message; I did not read the merged main changes or the flow tests behind them.

@yyhhyyyyyy

yyhhyyyyyy commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator Author

#1986 (review)

The same test failure with the same message appears in these runs:

The pages for the two earliest runs are no longer accessible on GitHub; their failure record comes from logs saved at the time, and the test name and message match the other two runs listed.

Each one reports storage_flow::a_slow_store_upgrade_reports_progress_and_keeps_the_opening_alive failing with reported progress keeps the opening inside its inactivity bound: Build("initialization timed out: SqliteStorage Loading []").

The earliest of these runs predates this branch's first commit.

PR #1550 changed only files under crates/dimcode/tests/cli_flow/.

This pull request changes the worktree removal path, its directory-record checks and the store-side method that runs them under the ownership lock, and does not touch the store opening or upgrade path.

@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

The verify (linux) failure in run 44995110416 is the intermittent store-opening failure in app_server_flow, not a result of this pull request. The storage_flow test failed with initialization timed out: SqliteStorage Loading [] during the store format upgrade, and that failure is tracked in #2030.

The same message failed run 45028209559 attempt 1 on a different head and passed on attempt 2 at the same head, which identifies it as intermittent. This pull request's changes are in the worktree removal path and its store operations; they do not change the store opening or upgrade progress reporting.

@yyhhyyyyyy
yyhhyyyyyy requested a review from eric8810 November 23, 2026 17:06

@eric8810 eric8810 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.

Reviewed at head 124d4ba.

This is a data-loss fix, so the thing to check is not that it deletes less but that it decides before it deletes, and it does. remove_unregistered now runs check_unregistered_entry, then sessions_under_workspace on the directory itself, then check_unregistered_children, and only then enters the store's removal operation — where the same three checks run again under the lock and remove_checked_entry deletes nothing that a check has not already passed. Re-checking inside the lock rather than trusting the earlier pass is the right shape for a path where the directory can change between the two.

The checks themselves are written against the ways this goes wrong: symlink_metadata and never a following call, so a symlink is refused rather than walked; a canonical path that must equal the checked path and stay under the managed root; .git refused at any depth in any form — directory, gitdir file, or a dangling link — with the walk refusing to follow links at all; and without --force, every child must be empty, with the verified empty children returned so the deletion acts on that list instead of re-reading the directory. Refusing a Session whose workspace is the task directory or below it, checked once for the directory and again in the store, closes the hole where a per-child check missed a cwd on the directory itself.

cleanup_unregistered_root carries the same discipline for the no-longer-a-worktree case: canonical check, emptiness decided before the delete, and a cancellation check on both sides of it.

Blocking: none.

Checks are green at this head. I read remove_unregistered, check_unregistered_children, check_unregistered_tree, cleanup_unregistered_root and the error taxonomy in worktrees.rs; I did not read the 779 lines of worktrees.rs flow tests, the storage/face.rs and timeline.rs changes that implement remove_unregistered_directory and sessions_under_workspace, or the design deltas, and ran nothing.

Non-blocking: none.

@zerob13 zerob13 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 prior blocking concern is resolved. The final unregistered cleanup now checks the full deletion tree for Git metadata without following symlinks, including on the forced path, after revalidating directory/Session ownership. No-force cleanup remains non-recursive. The exact merge with current main passed Linux (including nested Git directory, gitdir file, dangling link and concurrent ownership coverage), macOS, Windows and ci-ok. Static review and hosted CI only; no destructive local checks.

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.

Worktrees: removing an unregistered task directory without --force deletes ordinary files

3 participants