Skip to content

[bug] Removing a task mirror can force-delete uncommitted agent work: a failed git status is treated as "clean" #73

Closed

Description

@timacek

What happens

The worktree/mirror delete path conflates "git status failed" with "nothing is dirty", then removes
the worktree with --force and rm -rf:

  • src/host/git.ts:362-366 — dirtyLines() returns undefined when git status --porcelain
    fails;
  • src/host/isolation.ts:219 — await git.dirtyLines(target.path).catch(() => undefined) turns a
    throw into the same undefined;
  • src/host/isolation.ts:228 — only defined, non-empty lines count as dirty, so the aggregate
    dirty-mirror refusal at :230-238 never fires;
  • src/host/isolation.ts:250-251 — the root worktree is then removed with force: true;
  • src/host/git.ts:399-412 — removeWorktree's own guard is if (status.ok && dirty) — a failed
    status skips the guard too, so worktree remove --force (:413-415) deletes the directory;
  • src/host/routes.ts:1254-1258 — the delete route then rm -rfs the path as well.

This is exactly the opposite of the documented contract: "refuses uncommitted changes"
(routes.ts:1238), "one dirty repo refuses the WHOLE mirror before anything is deleted"
(isolation.ts:14-16), and "dirty worktrees are kept — never a data-loss primitive"
(execution.ts:1028-1030).

Trigger (realistic)

git status is a quick call with a 2 s timeout (QUICK_TIMEOUT_MS, git.ts:29) and a 4 MB stdout
cap (git.ts:238). The mirror is a fresh checkout, and the execution framing explicitly tells the
agent it may need to install dependencies inside it (execution.ts:1315). A mirror containing
node_modules (tens of thousands of untracked files) can exceed the timeout or the buffer on
Windows; a corrupt index (killed git during add/commit) fails outright. Then:

  1. A worktree-isolated task has uncommitted work.
  2. The user clicks Remove worktree (or a purge/cleanup flow runs).
  3. git status fails inside the mirror → no dirty refusal → worktree remove --force + rm -rf.
  4. The GUI reports success; the agent's uncommitted work is gone.

How I verified it

Reproduced against real git with the plugin's own createGitFace() / removeMirror():

  • control: a dirty root mirror rejects with { code: 'dirty-mirror' } and the file survives;
  • status-failure variant: corrupt the worktree's index → dirtyLines(root) returns undefined →
    removeMirror(...) resolves, the mirror directory is gone, and the work file is gone;
  • at the git level, git worktree remove --force succeeds on a registered worktree whose status
    command now fails.

Environment

  • dsh-taskboard 0.9.7 / dev @ fb97e7f (originally reproduced on 0.9.6 @ 3054eba)
  • DSH 0.2.1-rc.5, Windows 11, git 2.51

Suggested fix

Stop representing "unknown" as clean. Return a sentinel ('unsupported'/'failed') or let
dirtyLines throw, and make removeMirror/removeWorktree refuse with a readable message
("cannot verify worktree status; refusing to delete") instead of forcing. It is better to leave a
mirror behind for a retry than to delete work no one can recover. A regression test can script the
git face's status failure and assert the refusal + surviving directory.

Dedupe

#15 introduced multi-repo mirrors and the 0.6.3 review fixed false dirty refusals; the inverse
(status failure → silent force delete) has no issue. The broken promise is documented in-repo.

Activity

  1. self-assigned this
    on Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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