Skip to content

Commit f55ae1a

Browse files
fix(daemon): self-review fixes for sandbox 503 gate
Two issues found reviewing the previous commit: 1. A permanently-failed env (e.g. no dev.ts) would now return 503 and loop the activator forever, since the env can never become ready. Restore the original 424 for that case via isWorkerDisabled(); only a still-booting worker gets 503. 2. The optional warmup request went through the same 5s gate, so it was 503'd before it could JIT-compile/render the entry route — defeating its purpose. Warmup requests (x-deco-warmup header) now bypass the gate and block until the worker is fully ready, like normal mode. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 27c029d commit f55ae1a

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

daemon/worker.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,12 @@ export const createWorker = (optionsProvider: WorkerOptionsProvider) => {
105105
// ensure isolate is up and running
106106
app.use("/*", async (c, next) => {
107107
try {
108-
if (SANDBOX_MODE) {
108+
// Warmup requests (and normal, non-sandbox mode) keep the original
109+
// blocking behavior: wait for the worker to be fully ready, then proxy.
110+
// This is what lets the warmup request actually JIT-compile and render
111+
// the entry route — a fast-503 gate would skip the render entirely.
112+
const isWarmup = c.req.header("x-deco-warmup") === "1";
113+
if (SANDBOX_MODE && !isWarmup) {
109114
// worker() boots the dev server (idempotent) and resolves once it is
110115
// listening. On a cold sandbox that can take a while; rather than hold
111116
// the request open the whole time — which lets the CDN time out as a
@@ -119,6 +124,15 @@ export const createWorker = (optionsProvider: WorkerOptionsProvider) => {
119124
delay(SANDBOX_READY_GATE_MS).then(() => false),
120125
]);
121126
if (!isReady) {
127+
// A permanent init failure (e.g. no dev.ts) keeps returning 424 as
128+
// before: bouncing it to the activator would loop forever, since the
129+
// env can never become ready. Only a still-booting worker gets 503.
130+
if (isWorkerDisabled()) {
131+
c.res = new Response(`Error while starting worker`, {
132+
status: 424,
133+
});
134+
return;
135+
}
122136
c.res = new Response("Sandbox environment is starting", {
123137
status: 503,
124138
headers: { "retry-after": "2" },

0 commit comments

Comments
 (0)