From 9b56cf362b98e29aab6eebbe46b6c43e304d02d7 Mon Sep 17 00:00:00 2001 From: mawkone Date: Fri, 12 Jun 2026 15:36:35 -0700 Subject: [PATCH] fix(preview): remove brittle dev server readiness probes; trust that the server will eventually boot --- vibn-frontend/app/api/mcp/route.ts | 21 ++++++++----------- .../[projectId]/dev-server/ensure/route.ts | 12 +++++++++-- vibn-frontend/lib/dev-container.ts | 2 +- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/vibn-frontend/app/api/mcp/route.ts b/vibn-frontend/app/api/mcp/route.ts index 56e93e47..f3679b1c 100644 --- a/vibn-frontend/app/api/mcp/route.ts +++ b/vibn-frontend/app/api/mcp/route.ts @@ -5311,20 +5311,17 @@ async function toolDevServerStart( workspace: principal.workspace, }); - // Instead of firing-and-forgetting, we now wait for the server to ACTUALLY - // spin up and serve HTTP traffic before we return success to the AI. - // This allows the AI to see the exact health check failure synchronously. - let isHealthy = false; + // We mark it healthy immediately. Webpack compiles are taking too long + // on cold boots and causing the probe to fail and the AI to retry endlessly. + // The Traefik router will hold the connection open for the user until it responds. + let isHealthy = true; let failureOutput = ""; - try { - await probeDevServerReadiness(project.id, row.id, row.port); - isHealthy = true; - } catch (probeErr: any) { - isHealthy = false; - failureOutput = probeErr.message || String(probeErr); - console.error("[dev_server.start] Synchronous probe failed:", probeErr); - } + // We still fire the probe in the background so it eventually logs if it fails, + // but we don't await it. + probeDevServerReadiness(project.id, row.id, row.port).catch((err) => { + console.error("[dev_server.start] Async probe failed later:", err); + }); if (!isHealthy) { let recentLogs = ""; diff --git a/vibn-frontend/app/api/projects/[projectId]/dev-server/ensure/route.ts b/vibn-frontend/app/api/projects/[projectId]/dev-server/ensure/route.ts index 0df92f29..4e0c7d7b 100644 --- a/vibn-frontend/app/api/projects/[projectId]/dev-server/ensure/route.ts +++ b/vibn-frontend/app/api/projects/[projectId]/dev-server/ensure/route.ts @@ -134,8 +134,16 @@ export async function POST( workspace, }); const row = await startDevServer(restartOpts); - // Run the readiness probe in background so state transitions - // from 'starting' → 'running' (or 'failed') in the DB. + + // We immediately set it to running instead of waiting for the probe. + // The probe has been flaky on Webpack cold compiles and causing the + // frontend to get stuck in a "Preview not running" loop. + await query(`UPDATE fs_dev_servers SET state = 'running' WHERE id = $1`, [ + row.id, + ]); + + // Still run the probe in the background just to log any catastrophic failures, + // but the UI won't be blocked by it. probeDevServerReadiness(project.id, row.id, row.port).catch((err) => { console.error("[dev-server/ensure] probe failed:", err?.message); }); diff --git a/vibn-frontend/lib/dev-container.ts b/vibn-frontend/lib/dev-container.ts index 66824f9f..8808a9c5 100644 --- a/vibn-frontend/lib/dev-container.ts +++ b/vibn-frontend/lib/dev-container.ts @@ -760,7 +760,7 @@ export async function probeDevServerReadiness( `for i in $(seq 1 300); do ` + `for path in / ''; do ` + `code=$(curl -sS -o /dev/null -w '%{http_code}' --max-time 2 --connect-timeout 2 ` + - `"http://127.0.0.1:${port}$path" 2>/dev/null || printf '000'); ` + + `"http://localhost:${port}$path" 2>/dev/null || curl -sS -o /dev/null -w '%{http_code}' --max-time 2 --connect-timeout 2 "http://0.0.0.0:${port}$path" 2>/dev/null || printf '000'); ` + `last_code=$code; ` + `[ "$code" != "000" ] && [ -n "$code" ] && exit 0; ` + `done; ` +