Unified · Split
| @@ -103,12 +103,36 @@ export { McpExecutionOwnerDirectoryDO } from "@executor-js/cloudflare/mcp/execut · 102 unmodified lines | ||
| 103 | 103 | // until the in-flight export resolves. |
| 104 | 104 | // --------------------------------------------------------------------------- |
| 105 | 105 | |
| 106 | −const fetchHandler = handler.fetch as ( | |
| 106 | +const rawFetchHandler = handler.fetch as ( | |
| 107 | 107 | request: Request, |
| 108 | 108 | env: Env, |
| 109 | 109 | ctx: ExecutionContext, |
| 110 | 110 | ) => Response | Promise<Response>; |
| 111 | 111 | |
| 112 | +// TEMPORARY: does an isolate that already warmed still pay for Start? | |
| 113 | +let startEverHandled = false; | |
| 114 | +const fetchHandler = async ( | |
| 115 | + request: Request, | |
| 116 | + env: Env, | |
| 117 | + ctx: ExecutionContext, | |
| 118 | +): Promise<Response> => { | |
| 119 | + const wasWarm = startEverHandled; | |
| 120 | + startEverHandled = true; | |
| 121 | + await scheduler.wait(0); | |
| 122 | + const startedAt = Date.now(); | |
| 123 | + const response = await rawFetchHandler(request, env, ctx); | |
| 124 | + await scheduler.wait(0); | |
| 125 | + console.log( | |
| 126 | + JSON.stringify({ | |
| 127 | + probe: "start", | |
| 128 | + path: new URL(request.url).pathname, | |
| 129 | + wasWarm, | |
| 130 | + ms: Date.now() - startedAt, | |
| 131 | + }), | |
| 132 | + ); | |
| 133 | + return response; | |
| 134 | +}; | |
| 135 | + | |
| 112 | 136 | const tracer = trace.getTracer("executor-cloud-worker"); |
| 113 | 137 | |
| 114 | 138 | const traceparentValueFor = (spanContext: SpanContext): string => |
| @@ -220,6 +244,7 @@ const warmStartGraph = (env: Env, ctx: ExecutionContext): void => { · 105 unmodified lines | ||
| 220 | 244 | |
| 221 | 245 | ctx.waitUntil( |
| 222 | 246 | (async () => { |
| 247 | + const startedAt = Date.now(); | |
| 223 | 248 | // oxlint-disable-next-line executor/no-try-catch-or-throw -- adapter boundary; a warmup failure must never affect the request that triggered it |
| 224 | 249 | try { |
| 225 | 250 | await fetchHandler( |
| @@ -227,9 +252,18 @@ const warmStartGraph = (env: Env, ctx: ExecutionContext): void => { · 1 unmodified line | ||
| 227 | 252 | env, |
| 228 | 253 | ctx, |
| 229 | 254 | ); |
| 230 | − } catch { | |
| 255 | + console.log(JSON.stringify({ probe: "warm", ok: true, ms: Date.now() - startedAt })); | |
| 256 | + } catch (err) { | |
| 231 | 257 | // Advisory only — the request path still loads the graph lazily. |
| 232 | 258 | startGraphWarmupStarted = false; |
| 259 | + console.log( | |
| 260 | + JSON.stringify({ | |
| 261 | + probe: "warm", | |
| 262 | + ok: false, | |
| 263 | + ms: Date.now() - startedAt, | |
| 264 | + err: String(err), | |
| 265 | + }), | |
| 266 | + ); | |
| 233 | 267 | } |
| 234 | 268 | })(), |
| 235 | 269 | ); |