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`,