fix(host-service,cli): repair workspaces whose worktree moved (#6791)
Problem
A workspace record pins its worktree by absolute path. After git worktree move (a supported git operation) git stays healthy but Superset's copy of the path goes stale: workspaces get reports worktreeExists: false, terminals fail with WORKTREE_GONE, and nothing in workspaces update could re-point it. The only recoveries were moving the worktree back or deleting and recreating the workspace (losing task links and terminal history).
Fix
- Auto repair on open.
workspace.get(what the desktop workspace page andworkspaces gethit) now callsrepairMovedWorktree: when the stored path no longer exists and the row is aworktreeworkspace, it lists the project's worktrees via a new off-loopgit/listWorktreesworker task (built on the sharedparseWorktreeList), finds the one on the workspace's branch, updates the row, and logs a warning. - Explicit repair.
workspace.updateacceptsworktreePath; the path must exist, be a worktree of the project's repo, and be on the workspace's branch (main workspaces are rejected). Surfaced assuperset workspaces update <id> --worktree-path <path>, in the SDKWorkspaceUpdateParams, and in the CLI reference docs.
Verified
packages/host-service/src/workspaces/moved-worktree.test.ts: real temp repo +git worktree add/move/remove; 9 cases covering repair, no-op when present, no-op when removed, main workspaces untouched, and each validation rejection. The repair case fails when the repair is disabled.bun run typecheckin host-service, cli, sdk.no-main-loop-blocking.test.tspasses (git runs in the worker pool, no newctx.gitsites).bun test src/workers,src/commands/workspacespass.
Not in this PR: the terminal-create path still checks existsSync directly (it repairs once the workspace has been fetched), and the two secondary findings in the issue thread (cleanup skipping git worktree remove on a stale path; recreate hard-deleting the old row) are left for follow-ups.
Fixes #6791
https://claude.ai/code/session_011XQusXtWEwq2nxN4jfMUpv
Summary by cubic
Repairs workspaces whose Git worktree was moved so they open normally and terminals stop failing. Previously, moving a worktree left the workspace pinned to a stale absolute path; now we auto-repair on fetch/open and allow explicit re-pointing.
- Auto repair on fetch/open:
workspace.getinhost-servicelists project worktrees via the off-loopgit/listWorktreestask, finds the matching branch, and updates the storedworktreePath(logs a warning; main workspaces are untouched). - Explicit repair:
workspace.updateacceptsworktreePath; surfaced assuperset workspaces update <id> --worktree-path <path>incliandWorkspaceUpdateParams.worktreePathinsdk. Validates that the path exists, is a worktree of the project, and matches the workspace branch. - Docs/tests: CLI reference updated; added
moved-worktree.test.tscovering repair, no-ops, and all validation rejections. Git runs in the worker pool, avoiding main-loop blocking.
Summary by CodeRabbit
-
New Features
- Added a
--worktree-pathoption to update a workspace’s project worktree location. - Automatically repairs workspace paths after a Git worktree is moved, when the branch can be matched.
- Validates that the specified path exists, belongs to the project, and matches the workspace branch.
- Added a
-
Bug Fixes
- Improved workspace retrieval to recover from relocated worktrees while preserving valid workspace records.