From d9a39fd2827c78f88345aff285590e601bfb5da5 Mon Sep 17 00:00:00 2001 From: Rhys Sullivan <39114868+RhysSullivan@users.noreply.github.com> Date: Tue, 18 Aug 2026 15:10:11 -0700 Subject: [PATCH] Split header time from body-read time on the docs upstream fetch() resolves when headers arrive, so the earlier probe returned ~1ms without ever reading a body. Both genuinely slow operations read one: the docs proxy reads a 179KB page and the JWKS store calls hit.json(). Time headers and body separately on the exact upstream the docs proxy uses, gated to /robots.txt so normal traffic never pays for it. --- apps/cloud/src/server.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/apps/cloud/src/server.ts b/apps/cloud/src/server.ts index 7b4e38bc6..130cc3f91 100644 --- a/apps/cloud/src/server.ts +++ b/apps/cloud/src/server.ts @@ -224,6 +224,31 @@ const cloudflareHandler: ExportedHandler = { } const fetchProbeMs = Date.now() - fetchStartedAt; + // `fetch()` above resolves when HEADERS arrive — it never reads a body, + // which is why it returns in ~1ms while the request it lives in takes + // seconds. Both genuinely slow operations read a body: the docs proxy + // reads a 179KB page, and the JWKS store does `hit.json()`. Split header + // time from body time on the exact URL the docs proxy uses. + // + // Gated to one cheap path so normal traffic never pays for the probe. + let bodyHeadersMs = -1; + let bodyReadMs = -1; + let bodyBytes = -1; + if (probeUrl.pathname === "/robots.txt") { + // oxlint-disable-next-line executor/no-try-catch-or-throw -- temporary diagnostic: a probe failure must not affect the request + try { + const h0 = Date.now(); + const probeRes = await fetch("https://executor.mintlify.dev/docs/concepts/policies"); + bodyHeadersMs = Date.now() - h0; + const b0 = Date.now(); + const text = await probeRes.text(); + bodyReadMs = Date.now() - b0; + bodyBytes = text.length; + } catch { + // ignored — the timing is the signal + } + } + console.log( JSON.stringify({ probe: "clock-sync", @@ -232,6 +257,9 @@ const cloudflareHandler: ExportedHandler = { cacheProbeMs, timerProbeMs, fetchProbeMs, + bodyHeadersMs, + bodyReadMs, + bodyBytes, }), );