Forward docs and PostHog proxies before loading the Start graph - #1678
Merged
Conversation
Both are pure passthroughs to an external origin — they never touch the router, React, or the Effect app — but they lived in Start's request middleware, so each paid Start's lazy loadEntries import of the whole server graph before it could forward. Measured in production by timing the two costs apart on a cold isolate: the graph import is p50 3.1s while the request's own work is p50 33ms. Essentially every request is cold — worker.dispatch ran 1,666 requests across 1,608 isolates — because /mcp dispatches before fetchHandler and so never warms the graph. A /docs page took 3-6s through the Worker against 0.098s straight from the upstream. Move matching and forwarding into edge/passthrough.ts, which imports neither Start nor any app module, and dispatch it from the Worker entry next to marketing. The middleware wrappers stay registered and now source their matching from the same module, so local dev is unchanged and the two cannot drift. Also reverts the temporary latency probes from server.ts.
Contributor
Cloudflare previewTorn down — the PR is closed. |
RhysSullivan
added a commit
that referenced
this pull request
Aug 19, 2026
#1690) Reverts 0b1739b. Restores the SDK v1 stack and the Cloudflare Agents McpAgent bridge for /mcp. Dependent work is reverted with it, since it patched code that only exists under the v2 stack: the dead-session negative cache (#1627) and its tests, and the standalone-listener/keepalive changes (#1622, #1629, #1632) that live in the deleted v2 modules. Kept on top of the revert: the passthrough proxies at the Worker entry (#1678), version stamping and dispatch spans (#1664), and MCP request tracing, rewired through traceCloudMcpRequest since the v1 handler takes no traceRequest option. Dependencies: agents is pinned to 0.17.3 so patchedDependencies applies (a floating ^0.17.3 resolved to 0.17.4 and silently dropped the patch). bun.lock is reconciled from main rather than reverted wholesale, which otherwise split ajv across 8.18/8.20 and broke codemode-core typecheck.
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 this fixes
/docsand the PostHog proxy are pure passthroughs — they forward to an external origin and never touch the router, React, or the Effect app. But they lived in Start's request middleware, so each one paid Start's lazyloadEntriesimport of the entire server graph before it could forward a request.The measurement
Timing the two costs apart on a cold isolate, in production:
loadEntries)And essentially every request is cold:
worker.dispatchran 1,666 requests across 1,608 isolates (1.04 req/isolate)./mcpdispatches beforefetchHandler, so MCP traffic — the large majority — creates and occupies isolates without ever warming the graph. Page and proxy requests then land on isolates that have only served MCP.Concretely: a
/docspage took 3-6s through the Worker against 0.098s fetched straight from the upstream.The change
edge/passthrough.tsholds the matching, upstream construction, and the docs client span. It imports neither@tanstack/react-startnor any app module — that import is the cost it exists to avoid — andserver.tsdispatches it at the Worker entry, next to marketing (#1637), which is the same seam for the same reason.The
docsProxyMiddleware/posthogProxyMiddlewarewrappers stay registered and now source their matching from that module. In the deployed Worker they are unreachable; on any host that reaches Start by another entry (local dev) behavior is unchanged, and the two paths cannot drift.A test asserts the import boundary directly, since violating it would keep the behavior correct and silently restore the 3.1s.
Also reverts the temporary latency probes (#1670-#1677) from
server.ts.What this does NOT fix
The signed-in app itself. Document and
/api/*requests genuinely need Start, so they still pay ~3.1s on a cold isolate. Two things remain, and I'd treat them as separate:Verification
format,lint(0 errors),typecheck(44/44)apps/cloudvitest: 280 passed, including 6 new cases covering matching,/api/docsnot being shadowed, cookie stripping, ingest-vs-assets splitting, and the import boundary