fix(host-service): classify missing-worktree git errors as NOT_FOUND instead of 500

Merged
SA
3mo ago
+14-12

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 every git.* procedure resolves the workspace path through — now checks the directory exists and throws a typed NOT_FOUND with 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.get already exposes worktreeExists).
  • workspace.gitStatus (legacy CLI/SDK surface) had the same hole via a direct ctx.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 resolveWorktreePath to throw NOT_FOUND with { kind: "WORKTREE_MISSING", worktreePath }, preventing simple-git construct errors from escaping as 500s across all git.* procedures.
    • Routed workspace.gitStatus through resolveWorktreePath to apply the same guard.

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.