Skip to content

Interrupted git worktree remove leaves a registered dirty checkout with tracked deletions #1302

Description

@chubes4

Problem

git worktree remove is not transactional. If DMC cleanup times out or is interrupted while Git is deleting files, the handle stays registered and the checkout is left with mass tracked deletions.

Observed on static-site-importer@fix-1397-release-profile:

  • DMC metadata: lifecycle_state=cleanup_eligible, cleanup_policy=remove_on_success, liveness=stopped / lifecycle_finalized
  • Git still lists the worktree; .git marker still points at the primary worktree admin dir
  • Working tree has 34 tracked deletions (LICENSE, tools/*, bench/*, blocks/importer/*, …) and zero modifications/untracked files
  • Inventory still reports the handle (dirty: 34, stale: dirty)

remove_worktree_by_path() in inc/Workspace/WorkspaceWorktreeCleanupEngine.php already distinguishes:

  • Git error + directory gone → treat as partial success and drop metadata (filesystem_removed_git_metadata_failed)
  • Git error + directory still present → return the error and leave the checkout as-is

A timed-out git worktree remove hits the second branch after files have already been deleted. The next apply then skips the row as dirty unless --force is used.

Expected

  • Interrupted/timed-out remove is either completed or rolled back to a complete checkout before metadata is left in place.
  • A registered worktree is never left with only tracked deletions from a failed remove.
  • Retry is idempotent: complete the remove if the handle is still cleanup-eligible and the only dirt is those deletions, or restore from HEAD and skip without --force.
  • Evidence names the incomplete-remove state (remove_incomplete / remove_timeout) instead of generic dirty.

Reproduction

  1. Mark a populated worktree cleanup_eligible with remove_on_success.
  2. Start bounded cleanup-eligible apply with a removal timeout short enough to kill git worktree remove mid-delete.
  3. Observe the directory still present, git status showing only tracked deletions, and inventory still listing the handle.

Related

AI assistance

xAI grok-4.6 via OpenCode inspected the live static-site-importer@fix-1397-release-profile git/DMC state and WorkspaceWorktreeCleanupEngine::remove_worktree_by_path, then drafted this issue. Chris Huber directed the investigation. No code was changed in this repo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions