Skip to content

fix(server): recreate missing worktree on bootstrap - #197

Merged
patroza merged 3 commits into
fork/changesfrom
fix/recreate-missing-worktree
Jul 30, 2026
Merged

fix(server): recreate missing worktree on bootstrap#197
patroza merged 3 commits into
fork/changesfrom
fix/recreate-missing-worktree

Conversation

@patroza

@patroza patroza commented Jul 30, 2026

Copy link
Copy Markdown
Owner

Summary

  • When bootstrap prepares a worktree for an existing thread, check whether worktreePath still exists on disk.
  • If the directory is gone (GC of orphan/stale trees, manual cleanup, disk recovery) but the thread still has a branch, re-run git worktree add <same-path> <branch> and re-run setup (post-checkout / pnpm).
  • If the path still exists, keep the previous reuse-and-skip-setup behavior.

This pairs with worktree GC that strips reflinked node_modules and removes orphans: reactivating a cleaned thread should not require manual git worktree add.

Test plan

  • Thread with existing on-disk worktree: bootstrap still reuses path (no second add).
  • Thread with worktreePath recorded but directory removed: bootstrap re-creates at the same path, setup runs, agent can start.
  • Fresh thread create path unchanged.

@patroza
patroza enabled auto-merge July 30, 2026 08:09
@patroza

patroza commented Jul 30, 2026

Copy link
Copy Markdown
Owner Author

Fixed CI: switched path existence check from node:fs/promises to Effect FileSystem.exists (local server typecheck + vp check green). Pre-existing local web @pierre/diffs type errors are unrelated to this tip.

github-actions Bot added 3 commits July 30, 2026 10:52
When a thread already has worktreePath/branch but the directory was
removed (disk GC or manual cleanup), re-run git worktree add at the
same path for the existing branch and re-run setup instead of assuming
the tree is still on disk.
node:fs/promises trips effect(nodeBuiltinImport) in the server typecheck
gate. Match the rest of the codebase with FileSystem.exists.
The replay-reuse test used a non-existent worktree path; after exists()
checks that path no longer short-circuited prepareWorktree and hit an
unmocked fetchRemote. Create a real temp dir for reuse, and add a
missing-path recreate case.
@patroza
patroza force-pushed the fix/recreate-missing-worktree branch from d0e566c to cdde25d Compare July 30, 2026 08:52
@patroza
patroza disabled auto-merge July 30, 2026 09:18
@patroza
patroza merged commit c9ec043 into fork/changes Jul 30, 2026
10 checks passed
patroza added a commit that referenced this pull request Jul 30, 2026
* fix(server): recreate missing worktree on bootstrap

When a thread already has worktreePath/branch but the directory was
removed (disk GC or manual cleanup), re-run git worktree add at the
same path for the existing branch and re-run setup instead of assuming
the tree is still on disk.

* fix(server): use Effect FileSystem for worktree path check

node:fs/promises trips effect(nodeBuiltinImport) in the server typecheck
gate. Match the rest of the codebase with FileSystem.exists.

* test(server): fix bootstrap worktree reuse and cover recreate

The replay-reuse test used a non-existent worktree path; after exists()
checks that path no longer short-circuited prepareWorktree and hit an
unmocked fetchRemote. Create a real temp dir for reuse, and add a
missing-path recreate case.

---------

Co-authored-by: T3 Code PR Stack <41898282+github-actions[bot]@users.noreply.github.com>
patroza added a commit that referenced this pull request Jul 30, 2026
* fix(server): recreate missing worktree on bootstrap

When a thread already has worktreePath/branch but the directory was
removed (disk GC or manual cleanup), re-run git worktree add at the
same path for the existing branch and re-run setup instead of assuming
the tree is still on disk.

* fix(server): use Effect FileSystem for worktree path check

node:fs/promises trips effect(nodeBuiltinImport) in the server typecheck
gate. Match the rest of the codebase with FileSystem.exists.

* test(server): fix bootstrap worktree reuse and cover recreate

The replay-reuse test used a non-existent worktree path; after exists()
checks that path no longer short-circuited prepareWorktree and hit an
unmocked fetchRemote. Create a real temp dir for reuse, and add a
missing-path recreate case.

---------

Co-authored-by: T3 Code PR Stack <41898282+github-actions[bot]@users.noreply.github.com>
patroza added a commit that referenced this pull request Jul 31, 2026
* fix(server): recreate missing worktree on bootstrap

When a thread already has worktreePath/branch but the directory was
removed (disk GC or manual cleanup), re-run git worktree add at the
same path for the existing branch and re-run setup instead of assuming
the tree is still on disk.

* fix(server): use Effect FileSystem for worktree path check

node:fs/promises trips effect(nodeBuiltinImport) in the server typecheck
gate. Match the rest of the codebase with FileSystem.exists.

* test(server): fix bootstrap worktree reuse and cover recreate

The replay-reuse test used a non-existent worktree path; after exists()
checks that path no longer short-circuited prepareWorktree and hit an
unmocked fetchRemote. Create a real temp dir for reuse, and add a
missing-path recreate case.

---------

Co-authored-by: T3 Code PR Stack <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant