Defer worker startup imports in apps/cloud - #2068
Draft
RhysSullivan wants to merge 1 commit into
Draft
RhysSullivan wants to merge 1 commit into
RhysSullivan wants to merge 1 commit into
Conversation
Move the Start server entry, the MCP agent handler, the execution rate-limit counter DO and the WorkOS events cron runner behind dynamic imports so a cold isolate only evaluates what the path it serves needs. Record executor.dispatch.graph_import_ms on worker.dispatch. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
executor-marketing | 1dc1175 | Commit Preview URL Branch Preview URL |
Sep 18 2026, 07:46 PM |
Contributor
Cloudflare preview
Sign-in is Cloudflare Access (one-time PIN to an allowed email). The preview has its own database and encryption key; it is destroyed when this PR closes. |
@executor-js/cli
@executor-js/config
@executor-js/execution
@executor-js/sdk
@executor-js/codemode-core
@executor-js/runtime-quickjs
@executor-js/plugin-file-secrets
@executor-js/plugin-graphql
@executor-js/plugin-keychain
@executor-js/plugin-mcp
@executor-js/plugin-onepassword
@executor-js/plugin-openapi
executor
commit: |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
executor-cloud | 1dc1175 | Sep 18 2026, 07:47 PM |
This branch has not been 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.
Four static edges out of the Worker entry are now dynamic imports, memoized per isolate, so a cold isolate evaluates only the code the path it is about to serve needs:
@tanstack/react-start/server-entry— loaded insidefetchHandler. An isolate serving only/apior/mcpnever evaluates react-dom or the router.markStartGraphEntered()still runs synchronously on entry, so the flag means the same thing.makeCloudMcpAgentHandler— built on the first/mcprequest.ExecutionRateLimiterDO— Cloudflare requires a DO class as a top-level export, so the export is now a thinDurableObjectshim that imports the real two-method counter and delegatesincrementandalarmto an instance built from the same ctx/env, memoized per DO instance.runWorkOsEventsSync— imported insidescheduled.McpSessionDOSqliteis deliberately left static. The same shim pattern would have to forward partyserver'ssetNameplus roughly fifteen@internalRPC methods the agents SDK calls straight on the stub, andstreamable-httpbridges through a hibernatable WebSocket into the DO. A missed or newly added method fails at the call site in production, and stub calls are dynamic so nothing catches it at build time. It is worth 1.05 MB, measured; the reasoning is in a comment at the export.Also on
worker.dispatch:executor.dispatch.graph_import_ms, measured aroundgetAppPlane(). workerd freezesDate.now()until the first real I/O, so a cold app-plane dispatch performs one throwawaycaches.default.matchfirst — otherwise the measurement reads 0 and the cold graph cost lands on whatever span straddles the next I/O (the Sep 2026 investigation mis-attributed it toworkos.session.local_verify). Warm dispatches skip it.scripts/start-closure.mjsneeded a fix: the Start server entry is now itself a dynamic chunk, which put Start's own lazyloadEntriesimports one hop further from the entry. Both hops are followed now.Closure (
node apps/cloud/scripts/start-closure.mjs apps/cloud/dist/server)Verified with
bun run --cwd apps/cloud typecheck,src/app-paths.test.ts,src/engine/execution-rate-limit.node.test.ts,src/api.request-scope.node.test.ts, and a production build. Not deployed.