Skip to content

feat: v1 api freeze#230

Closed
pi0x wants to merge 1 commit into
mainfrom
feat/v1-api-freeze
Closed

feat: v1 api freeze#230
pi0x wants to merge 1 commit into
mainfrom
feat/v1-api-freeze

Conversation

@pi0x

@pi0x pi0x commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

API stabilization batch for v1. All breaking-shaped changes land together.

  • F8 (breaking-shaped): wire errorPlugin on the Bun and Deno adapters so the error option runs on every adapter; docs section renamed onError -> error to match the real option.
  • F9 (breaking-shaped): remove the unimplemented gracefulShutdown.forceTimeout type; fix the falsy check so gracefulTimeout: 0 is honored; document gracefulShutdown (unit is seconds, default 5, SERVER_SHUTDOWN_TIMEOUT env var).
  • F10 (breaking-shaped): standardize Server.serve() on Promise<Server<Handler>>; adapters that returned void now return Promise.resolve(this).
  • F11: drop @experimental from toFetchHandler / fetchNodeHandler (stable/frozen at v1); srvx/tracing stays experimental.
  • F17 (breaking-shaped): NodeResponse now throws (like native Response) for a non-null body with a null-body status (101/204/205/304) instead of emitting an illegal body + content-length.
  • F26 / F18 (breaking-shaped): Bun/Deno serve() never throws; listen errors (e.g. EADDRINUSE) surface via ready(), matching Node. If ready() is never awaited, the error is re-surfaced as an unhandled rejection (Node's default handler reports it) rather than leaving a live process with a dead server.
  • F51: lazily initialize request.context (??= {}) once in shared code so request.context.x = ... works on every adapter.
  • F52 (breaking-shaped): remove the unused, any-typed netlify / stormkit / vercel runtime context keys (removal after v1 would itself be breaking).
  • D6: keep ServerPlugin return type sync-only (void), not widened to Promise<void> | void.

Adds node-adapter tests for each behavioral change (error runs, gracefulTimeout: 0 honored, serve() returns a Promise<Server>, NodeResponse throws on null-body-status + body, ready() rejects on EADDRINUSE, request.context works). Bun/Deno-only behaviors are covered by the existing bun/deno suites.

Verified: pnpm vitest run --exclude '**/{deno,bun}*.test.ts' test/ (860 passed / 32 skipped), pnpm lint, pnpm typecheck all green.

🤖 Generated with Claude Code

Breaking-shaped API stabilization landing together for v1:

- F8: wire `errorPlugin` on the Bun and Deno adapters so the `error` option runs on every adapter; rename the docs section `onError` -> `error`.
- F9: drop the unimplemented `gracefulShutdown.forceTimeout` type; honor `gracefulTimeout: 0` (use nullish check, not `||`); document `gracefulShutdown` (seconds, default 5, `SERVER_SHUTDOWN_TIMEOUT`).
- F10: standardize `Server.serve()` on `Promise<Server<Handler>>`; void-returning adapters now `Promise.resolve(this)`.
- F11: drop `@experimental` from `toFetchHandler` / `fetchNodeHandler` (frozen at v1); `srvx/tracing` stays experimental.
- F17: `NodeResponse` throws (like native `Response`) for a non-null body with a null-body status (101/204/205/304).
- F26/F18: Bun/Deno `serve()` never throws; listen errors (EADDRINUSE) surface via `ready()`, matching Node. If `ready()` is never awaited, the error is re-surfaced as an unhandled rejection instead of leaving a dead server.
- F51: lazily initialize `request.context` once in shared code so `request.context.x = ...` works everywhere.
- F52: remove the unused `netlify` / `stormkit` / `vercel` runtime context keys.
- D6: keep `ServerPlugin` return type sync-only (`void`).

Adds node-adapter tests for each behavioral change.

Co-Authored-By: Claude Fable 5 <[email protected]>
@pi0x
pi0x requested a review from pi0 as a code owner July 14, 2026 11:28
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@pi0x, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 48 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 53b58d1b-6738-41fc-9b25-d42be18bb513

📥 Commits

Reviewing files that changed from the base of the PR and between f2edab1 and b0fe471.

📒 Files selected for processing (17)
  • docs/1.guide/5.options.md
  • src/_middleware.ts
  • src/_plugins.ts
  • src/_utils.ts
  • src/adapters/_node/adapter.ts
  • src/adapters/_node/response.ts
  • src/adapters/_node/web/fetch.ts
  • src/adapters/aws-lambda.ts
  • src/adapters/bun.ts
  • src/adapters/bunny.ts
  • src/adapters/cloudflare.ts
  • src/adapters/deno.ts
  • src/adapters/generic.ts
  • src/adapters/node.ts
  • src/adapters/service-worker.ts
  • src/types.ts
  • test/v1-api-freeze.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/v1-api-freeze

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.

@pkg-pr-new

pkg-pr-new Bot commented Jul 14, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/srvx@230

commit: b0fe471

@pi0x pi0x mentioned this pull request Jul 14, 2026

@pi0x pi0x left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent review — v1 API freeze (PR #230)

Verdict: Approve (with one minor follow-up). Every locked hard spec is correctly implemented and I verified each one end-to-end (unit tests + manual EADDRINUSE/null-body repros run on Node, Bun and Deno). Full suite is green: 923 passed | 35 skipped, no type errors. The single failing test in a fresh checkout (test/loader.test.ts) is purely environmental — it needs a built dist/ for the import("srvx/node") self-import and passes after pnpm build; loader.ts is untouched by this PR.

Per-finding compliance checklist

Finding Status Evidence
F8/D2 — option stays error, actually wired on every adapter PASS errorPlugin(this) runs in node/bun/deno/cloudflare/aws-lambda/generic/bunny/service-worker, always before wrapFetch. Verified a thrown handler is caught and mapped (500 "handled: boom"). Docs 5.options.md rewritten ### onError### error; body-limit cross-ref updated. (The remaining onError at 5.options.md:263 is Deno's native deno.onError option — correct.)
F9/D3 — seconds, 0 honoured, forceTimeout deleted, documented PASS* _plugins.ts:27 uses == null not `
F10serve(): Promise<Server<Handler>> PASS types.ts:280 narrowed; every void adapter returns Promise.resolve(this) / Promise.resolve().then(() => this).
F11/D5 — drop @experimental on toFetchHandler/fetchNodeHandler; tracing stays experimental PASS Tags removed from _node/adapter.ts + _node/web/fetch.ts; @experimental remains only on src/tracing.ts.
D6ServerPlugin stays sync void PASS types.ts:47 (server: Server) => void, not widened.
F17NodeResponse throws for body + null-body status PASS Throws for 101/204/205/304 whenever body != null (covers strings and streams). Matches native Response (confirmed empty-string and stream bodies both throw natively).
F18 — unawaited ready() still surfaces listen error PASS reportUnhandledListenError re-surfaces via a deferred unhandled rejection unless ready() claimed it. Repro: second server on a busy port, ready() never awaited → EADDRINUSE surfaced loudly (Node exits 1; Bun prints), not swallowed.
F26serve() never throws, ready() rejects (Bun+Deno) PASS Bun.serve/Deno.serve wrapped; verified on both runtimes: serve() did not throw synchronously, ready() rejected (EADDRINUSE / AddrInUse). No spurious unhandled rejection when ready() is awaited. Knock-on checked: CLI (cli/serve.ts:81) and all docs/examples read server.url only after await ready() — no sync server.url regressions.
F51request.context lazy-init in shared code PASS ??= {} lives once in wrapFetch (both branches), which every adapter routes through. req.context.user = "alice" works (verified); native Bun/Deno Requests are extensible so assignment succeeds there too.
F52 — remove netlify/stormkit/vercel any-typed keys PASS Removed from ServerRuntimeContext; no dangling references in src/.

Findings

Minor — SERVER_SHUTDOWN_TIMEOUT=0 env var is silently ignored (docs/behavior mismatch). src/_plugins.ts:28Number.parseInt(process.env.SERVER_SHUTDOWN_TIMEOUT || "") || 5. The || 5 is the exact falsy bug F9 fixed for the option, still present on the env path: SERVER_SHUTDOWN_TIMEOUT=0 resolves to 5, not 0. The docs this PR adds say the timeout "can also be set via the SERVER_SHUTDOWN_TIMEOUT environment variable" and "Set it to 0 to force close immediately", so a user setting 0 via env gets a 5s wait instead. Suggest const env = process.env.SERVER_SHUTDOWN_TIMEOUT; const fallback = env == null || env === "" ? 5 : Number.parseInt(env); (or apply the same ?? / == null guard). Not blocking — the primary option path is correct.

Info — PR branch is stale. Base is f2edab1; main is now d8523dc (#225/#227/#228/#234 landed since). Everything applies cleanly and tests pass, but a rebase before merge is advisable so CI runs against current main.

Info (out of scope, flagging for the freeze) — docs/1.guide/3.server.md:40-48 still documents server.addr / server.port, which don't exist on Server or any adapter. That's F54 (Docs scope, not this PR), but it's semver-adjacent doc debt worth clearing before the freeze tag.

Nice touch: the added test/v1-api-freeze.test.ts covers error-wiring, lazy context, promise return, EADDRINUSE-via-ready, null-body throw, and the gracefulTimeout: 0 regression directly — good behavioral (not just type) coverage that pins these decisions.

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.

2 participants