fix(host-service): classify missing project directory as NOT_FOUND in workspace-creation git procedures

Merged
KI
3mo ago
+33-7

Problem

Sentry HOST-SERVICE-W (40 events on 1.20.1, regressed): when a project's main repo directory has been deleted or moved outside the app, workspaceCreation.searchBranches (and siblings) construct a simple-git instance on localProject.repoPath without checking the directory exists. simple-git's constructor throws its GitConstructError ("cannot use simple-git on a directory that does not exist"), which escapes as an INTERNAL_SERVER_ERROR 500 on every branch-search batch.

Root cause

PR #6199 classified this family for the worktree-scoped git.* procedures via the shared resolve-worktree.ts boundary, but the workspace-creation procedures construct git directly on the project repoPath and were left out — so the issue regressed on the 1.20.1 release that ships #6199.

Fix

Mirror #6199 at the workspace-creation layer: one shared guard, requireProjectRepoPath() in shared/local-project.ts, that checks existsSync(repoPath) before git construction and throws a typed NOT_FOUND TRPCError with cause { kind: "PROJECT_DIR_MISSING", repoPath }. Applied at the three procedures that construct git on the project repo path:

  • searchBranches (the failing frame)
  • listProjectWorktrees
  • adopt (guarded before ensureMainWorkspace so no workspace row is created for a missing directory)

Behavior is unchanged — the operation still fails when the directory is gone — only the classification changes from an unexpected 500 to a routine typed NOT_FOUND. Genuine unexpected git failures on these paths still surface as 500s.

Verification

bunx biome check on the four changed files:

Checked 4 files in 11ms. No fixes applied.

cd packages/host-service && bun run typecheck:

$ tsc --noEmit --emitDeclarationOnly false

(exited clean, no errors)

No existing tests cover the touched files, so no test run applied.

Refs HOST-SERVICE-W

https://claude.ai/code/session_fb644a69-16aa-40f3-974b-fe2757d6255c


Summary by cubic

Classifies missing project repo directories as NOT_FOUND in workspace-creation git procedures to stop 500s from simple-git constructor errors. Aligns workspace-creation paths with the worktree handlers and reduces HOST-SERVICE-W noise. (Linear: HOST-SERVICE-W)

  • Bug Fixes
    • Added requireProjectRepoPath() to check existsSync(repoPath) and throw a typed TRPCError with cause { kind: "PROJECT_DIR_MISSING", repoPath }.
    • Applied to searchBranches, listProjectWorktrees, and adopt (before ensureMainWorkspace).
    • Behavior unchanged; only error classification changes from 500 to NOT_FOUND. Unexpected git errors still surface as 500s.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of missing or invalid local repository paths during workspace creation.
    • Users now receive a clear “not found” error instead of an unexpected filesystem error.
    • Repository operations, including branch search and worktree listing, now validate paths before proceeding.