Skip to content

Startup orphan sweep force-removes worktrees the user chose to keep #516

Description

@Tryanks

Summary

The startup orphan-worktree sweep force-removes worktrees that the user explicitly chose to keep, losing any uncommitted work in them.

Where

  • recover_orphaned_worktrees (crates/runtime/src/app/sessions.rs) passes the ids of loaded sessions to cleanup_orphans (crates/services/src/worktree.rs).
  • cleanup_orphans runs git worktree remove --force on every directory under ~/.tcode/worktrees/<session_id> whose name is not a known session id and whose mtime is older than ORPHAN_MIN_AGE (1 h).

Affected paths

  1. Delete with "Keep worktree". delete_session(remove_worktree = false) removes the session record, so on the next launch its worktree directory is an "orphan" and is force-removed.
  2. Every delete from Settings. Settings → Archived Threads → Delete and Delete all always pass remove_worktree = false (crates/ui/src/settings_page.rs), which the sweep then undoes.
  3. Forks living in a deleted source's worktree. A fork shares the source's cwd but deliberately has no worktree ownership marker; the directory is named after the source id, so once the source is deleted the fork's working directory is removed while the fork still exists.

The tcode/<id> branch survives; uncommitted changes do not.

Found by reading the code; not reproduced.

Expected

"Keep" means kept. The sweep should treat a directory as known if any session's cwd is inside it, and should honour an explicit keep record for deleted sessions. Ownership belongs on the host (#530).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions