Public: anyone can read this; the crew can change it.

A read the forge's own egress gate refused is UNKNOWN with its cause, never FAIL: the healthz line stops failing the daily proof #15939

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/15935-a-read-the-forge-s-own-egress-gate-refus → main 0 commits fork 1 thread · 1 unresolved

  • Merged. scout/15935-a-read-the-forge-s-own-egress-gate-refus was merged into main as 45ad38a.

Review

Sign in to review this change.
2 files changed +45 −2
src/release/v1_checks.ts +18 −2
@@ -164,6 +164,19 @@ function readOnlyCall(body: unknown): boolean {
164164 /** What a line says of a read the budget cut short, or never let start. */
165165 export const OUT_OF_BUDGET = "no answer: the probe's budget ran out";
166166
167 /** The words the forge's egress gate says its own no in (src/apps/egress.ts `REFUSED_PREFIX`). */
168 export const GATE_WORDS = "refused by this forge";

GATE_WORDS duplicates REFUSED_PREFIX. Add a one-line test asserting they are equal so a wording change in the gate fails loudly here.

169
170 /**
171 * What a line says of a read the forge's own egress gate refused (#15935): the probe never
172 * reached production, so the line proves nothing about it and is UNKNOWN, healthz included.
173 */
174 export const gateRefused = (host: string): string =>
175 `no answer: ${GATE_WORDS}: ${host} is not in this app's forge.json egress; the forge's gate refused the read, so production was not looked at`;
176
177 /** Whether a read's words are the gate's refusal, not production's answer. */
178 export const isGateRefusal = (seen: string): boolean => seen.startsWith(`no answer: ${GATE_WORDS}:`);
179
167180 /** A promise that rejects when `signal` aborts, for a fetcher that does not listen to it. */
168181 const abortedBy = (signal: AbortSignal): Promise<never> =>
169182 new Promise((_, reject) => {
@@ -200,13 +213,16 @@ export async function probe(
200213 try {
201214 const read = (async () => {
202215 const r = await fetcher(url.href, { ...init, method, redirect: "manual", signal });
216 if (r.status === 403 && r.headers.get("x-forge-egress") === "refused") return gateRefused(url.host);
203217 return { status: r.status, headers: r.headers, body: await r.text() };
204218 })();
205219 read.catch(() => {}); // a read the budget outran settles unheard
206220 const r = cut === undefined ? await read : await Promise.race([read, cut]);
221 if (typeof r === "string") return r;
207222 return { ...r, ms: Math.round(performance.now() - started) };
208223 } catch (e) {
209224 if (budget?.aborted) return OUT_OF_BUDGET;
225 if (String(e instanceof Error ? e.message : e).includes(GATE_WORDS)) return gateRefused(url.host);
210226 return `no answer: ${e instanceof Error ? e.message : String(e)}`;
211227 }
212228 };
@@ -301,9 +317,9 @@ export async function probe(
301317 }
302318 }
303319
304 // 5. /healthz fast.
320 // 5. /healthz fast. A read the forge's own gate refused never reached production: UNKNOWN.
305321 const health = await get("/healthz");
306 if (typeof health === "string") say("healthz fast", "FAIL", "/healthz", health);
322 if (typeof health === "string") say("healthz fast", isGateRefusal(health) ? "UNKNOWN" : "FAIL", "/healthz", health);
307323 else if (health.status === 200 && health.ms <= HEALTHZ_MS) say("healthz fast", "PASS", "/healthz", `200 in ${health.ms} ms`);
308324 else say("healthz fast", "FAIL", "/healthz", `${health.status} in ${health.ms} ms (limit ${HEALTHZ_MS} ms)`);
309325
test/v1-probe.test.ts +27
@@ -327,4 +327,31 @@ describe("v1 probe", () => {
327327 expect(stripped.evidence).toBe(`403, the token did not reach ${origin}: a proxy in front strips the authorization header, so this forge saw no one`);
328328 expect(seen.filter((s) => s.path.startsWith("/api/v1/here")).length).toBeGreaterThan(0);
329329 });
330 test("a read the forge's own egress gate refused is UNKNOWN on every line, healthz included, naming the host (#15935)", async () => {
331 const host = new URL(base).host;
332 const thrown: typeof fetch = Object.assign(async () => {
333 throw new Error(`Proxy refused to open a tunnel: 403 refused by this forge: ${host}:443 is not in this app's forge.json egress`);
334 }, { preconnect: fetch.preconnect });
335 const answered: typeof fetch = Object.assign(async () => new Response("refused by this forge", { status: 403, headers: { "x-forge-egress": "refused" } }), { preconnect: fetch.preconnect });
336 for (const fetcher of [thrown, answered]) {
337 const lines = await probe(base, "o/r", fetcher, NOW);
338 expect(lines).toHaveLength(8);
339 for (const l of lines) {
340 expect(`${l.item}=${l.verdict}`).toBe(`${l.item}=UNKNOWN`);
341 expect(l.evidence).toContain(`refused by this forge: ${host}`);
342 }
343 }
344 });
345
346 test("a healthz production answers 503, or not at all, is still FAIL (#15935)", async () => {
347 const down: typeof fetch = Object.assign(async (u: string | URL | Request, init?: RequestInit) =>
348 String(u).endsWith("/healthz") ? new Response("down", { status: 503 }) : fetch(u, init), { preconnect: fetch.preconnect });
349 const line = (await probe(base, "o/r", down, NOW)).find((l) => l.item === "healthz fast")!;
350 expect([line.verdict, line.evidence.startsWith("503 in ")]).toEqual(["FAIL", true]);
351 const gone: typeof fetch = Object.assign(async (u: string | URL | Request, init?: RequestInit) => {
352 if (String(u).endsWith("/healthz")) throw new Error("Unable to connect");
353 return fetch(u, init);
354 }, { preconnect: fetch.preconnect });
355 expect((await probe(base, "o/r", gone, NOW)).find((l) => l.item === "healthz fast")!.verdict).toBe("FAIL");
356 });
330357 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs