Unified · Split
| @@ -66,9 +66,6 @@ import { · 65 unmodified lines | |||
| 66 | type DrizzleDb, | 66 | type DrizzleDb, |
| 67 | type DbServiceShape, | 67 | type DbServiceShape, |
| 68 | } from "../db/db"; | 68 | } from "../db/db"; |
| 69 | import { makeExecutionStack } from "../engine/execution-stack"; | ||
| 70 | import { preloadQuickJs } from "../quickjs"; | ||
| 71 | import { CloudMeteredExecutionStackLayer } from "../engine/execution-stack-metered"; | ||
| 72 | import { AutumnService } from "../extensions/billing/service"; | 69 | import { AutumnService } from "../extensions/billing/service"; |
| 73 | import { DoTelemetryLive, flushTracerProvider } from "../observability/telemetry"; | 70 | import { DoTelemetryLive, flushTracerProvider } from "../observability/telemetry"; |
| 74 | import { | 71 | import { |
| @@ -242,6 +239,31 @@ export class McpSessionDOSqlite extends McpAgentSessionDOBase<Env, CloudSessionD · 167 unmodified lines | |||
| 242 | ): Effect.Effect<BuiltMcpServer> { | 239 | ): Effect.Effect<BuiltMcpServer> { |
| 243 | const self = this; | 240 | const self = this; |
| 244 | return Effect.gen(function* () { | 241 | return Effect.gen(function* () { |
| 242 | // Imported here rather than at module scope. Cloudflare requires a | ||
| 243 | // Durable Object class to be exported from the Worker entry, so every | ||
| 244 | // static import this module makes is evaluated by *every* cold isolate — | ||
| 245 | // including the ones that only render a page or forward a passthrough | ||
| 246 | // proxy and never open an MCP session. These three roots pull the whole | ||
| 247 | // code-execution stack (sucrase, ajv, QuickJS-WASM): measured at 1.9 MB | ||
| 248 | // of the Worker's startup closure, for code only a real session runs. | ||
| 249 | // `apps/cloud/scripts/start-closure.mjs` reports that number and will | ||
| 250 | // show it moving back if these become static again. | ||
| 251 | const [{ preloadQuickJs }, { makeExecutionStack }, { CloudMeteredExecutionStackLayer }] = | ||
| 252 | yield* Effect.promise( | ||
| 253 | () => | ||
| 254 | Promise.all([ | ||
| 255 | import("../quickjs"), | ||
| 256 | import("../engine/execution-stack"), | ||
| 257 | import("../engine/execution-stack-metered"), | ||
| 258 | ]) as Promise< | ||
| 259 | [ | ||
| 260 | typeof import("../quickjs"), | ||
| 261 | typeof import("../engine/execution-stack"), | ||
| 262 | typeof import("../engine/execution-stack-metered"), | ||
| 263 | ] | ||
| 264 | >, | ||
| 265 | ); | ||
| 266 | |||
| 245 | // QuickJS-WASM must be loaded before anything asks for a sandbox: the | 267 | // QuickJS-WASM must be loaded before anything asks for a sandbox: the |
| 246 | // default variant cannot fetch its own `.wasm` on Workers. Cloud runs | 268 | // default variant cannot fetch its own `.wasm` on Workers. Cloud runs |
| 247 | // user `execute` code on the dynamic-worker runtime, but the artifact | 269 | // user `execute` code on the dynamic-worker runtime, but the artifact |