Skip to content

fix(host-service): classify missing cloud project in setup as NOT_FOUND - #6433

Merged
saddlepaddle merged 1 commit into
mainfrom
sentry/hs-project-setup-notfound
Aug 13, 2026
Merged

saddlepaddle merged 1 commit into
mainfrom
sentry/hs-project-setup-notfound

Conversation

@saddlepaddle

@saddlepaddle saddlepaddle commented Aug 13, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

project.setup files a steady trickle of INTERNAL_SERVER_ERROR reports (HOST-SERVICE-16, 14 events lifetime, 2 in the last 24h, release 1.20.2). The captured stack contains only tRPC client transport frames (TRPCClientError.from), which is why the first-party site was hard to place from the event alone; the trpc_path tag project.setup is what identifies it.

Root cause

Setting a project up on a device falls back to a cloud lookup when the project is neither already in the local host database nor accompanied by caller-supplied origin coordinates:

const cloudProject =
  existing || input.origin
    ? null
    : await ctx.api.v2Project.get.query({ organizationId: ctx.organizationId, id: input.projectId });

When the cloud has no such project — the ordinary outcome for a project deleted cloud-side, or for an older client trying to adopt one it cannot see — upstream v2Project.get rejects NOT_FOUND ("Project not found") via requireOrgScopedResource. Nothing at this boundary caught it, so the rejection propagated out of the mutation and the Sentry middleware, which reports every INTERNAL_SERVER_ERROR reaching it, filed it as a bug. This is an expected domain state, not a bug, so the missing classification belongs at the throw site.

Fix

Wrap that one upstream call in fetchCloudProjectForSetup. An upstream not-found is rethrown as a typed TRPCError with code NOT_FOUND and cause { kind: "CLOUD_PROJECT_NOT_FOUND" }, so the Sentry middleware never sees a 500. Everything else — network failures, cloud 5xx, auth errors — propagates untouched and keeps reporting.

Detection is a name check (error.name === "TRPCClientError"), not instanceof: errors arriving from the upstream client cross a bundle boundary and lose their prototype. The not-found condition matches the structured data.code, falling back to a message check only when no structured code is present. The upstream message text is preserved verbatim, so user-facing copy is unchanged. Behaviour is otherwise identical — this is a classification change only.

No Sentry-side suppression, no beforeSend filter, no middleware allowlist.

Verification

bunx biome check packages/host-service/src/trpc/router/project/project.ts:

Checked 1 file in 11ms. No fixes applied.

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

$ tsc --noEmit --emitDeclarationOnly false

bun test src/trpc/router/project/project-import.test.ts (existing tests over the touched router):

bun test v1.3.14 (0d9b296a)

 3 pass
 0 fail
 16 expect() calls
Ran 3 tests across 1 file. [1159.00ms]

Refs HOST-SERVICE-16

https://claude.ai/code/session_70334aac-77cb-4a5f-86c0-8cd388bf20a0


Summary by cubic

Classifies a missing cloud project during setup as NOT_FOUND instead of INTERNAL_SERVER_ERROR, reducing Sentry noise and returning a typed not-found to clients. Old behavior: unhandled upstream NOT_FOUND bubbled as 500. New behavior: TRPCError with code NOT_FOUND and cause { kind: "CLOUD_PROJECT_NOT_FOUND" }. No user-facing copy change.

  • Wrap the cloud lookup in fetchCloudProjectForSetup in packages/host-service, rethrowing a typed NOT_FOUND.
  • Detect upstream not-found via error.name === "TRPCClientError" and data.code === "NOT_FOUND", with a message fallback; preserve upstream message.
  • Scope: only the setup path when the project is not in the local DB and no origin is provided. Network/auth/5xx still propagate and report.

Written for commit 1b6e978. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of missing cloud projects during legacy setup lookups.
    • Missing projects are now consistently reported as “Not Found,” while unrelated errors continue to be surfaced unchanged.

@coderabbitai

coderabbitai Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: bf34f894-d9c8-455a-ac69-5f1daa7f6758

📥 Commits

Reviewing files that changed from the base of the PR and between a8390a7 and 1b6e978.

📒 Files selected for processing (1)
  • packages/host-service/src/trpc/router/project/project.ts

📝 Walkthrough

Walkthrough

The setup procedure now uses a cloud project lookup helper. The helper maps cross-bundle tRPC not-found errors to structured NOT_FOUND errors and rethrows other failures unchanged.

Changes

Cloud project lookup

Layer / File(s) Summary
Setup cloud lookup and error mapping
packages/host-service/src/trpc/router/project/project.ts
Adds typed context and not-found cause handling. The helper detects cross-bundle tRPC not-found errors, maps them to NOT_FOUND, and preserves other failures. setup uses the helper when cloud access is required.

Estimated code review effort: 2 (Simple) | ~10 minutes

Mergeability Score: ⚪ Minimal · up to 1b6e9

The change narrowly classifies missing cloud projects as NOT_FOUND while preserving other failures; no actionable merge-blocking risk remains beyond normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant Setup as setup
  participant Lookup as fetchCloudProjectForSetup
  participant Cloud as Cloud API
  Setup->>Lookup: Request cloud project
  Lookup->>Cloud: Query project
  Cloud-->>Lookup: Return project or tRPC error
  Lookup-->>Setup: Return project or NOT_FOUND error
Loading

Possibly related PRs

Suggested reviewers: kitenite

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title uses conventional commit format and clearly describes the missing cloud project classification change.
Description check ✅ Passed The description explains the problem, root cause, fix, scope, and verification results; the required content is mostly complete despite omitting the checklist.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sentry/hs-project-setup-notfound

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ✅ Neon database branch

Thank you for your contribution! 🎉

@saddlepaddle
saddlepaddle merged commit 6f2b59f into main Aug 13, 2026
19 checks passed
@saddlepaddle
saddlepaddle deleted the sentry/hs-project-setup-notfound branch August 22, 2026 22:26

This branch was previously deployed

1 inactive deployment
preview — 1b6e978b Deployed Aug 13, 2026 by saddlepaddle via Deploy Admin #7659
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant