Repository navigation
Task/vercel handler resilience - #1548
Merged
greatest0fallt1me merged 14 commits intoOct 21, 2026
Merged
Conversation
added 14 commits
October 21, 2026 14:26
…e or client missing
|
@emarkees Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
4 tasks
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.
fix(vercel): Recover from failed demo bootstraps in the Vercel handler and smoke-test the built bundle in CI
Closes #1516
Summary
Hardens the Vercel serverless deployment entrypoint against cold-start concurrency races, uninitialized / transient database connection failures, and SQLite demo migration syntax incompatibilities. Additionally fixes Vercel bundling artifacts, prevents the Express server from opening duplicate local listeners when imported by the serverless wrapper, and integrates a pre-deployment CI bundle smoke test.
Problem
timestamptz,BYTEA,DEFAULT NOW(),gen_random_uuid()), breaking demo runs.scripts/vercel-entry.tsimported the compiled application (dist/index.js),require.main === modulechecks could falsely triggerapp.listen()inside the serverless runtime.scripts/build-vercel.mjsstrippedenginesand critical dependencies from.vercel/output/functions/index.func/package.json, risking Node engine mismatch on Vercel.src/routes/index.tshad a nested property bug (config.creditsRateLimit.billingRateLimit) that threw at runtime.Changes
1. Vercel Handler Resilience & Self-Healing (
scripts/vercel-entry.ts)ensureDatabaseReady()with bounded exponential backoff (up to 3 retries, configurable delay).503 Service UnavailablewithSERVICE_INITIALIZINGerror envelope rather than crashing the Lambda.2. Demo SQLite Migration & Seeding Fixes (
src/db/demo.ts)isPostgresMigration), safely skipping PostgreSQL migrations on SQLite while still tracking them in_prisma_migrations.timestamptz->TEXT,BYTEA->BLOB,gen_random_uuid()-> hex string) for SQLite compatibility.ON CONFLICT DO NOTHING/ pre-existence checks) to preventUNIQUE constraint failederrors on retries.3. Server Direct Execution Guard (
src/index.ts)checkDirectExecution(mainModule, currentModule, isVercel)helper.app.listen()from firing whenprocess.env.VERCEL === '1'or when imported by serverless handlers.4. Prisma Fallback & Envelope Standardization (
src/lib/prisma.ts,src/errors/errorEnvelopePolicy.ts)SERVICE_INITIALIZINGunder public error codes and allowed error types.5. Build & CI Smoke Testing (
scripts/build-vercel.mjs,scripts/smoke-vercel-bundle.mjs,.github/workflows/ci.yml)enginesand runtime dependencies in Vercel function outputpackage.json.smoke-vercel-bundle.mjsscript that builds the Vercel output and tests handler cold-start against/healthzand demo endpoints.6. OpenAPI & Route Fixes (
docs/openapi.json,src/routes/index.ts)SuccessEnvelopeandBillingHistoryRowschemas undercomponents.schemasto pass OpenAPI schema validation.config.creditsRateLimit.billingRateLimittoconfig.billingRateLimit.Commits
feat(errors): add SERVICE_INITIALIZING to public error codesfix(server): export checkDirectExecution to prevent listening on Vercel bundle importtest(server): add unit tests for checkDirectExecution mode detectionfix(prisma): return 503 service unavailable envelope when in demo mode or client missingfix(routes): correct billingRateLimit configuration property accessfix(demo): skip postgres-only migrations and make catalog seeding idempotenttest(demo): add unit tests for migration dialect detection and idempotent seedingbuild(vercel): preserve engines and dependencies in deployment package.jsonfix(vercel): add self-healing database initialization and sync error handlingtest(vercel): add unit tests for vercel entrypoint cold-start and backofftest(smoke): add smoke test script for bundled vercel deploymentci: add vercel bundle smoke test step to build pipelinedocs(openapi): add SuccessEnvelope and BillingHistoryRow component schemasdocs: document self-healing vercel handler and ci smoke testVerification
npm run error-codes:checkpassed cleanly.npm run validate:openapipassed cleanly.scripts/vercel-entry.test.ts,src/db/demo.test.ts,src/__tests__/directExecution.test.ts).npm run build:vercelsuccessfully built.vercel/output.node scripts/smoke-vercel-bundle.mjspassed end-to-end against bundled handler.