fix(host-service): report GitHub being unreachable as unavailable, not a 500

Merged
SA
2mo ago
+22-0

Problem

When the host cannot reach GitHub at all (no route to host, DNS failure, refused or timed-out connection), workspaceCreation.searchPullRequests and searchGithubIssues fail with an INTERNAL_SERVER_ERROR. The Sentry middleware treats every remaining 500 as a host-service bug, so each offline moment opens a new Sentry issue (the GitHub IP and errno are in the title, so they don't group): HOST-SERVICE-74, -60, -4N, -40 are all this.

Root cause

githubRequestError is the throw-site classifier for these two procedures. It maps rate limits to TOO_MANY_REQUESTS and rejected credentials to UNAUTHORIZED, but has no case for transport failures. The error Octokit throws is a RequestError with status 500 whose cause chain is TypeError("fetch failed") → a socket error with code: "EHOSTUNREACH" (verified in @octokit/request 10.0.13 fetchWrapper: requestError.cause = error), so it fell through untouched.

Fix

Reuse the host's existing isGitHubUnreachableError (the same classifier the PR runtime's availability gate uses; it walks the cause chain for Node/undici transport codes and gh's network stderr) and return SERVICE_UNAVAILABLE with a plain message. Real GitHub responses — 5xx, validation errors, anything else — still pass through and still report.

Side effect

The desktop's shared QueryClient retries SERVICE_UNAVAILABLE up to 3 times (hostServiceQueryRetry, 700/1400/2100 ms), because it reads that code as the host restarting. An unreachable-GitHub search is now retried too. For a fast failure (no route, DNS, refused) the error appears about 4s later. For a connect timeout, each attempt already waits on the gh and Octokit timeouts, so the error can take several times longer to show. The cloud-API path (rethrowCloudUnreachable) already accepts this trade-off.

Verification

  • New test fails on main, passes with the change:
    • before: (fail) githubRequestError > an Octokit request that never reached GitHub is unavailable, not a 500 — 26 pass, 1 fail
    • after: bun test src/trpc/router/workspace-creation → 208 pass, 0 fail, 378 expect() calls
  • Existing negative test anything else passes through untouched (a validation error) still passes.
  • bunx biome check on both files → Checked 2 files. No fixes applied.
  • cd packages/host-service && bun run typecheck → clean.

Refs HOST-SERVICE-74