| 409 | |
| 410 | /** Probe the unauthenticated Executor health endpoint without disclosing the saved bearer. */ |
| 411 | const isDaemonReachable = async (origin: string): Promise<boolean> => { |
| 412 | for (let attempt = 0; attempt < 3; attempt += 1) { |
| 413 | const controller = new AbortController(); |
| 414 | const timer = setTimeout(() => controller.abort(), 1500); |
| 415 | // oxlint-disable-next-line executor/no-try-catch-or-throw -- boundary: fetch rejects on a down server; that's the "not reachable" signal |
| 416 | try { |
| 417 | const response = await fetch(new URL("/api/health", origin), { |
| 418 | signal: controller.signal, |
| 419 | redirect: "manual", |
| 420 | }); |
| 421 | const body = await response.text(); |
| 422 | if (response.ok && body.trim() === "ok") return true; |
| 423 | } catch { |
| 424 | // retry below |
| 425 | } finally { |
| 426 | clearTimeout(timer); |
| 427 | } |
| 428 | if (attempt < 2) await delay(150); |
| 429 | } |
| 430 | return false; |
| 431 | }; |
| 432 | |
| 433 | /** |
| 434 | * Attach to an already-running OS-supervised daemon instead of spawning our own |