fix: use readiness endpoint for health checks instead of port check

The waitForHealth function now checks /api/readiness which returns 503
until background initialization completes, rather than just checking if
the port is in use. This ensures callers wait for full worker readiness.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Alex Newman
2025-12-26 20:56:14 -05:00
parent def01790ea
commit 84a23450c8
2 changed files with 42 additions and 35 deletions
File diff suppressed because one or more lines are too long
+8 -1
View File
@@ -61,7 +61,14 @@ async function isPortInUse(port: number): Promise<boolean> {
async function waitForHealth(port: number, timeoutMs: number = 30000): Promise<boolean> {
const start = Date.now();
while (Date.now() - start < timeoutMs) {
if (await isPortInUse(port)) return true;
try {
const response = await fetch(`http://127.0.0.1:${port}/api/readiness`, {
signal: AbortSignal.timeout(2000)
});
if (response.ok) return true;
} catch {
// Not ready yet
}
await new Promise(r => setTimeout(r, 500));
}
return false;