Description
Deleting a session fails with the following error:
Delete failed
Failed to delete session: git ["--no-optional-locks", "status", "--porcelain=v1", "-b", "-M", "-uall"] failed: fatal: not a git repository (or any of the parent directories): .git
Root cause (confirmed via local investigation)
Each session record in session-store.db stores a cwd path. For sessions created from background-agent tasks, this cwd points to a disposable per-task Git worktree under:
~/.copilot/repos/copilot-worktrees/<repo-name>/<random-worktree-name>/
Once the background task finishes, the worktree folder is often removed (either by the user, by app cleanup, or by the worktree lifecycle itself), but the corresponding row in sessions is not always cleaned up in sync. When the user later tries to delete that now-orphaned session, the app runs git status against the recorded cwd to build session context before deleting it. Since the directory either:
- no longer exists at all, or
- still exists but its
.git was removed,
git status fails with fatal: not a git repository, and this failure is surfaced as a hard error that blocks session deletion entirely, instead of being treated as a non-fatal condition.
Evidence
Inspecting a read-only copy of session-store.db, out of 1181 total sessions:
- 194 sessions reference a
cwd directory that no longer exists on disk.
- 47 sessions reference a
cwd directory that still exists, but its .git is missing.
All of the above 241 sessions are tied to ephemeral worktrees created for background-agent tasks (e.g. ~/.copilot/repos/copilot-worktrees/<repo>/chboeye-microsoft-<random-name>/), confirming these are orphaned worktree references, not a corrupted main repository. The main project repo and all currently-existing worktrees have valid .git directories and git status runs fine on them.
Impact
Any session whose worktree has since been deleted becomes permanently un-deletable through the UI, since the delete action itself depends on a successful git status call.
Expected behavior
Session deletion should not depend on the target directory still being a valid Git repository. If git status fails because the directory is missing or is no longer a Git repo, the app should:
- Skip/ignore the Git status check for a deletion action, and/or
- Fall back gracefully (e.g., treat as "no git context") instead of throwing a fatal error, and
- Still allow the session record to be deleted from the database.
Environment
- OS: Windows
- Affected: session deletion for sessions created via background-agent worktrees
Description
Deleting a session fails with the following error:
Root cause (confirmed via local investigation)
Each session record in
session-store.dbstores acwdpath. For sessions created from background-agent tasks, thiscwdpoints to a disposable per-task Git worktree under:Once the background task finishes, the worktree folder is often removed (either by the user, by app cleanup, or by the worktree lifecycle itself), but the corresponding row in
sessionsis not always cleaned up in sync. When the user later tries to delete that now-orphaned session, the app runsgit statusagainst the recordedcwdto build session context before deleting it. Since the directory either:.gitwas removed,git statusfails withfatal: not a git repository, and this failure is surfaced as a hard error that blocks session deletion entirely, instead of being treated as a non-fatal condition.Evidence
Inspecting a read-only copy of
session-store.db, out of 1181 total sessions:cwddirectory that no longer exists on disk.cwddirectory that still exists, but its.gitis missing.All of the above 241 sessions are tied to ephemeral worktrees created for background-agent tasks (e.g.
~/.copilot/repos/copilot-worktrees/<repo>/chboeye-microsoft-<random-name>/), confirming these are orphaned worktree references, not a corrupted main repository. The main project repo and all currently-existing worktrees have valid.gitdirectories andgit statusruns fine on them.Impact
Any session whose worktree has since been deleted becomes permanently un-deletable through the UI, since the delete action itself depends on a successful
git statuscall.Expected behavior
Session deletion should not depend on the target directory still being a valid Git repository. If
git statusfails because the directory is missing or is no longer a Git repo, the app should:Environment