fix(host-service): classify missing-worktree git errors as NOT_FOUND instead of 500
Problem
HOST-SERVICE-W (escalating, 16 events/minute on canary 1.18.3-canary.20260805123527): when a workspace's worktree directory no longer exists — deleted externally or a cleanup raced the poll loop — every polled git tRPC endpoint (git.getStatus, git.listCommits, git.listBranches, git.getBranchSyncStatus, ...) constructs simple-git on the missing path, throws GitConstructError: Cannot use simple-git on a directory that does not exist, and escapes as INTERNAL_SERVER_ERROR into Sentry — once per batched procedure per poll.
This is an expected lifecycle state, not a bug, so per the error-handling contract (#6164) it must be classified at the throw site — the dumb 500=report Sentry middleware stays filter-free.
Fix
resolveWorktreePath— the shared boundary everygit.*procedure resolves the workspace path through — now checks the directory exists and throws a typedNOT_FOUNDwith cause{ kind: "WORKTREE_MISSING", worktreePath }, mirroring the desktop v1 changes-router convention. Non-500 → not captured by the Sentry middleware; the renderer already degrades on error results (workspace.getalready exposesworktreeExists).workspace.gitStatus(legacy CLI/SDK surface) had the same hole via a directctx.git(worktreePath); it now routes through the same helper.
Related
DESKTOP-H0 is the same error via the desktop project, but through the desktop v1 changes/workspaces routers. That path is already classified on main (pathExistsCached guard → NOT_FOUND WORKTREE_MISSING, plus GitEnvironmentError → PRECONDITION_FAILED); its remaining events all come from released builds ≤ 1.18.3 whose bundles predate those guards (verified against event stacks), so it drains as users update — no further code change needed.
Refs HOST-SERVICE-W
https://claude.ai/code/session_01JAJWZrVSdXGbsfiGvwCyKW
Summary by cubic
Classified missing workspace worktrees as NOT_FOUND to prevent simple-git construct errors from surfacing as 500s during git polling. This stops Sentry noise (Refs HOST-SERVICE-W) and keeps the UI degrading gracefully.
- Bug Fixes
- Added an existence check in
resolveWorktreePathto throwNOT_FOUNDwith{ kind: "WORKTREE_MISSING", worktreePath }, preventingsimple-gitconstruct errors from escaping as 500s across allgit.*procedures. - Routed
workspace.gitStatusthroughresolveWorktreePathto apply the same guard.
- Added an existence check in
Summary by CodeRabbit
- Bug Fixes
- Improved handling when a workspace worktree is missing.
- Git status requests now return a clear “not found” error instead of failing unexpectedly.
- Added structured error details to help identify missing worktree paths.