From 27a1f308d09b2e21aca337b89a3a61d1f81c0978 Mon Sep 17 00:00:00 2001 From: mawkone Date: Fri, 12 Jun 2026 15:05:24 -0700 Subject: [PATCH] fix(preview): add 60-second grace period before zombie killer murders booting dev servers throwing 504s --- .../app/api/projects/[projectId]/anatomy/route.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/vibn-frontend/app/api/projects/[projectId]/anatomy/route.ts b/vibn-frontend/app/api/projects/[projectId]/anatomy/route.ts index a906ca6..917b867 100644 --- a/vibn-frontend/app/api/projects/[projectId]/anatomy/route.ts +++ b/vibn-frontend/app/api/projects/[projectId]/anatomy/route.ts @@ -825,8 +825,17 @@ async function loadPreviews(projectId: string): Promise { ping.status === 504 || ping.status === 404 ) { + // GRACE PERIOD: If the server was started less than 60 seconds ago, + // Traefik might return a 502/504 simply because the Node process hasn't + // finished booting and binding to the port yet. Do not kill it! + const ageMs = Date.now() - new Date(r.started_at).getTime(); + if (ageMs < 60_000) { + activePreviews.push(r); // Give it the benefit of the doubt + return; + } + console.warn( - `[anatomy] Preview zombie detected for ${r.preview_url} (HTTP ${ping.status}). Marking stopped.`, + `[anatomy] Preview zombie detected for ${r.preview_url} (HTTP ${ping.status}, age ${Math.round(ageMs / 1000)}s). Marking stopped.`, ); await query( `UPDATE fs_dev_servers SET state = 'stopped' WHERE id = $1`,