From f5939a1d90ae3a2461d7d809931b58cd3a9bf2f6 Mon Sep 17 00:00:00 2001 From: ci-check Date: Mon, 26 Oct 2026 21:05:43 +0800 Subject: [PATCH 1/2] fix(intercept): stop overwriting lastUnavailableReason to 'dead' after a send-failure give-up (#4599) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #4516 (bc50f1a87) replaced the post-give-up warn log with a state write that clobbered the 'send-failed' register value, breaking #4125's pinned contract (the register must stay 'send-failed' after a send-failure give-up). The user-facing intent of #4516 — accurate oversized-refusal wording — is kept by mapping 'send-failed' onto the dead-equivalent sentence in fallbackOversizeRefusal. --- src/agent/native-intercept.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/agent/native-intercept.ts b/src/agent/native-intercept.ts index 67f99baedc..79c261cddc 100644 --- a/src/agent/native-intercept.ts +++ b/src/agent/native-intercept.ts @@ -601,7 +601,8 @@ function fallbackOversizeRefusal( reason?: UnavailableReason, ): Response { const why = - reason === "dead" + // #4516: a send-failure give-up leaves the register at "send-failed" (#4125) — for the user the connection is dead either way. + reason === "dead" || reason === "send-failed" ? "the bili proxy died and no replacement came up" : reason === "busy-exhausted" ? "the bili proxy is alive but unresponsive within the wait budget (#3654)" @@ -1293,9 +1294,9 @@ export function installNativeFetchIntercept(initialState: NativeInterceptState): noteDispatchMode("proxy"); return resp; } + // #4125 pins the register at "send-failed" after a send-failure give-up; its refusal wording lives in fallbackOversizeRefusal (#4516). state.lastUnavailableReason = "send-failed"; state.onGiveUp?.(); - state.lastUnavailableReason = "dead"; return directSendOrRefuse(routedTarget, makeTarget(routedTarget), init, "no live proxy — model requests go direct (uncompressed)"); } } @@ -1500,9 +1501,9 @@ export function installNativeFetchIntercept(initialState: NativeInterceptState): // lifetime. Degrade exactly like a bootstrap failure: actually // send the request direct, then let the owner clear proxy-owned // state. + // #4125: same register contract as the fetch path above. state.lastUnavailableReason = "send-failed"; state.onGiveUp?.(); - state.lastUnavailableReason = "dead"; return directSendOrRefuse(url, input, init, "proxy respawn failed — model requests go direct (uncompressed)"); } throw err; From 6381f0505e220b69ce09711812302d2e69a91c64 Mon Sep 17 00:00:00 2001 From: ranxianglei Date: Mon, 26 Oct 2026 22:40:43 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(server):=20an=20unconditional=20304=20f?= =?UTF-8?q?rom=20the=20catalog=20endpoint=20is=20off-spec=20=E2=80=94=20no?= =?UTF-8?q?=20phantom=20hit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The catalog cache replayed its cached 200 on ANY 304 and extended freshness by another maxAge. That is correct only when the request was conditional (the end client sent if-none-match / if-modified- since; the wrapper itself never sends a validator). A 304 answered to an UNCONDITIONAL GET is off-spec — some transparent middleboxes do it anyway — and treating it as a hit manufactured a phantom success: six more hours of freshness, all real response headers discarded, and the relay billing it as a genuine catalog fetch. Gate the 304 branch on the request having carried a conditional header; otherwise invalidate the cache and pass the odd response through, same as any other unexpected status. The existing revalidation test now models the conditional header its name always implied; a new test pins the off-spec passthrough plus cache invalidation. --- src/server/codex-catalog-cache.ts | 13 +++++++++++++ tests/codex-catalog-cache.test.ts | 18 ++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/server/codex-catalog-cache.ts b/src/server/codex-catalog-cache.ts index 1b69b362a0..3610ea30e1 100644 --- a/src/server/codex-catalog-cache.ts +++ b/src/server/codex-catalog-cache.ts @@ -213,6 +213,19 @@ export function createCodexCatalogFetch( if ([500, 502, 503, 504].includes(status)) return fresh(entry) ? cached(`temporary HTTP ${status}`, result) : result; if (status === 304) { if (!entry) return result; + // A 304 only means "not modified" when THIS request was + // conditional — the wrapper itself never sends a validator, + // but the end client may have added if-none-match / + // if-modified-since and that negotiated 304 replays the + // cached 200 legitimately. An UNCONDITIONAL 304 is off-spec + // (some transparent middleboxes answer it anyway): treat it + // like any other unexpected status — drop the cache, pass + // the oddity through — instead of extending freshness on a + // phantom hit whose real headers we would also discard. + if (!headers.has("if-none-match") && !headers.has("if-modified-since")) { + await invalidate(); + return result; + } await remember({ ...entry, savedAt: clock() }); discard(result); return replay(entry, false); diff --git a/tests/codex-catalog-cache.test.ts b/tests/codex-catalog-cache.test.ts index 516b1f025f..a89024ab6f 100644 --- a/tests/codex-catalog-cache.test.ts +++ b/tests/codex-catalog-cache.test.ts @@ -127,15 +127,29 @@ test("malformed/empty/oversized successful catalog is forwarded but never rescue } }); -test("temporary HTTP outages recover; 304 revalidation is a complete 200 catalog", async () => { +test("temporary HTTP outages recover; a NEGOTIATED 304 revalidation is a complete 200 catalog", async () => { const f = createCodexCatalogFetch({ directory: null }); await send(f, async () => result()); for (const status of [500, 502, 503, 504]) assert.equal(await (await send(f, async () => result("outage", status))).response.text(), text); - const recovered = await send(f, async () => result(null, 304)); + // The client revalidated (conditional header on the request), so the + // 304 replays the cached catalog as a full 200. + const conditional = { ...init, headers: { ...init.headers, "if-none-match": '"synthetic-v1"' } }; + const recovered = await send(f, async () => result(null, 304), url, conditional); assert.equal(recovered.response.status, 200); assert.deepEqual(await recovered.response.json(), catalog); }); +test("an UNCONDITIONAL 304 is off-spec: no phantom hit — pass it through and drop the cache", async () => { + const f = createCodexCatalogFetch({ directory: null }); + await send(f, async () => result()); + // No if-none-match / if-modified-since on the request: nothing was + // revalidated, so a 304 from a broken middlebox must not extend + // freshness or masquerade as the catalog. + const odd = await send(f, async () => result(null, 304)); + assert.equal(odd.response.status, 304, "the off-spec response is passed through untouched"); + await assert.rejects(() => send(f, offline), /synthetic offline/, "cache invalidated, no phantom rescue"); +}); + test("outage does not renew cache age; expired and cold caches fail honestly", async () => { let clock = 1000; const f = createCodexCatalogFetch({