Skip to content

cleanupWorktree should null ghost fields when the dir is already gone #843

Closed

Description

@currentbits

Summary

cleanupWorktree (electron/worktrees.js) runs git worktree remove and throws if that fails, before it can updateThread({ worktreePath: null, branch: null }). That leaves ghost worktreePath/branch on done threads after the directory was removed outside the app (PR #840 leftover extract, orphan sweep, manual rm). After prune, git reports is not a working tree.

maybeCleanupMergedWorktree already handles the missing-dir case: prune, best-effort branch -D, then null the fields.

Do

  • Treat a missing worktreePath the same way: do not throw, still null worktreePath+branch, do not set pendingWorktree.
  • Add a test next to the existing worktrees tests.
  • Do not change default-branch merge behavior when the dir still exists.

Callers

  • thread_merge → mergeWorktree → cleanupWorktree({ forceRemove: false })
  • git:removeWorktree → removeWorktree → cleanupWorktree({ forceRemove: true })

Follow-up to #841 (six-row store clear that Nightly overwrote).

Activity

  1. currentbits commented on Sep 2, 2026

    @currentbits
    OwnerAuthor

    cleanupWorktree now matches maybeCleanupMergedWorktree when the dir is already gone: prune, best-effort branch -D, then updateThread({ worktreePath: null, branch: null }). Does not set pendingWorktree. Live-dir git worktree remove still throws on failure.

    Test: removeWorktree nulls ghost fields when the worktree dir is already gone in electron/test/worktrees.test.js. RED was Failed to remove worktree: … is not a working tree. worktrees.test.js 64/64 pass; blast-radius rematerialize-then-merge still passes.

  2. added
    plan:done
    and removed
    plan:doing
    on Sep 2, 2026
  3. currentbits commented on Sep 2, 2026

    @currentbits
    OwnerAuthor

    Implementing on coder/fork-fork-fork-solenta-guardrail-deny-as-712b7c: treat a missing worktree dir as already removed in cleanupWorktree, then null worktreePath/branch the same as the success path. Tests first in electron/test/worktree-cleanup.test.js. Not touching live coder-store.json or Application Support worktrees.

  4. currentbits commented on Sep 2, 2026

    @currentbits
    OwnerAuthor

    Implemented on coder/fork-fork-fork-solenta-guardrail-deny-as-712b7c.

    cleanupWorktree now treats a missing directory as already removed: prune, then updateThread({ worktreePath: null, branch: null }) + save(), same as the success path. pendingWorktree is not set. A present dir that git cannot remove still throws.

    Tests in electron/test/worktree-cleanup.test.js (missing dir, present dir, throw when the path is the main checkout). Verified: 3/3 new tests pass; existing removeWorktree tests pass.

    Did not touch live coder-store.json or Application Support worktrees.

  5. currentbits commented on Sep 3, 2026

    @currentbits
    OwnerAuthor

    Audit of how this landed on main (via #850 squash ea85e2be):

    This is the intended #843 fix. It belonged on main. Do not revert.

    What shipped in electron/worktrees.js + electron/test/worktree-cleanup.test.js matches this issue:

    • missing worktreePath is treated as already-removed: prune, then updateThread({ worktreePath: null, branch: null })
    • does not set pendingWorktree
    • a present dir that git cannot remove still throws
    • same missing-dir pattern as maybeCleanupMergedWorktree

    How it got onto main was a leftover worktree merge, not STT work:

    Vehicle was wrong. Content was right. Reverting those two files would re-open the #841/#843 ghost-field bug.

    Verified on this audit: the three #843 tests in electron/test/worktree-cleanup.test.js pass (missing dir, present dir, throw on main checkout).

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

    plan:done

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions