Skip to content

refactor(cli): web-standard (Request) => Response runtime core; Node listener becomes an adapter (deploy-anywhere B1) - #373

Merged
blove merged 9 commits into
mainfrom
feat/web-standard-request-core
Aug 4, 2026
Merged

blove merged 9 commits into
mainfrom
feat/web-standard-request-core

Conversation

@blove

@blove blove commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Web-standard request core (deploy-anywhere B1)

Dawn's served runtime was welded to node:http — handlers typed (IncomingMessage, ServerResponse) => void, responses written through Node sinks. That blocks the edge build targets (Cloudflare Workers / Vercel / Hono) of the deploy-anywhere epic, whose runtimes speak Web-standard fetch.

This extracts a transport-agnostic createRuntimeFetchHandler(options) → (request: Request) => Promise<Response> core (exported from @dawn-ai/cli/runtime) and reimplements the Node listener as a thin adapter over it. Zero behavior change — dawn dev, dawn start, and serveRuntime keep their exact signatures and wire behavior.

What changed

  • Core (runtime-fetch-handler.ts): the boot assembly, route table, shutdown state, and drain logic, returning Web Responses. JSON via Response.json; the three SSE sites (AP stream, resume, AG-UI) via ReadableStream — the pure string encoders (toSseEvent, encodeAgUiSse) untouched. In-flight accounting transfers to the stream's completion paths so close() never releases sandboxes mid-stream, with a bounded drain deadline.
  • Adapter (node-web-adapter.ts): IncomingMessage → Request (socket close aborts request.signal; streaming body with duplex: "half") and Response → ServerResponse (JSON keeps Content-Length framing; SSE streams incrementally; getSetCookie preserved; stream errors tear the socket down rather than framing truncation as success).
  • Harness (@dawn-ai/testing): injectAgentProtocol drives the fetch core directly; light-my-request removed from the dependency tree.

The safety invariant, held

Every pre-existing test passes unchanged (445-test baseline → 467 → 472 with the new coverage; zero edits to existing tests). An adversarial review of the flip — reproducing findings over raw sockets — caught 7 wire-parity regressions the suite couldn't see, all fixed with regression tests:
JSON responses silently switching to chunked framing; AG-UI mid-stream errors terminating as clean success; two activeRequests leak paths that could hang close() and leak sandboxes; empty/bogus Host killing the connection; middleware rejects with 204/304 becoming 500s; repeated set-cookie dropped for middleware; and AP stream/resume gaining abort-on-disconnect the old server never had (reverted to parity; the semantic question is a deliberate follow-up).

Verification

  • Socket-level lanes green: verify:harness:runtime (real dev-server parity) + verify:harness:smoke.
  • Full monorepo suite: 1319 passed / 0 failed; typecheck, lint, check-docs, pack-check clean.
  • Manual streaming proof on a real socket: a run with a 1.5s tool shows the tool-call SSE event arriving at +172ms with the stream closing at +1695ms — first event 1.5s before completion, no buffering, first-token latency preserved.

Changeset: patch (@dawn-ai/cli, @dawn-ai/testing). Next in the epic: B2 (build-time static wiring — kill per-request readdir + tsx-loader dependence), then B3 (the Workers/Vercel/Hono targets with per-target capability gating).

🤖 Generated with Claude Code

@vercel

vercel Bot commented Aug 4, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dawnai Ready Ready Preview Aug 4, 2026 9:26pm

Request Review

@github-actions

github-actions Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @blove's task in 0s —— View job


I'll analyze this and get back to you.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated approval: this PR received an intelligent (AI) code review. See the review comments on this PR.

@blove
blove merged commit df54695 into main Aug 4, 2026
14 checks passed
@blove
blove deleted the feat/web-standard-request-core branch August 4, 2026 21:37
blove added a commit that referenced this pull request Sep 17, 2026
…00 (#711)

`statusResponse` built every middleware reject with `Response.json(body)`, which throws when `body` is `undefined`. The documented body-omitted form of `reject(status)` therefore answered 500 "Unexpected runtime server failure" instead of the 401 or 403 the app asked for, on the AG-UI and both Agent Protocol run endpoints. A body-less reject now sends an empty payload under the JSON content-type at the requested status.

On the Node targets, body-less replies are now framed with `Content-Length: 0` rather than `Transfer-Encoding: chunked`, restoring the pre-`fetch`-core framing and extending the adapter's existing content-length rule for JSON to empty payloads. The statuses that forbid a body (204, 205, 304) keep Node's own suppression.

Regressed in #373. A separate live instance of the same bug class, on the route-output path, is filed as #714.

Merged with admin: the required `validate` check is green, and the advisory `review` check failed only because the org's Anthropic credit balance is exhausted. An independent review stood in for it and caught the chunked-framing defect above.

This branch was successfully deployed

1 active deployment
Preview — 7d3d1c27 Deployed Aug 4, 2026 by vercel[bot]
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