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
- 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.
- 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.
- 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).
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 tocleanup_orphans(crates/services/src/worktree.rs).cleanup_orphansrunsgit worktree remove --forceon every directory under~/.tcode/worktrees/<session_id>whose name is not a known session id and whose mtime is older thanORPHAN_MIN_AGE(1 h).Affected paths
delete_session(remove_worktree = false)removes the session record, so on the next launch its worktree directory is an "orphan" and is force-removed.remove_worktree = false(crates/ui/src/settings_page.rs), which the sweep then undoes.worktreeownership 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).