Repository navigation
perf(web): load sign-in and email code only when a developer API request needs it - #4229
Merged
Merged
Conversation
added 2 commits
November 13, 2026 11:44
The developer API and hosted MCP routes imported next-auth, SSO and the React Email templates at module load through three static paths: the Hono auth helpers, the web-backend Auth service, and the Infra billing emails. Every cold start evaluated them although only cookie-authenticated requests and billing emails use them. Import them where they are used instead.
Member
Author
|
@greptileai review |
|
Sandchest reviewed Sandchest reviews every change for vulnerabilities an attacker could use · Review details |
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Member
Author
|
@greptileai review |
Member
Author
|
@greptileai review |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What
The developer API (
/api/developer/v1/[...route]) and the hosted MCP route (/api/developer/mcp) loaded sign-in and email code at module load. That code is next-auth, SSO (WorkOS), nodemailer, Resend and the React Email templates. Three static imports pulled it in:apps/web/app/api/utils.tsimportedgetCurrentUserfrom@cap/database/auth/sessionfor the cookie branch ofgetAuth.packages/web-backend/src/Auth.tsimportedgetServerSessionfrom@cap/database/auth/auth-optionsfor the session branch ofgetCurrentUser.apps/web/lib/infra-billing-emails.tsimportedsendEmailand the two Infra email templates at the top.Each now imports the module where it is used, so it loads on the first request or email that needs it. Behaviour is unchanged: the same functions run with the same arguments in the same order. Cookie-authenticated routes load the session module on their first request instead of at startup.
Why
A cold start evaluates every module in the route's static import graph. Secret-key and upload-token requests never use the session or email code. Measured on a local bundle of the route, built with code splitting as Next.js does:
On the preview deployment of this branch:
/v1/usagewith no key returns 401, an unknown secret key returns 401invalid_secret_key, and the MCP route returns 401.GET /api/developer/credits/transactions(HonowithAuth, cookie branch) andDELETE /api/video/delete(HttpAuthMiddleware, session branch) return the same 401 status and body on the preview as on production, not a 500.Tests
__tests__/unit/developer-api-cold-path.test.tsbundles both routes with esbuild and walks the static import graph. It fails on main with the import chain (route.ts -> app.ts -> api/utils.ts -> auth/session.ts -> next-auth) and passes here.share-stage-identityfailures that are the same on main under Node 26. The repo typecheck (bun run typecheck) and Biome pass.

Confidence Score: 5/5
The PR appears safe to merge; no new actionable issues were found.Summary
This PR loads sign-in and billing email code only when a request needs it.
No new actionable issues were found. Tests were not run during this review.
Reviews (3) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile