INNER CODE UNIT · TypeScript
proxyAliveOnce
JuliusBrussee/caveman · packages/pi-extension/src/index.ts:87
async function proxyAliveOnce(gateway: string, instanceToken: string): Promise<boolean> {
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), HEALTH_TIMEOUT_MS);
try {
const response = await fetch(`${gateway.replace(/\/+$/, "")}/health/live`, { signal: controller.signal, redirect: "error" });
await response.body?.cancel();
return response.ok && response.headers.get("x-caveman-instance") === instanceToken;
} catch {
return false;
} finally {
clearTimeout(timer);
}
}
// A proxy the SessionStart hook just autostarted may be a few hundred ms behind
// the first probe; retry briefly before declaring the session direct.
async function readLiveRunState(gateway: string): Promise<RunState | undefined> {
for (let attempt = 0; attempt < 3; attempt++) {