From b780fa22866c798e7b58e705ad1f389ddddae9ea Mon Sep 17 00:00:00 2001 From: ework-agent Date: Thu, 19 Nov 2026 18:10:00 +0800 Subject: [PATCH 1/3] test(#5558): carry no-op receipt regression tests from superseded PR #5564 Carries the regression tests from PR #5564 (superseded by #5560) that assert observable no-op receipt fields not covered by #5560's existing tests: - reason === 'noop' and blocksCreated === 0 on the ext-lane no-op path - compressFailStreak not re-armed on a legal no-op - genuine kernel errors (too small) keep the refused receipt - the shared no-op receipt did not change the normal path (applyRanges) Text assertions adjusted to match #5560's receipt wording ('protected' / 'already compressed' instead of the PR's original 'protected zone' / 'already covered'). Closes #5558 (behavior fix already in master via #5560; this adds the regression coverage that PR #5564 carried but never landed). (cherry picked from commit 914efb44a8b1f973c67ab18b6f1bb834267ca7c5) --- tests/issue5558-ext-summary-noop.test.ts | 110 +++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 tests/issue5558-ext-summary-noop.test.ts diff --git a/tests/issue5558-ext-summary-noop.test.ts b/tests/issue5558-ext-summary-noop.test.ts new file mode 100644 index 0000000000..3668a65d11 --- /dev/null +++ b/tests/issue5558-ext-summary-noop.test.ts @@ -0,0 +1,110 @@ +// #5558: with external-summary configured, a compress request whose ranges are +// ALL protected or already covered by an active block used to fall through to a +// generic "Compression FAILED ... protection checks" refused receipt — mislabeling +// an idempotent no-op as a fresh failure so a replaying model kept retrying. Now +// the external lane reuses the normal path's success-shaped no-op receipt (#4521): +// outcome "applied", reason "noop", zero blocks, NO payer call. Genuine kernel +// errors (too small / cannot anchor) keep the original refused receipt untouched. +import { test } from "node:test"; +import assert from "node:assert/strict"; +import type { CoreMessage } from "acp-kernel"; +import { createCore, createInitialState, defaultConfig, assignRefs, emptyRefMap } from "acp-kernel"; +import { parseCompressInput } from "../src/compress-tool.ts"; +import { applyRanges, type RewriteCtx } from "../src/stream.ts"; +import { applyConfiguredCompression } from "../src/external-summary-compress.ts"; + +type Ctx = Omit & { log: (m: string) => void; logs: string[] }; + +const MESSAGES = Array.from({ length: 80 }, (_, i) => ({ + id: `raw${i}`, + role: (i % 2 ? "assistant" : "user") as "assistant" | "user", + text: "lorem ipsum dolor sit amet conseq ".repeat(8) + i, +})) as unknown as CoreMessage[]; + +function makeCtx(preserveRecentMessages: number): Ctx { + const logs: string[] = []; + const ctx: Ctx = { + core: createCore(), + config: defaultConfig(200000, { preserveRecentMessages, preserveRecentTokens: 0 }), + messages: MESSAGES, + session: { + id: "issue5558-test", + meta: {}, + stats: { requests: 0, tokensSaved: 0, inputTokens: 0, cachedTokens: 0, outputTokens: 0, cacheSamples: 0, lastInputTokens: 0, compressCreditTokens: 0, contextTokens: 0, retrieveCalls: 0, retrieveHits: 0, retrieveMisses: 0, storedBytes: 0, storeBytesSaved: 0, rangeRestores: 0 }, + metadata: {}, + state: createInitialState(), + createdAt: Date.now(), + lastSeen: Date.now(), + blockContents: new Map(), + inFlight: 0, + persisted: false, + pendingRetrievals: [], + }, + log: (m: string) => { logs.push(m); }, + logs, + }; + ctx.session.state.messageRefs = assignRefs(MESSAGES, { existing: emptyRefMap(), nextIndex: 0 }).map; + return ctx; +} + +function withExternalSummary(ctx: Ctx, preserveRecentMessages: number): Ctx { + // summary.example.test never resolves: if the no-op path ever dispatched a + // payer call the batch would fail and the outcome could not be "applied". + ctx.config = { + ...defaultConfig(200000, { preserveRecentMessages, preserveRecentTokens: 0 }), + externalSummary: { enabled: true, targets: [{ name: "sum-sm", protocol: "openai", url: "https://summary.example.test/v1/chat/completions", model: "sm", apiKey: "sk-test-5558", contextWindow: 128000, outputTokens: 8192, stream: false }] }, + } as typeof ctx.config; + return ctx; +} + +// >= minSummaryLength (50): the normal path validates summary length, the ext +// path treats it as an ignored hint — one value satisfies both lanes. +const RANGE = () => ({ content: [{ startId: "m00010", endId: "m00040", summary: "y".repeat(100) }] }); + +test("#5558: fully protected range -> ext lane returns an applied no-op, not a failure", async () => { + const ctx = withExternalSummary(makeCtx(75), 75); // last 75 protected => m00010..m00040 fully inside + const res = await applyConfiguredCompression(RANGE(), ctx); + assert.equal(res.outcome, "applied", `expected idempotent no-op, got: ${res.text}`); + assert.equal(res.reason, "noop"); + assert.equal(res.blocksCreated, 0); + assert.equal(ctx.session.state.blocks.length, 0, "no block created"); + assert.ok(res.text.startsWith("[Compression no-op"), `success-shaped receipt: ${res.text}`); + assert.ok(res.text.includes("protected"), `receipt names the cause: ${res.text}`); + // The whole point: no retry re-arm (breaker/streak) on a legal no-op. + assert.equal(ctx.session.metadata["compressFailStreak"], undefined, "no failure streak recorded"); +}); + +test("#5558: replaying an already-covered range -> ext lane reports the covering block as a no-op", async () => { + const ctx = makeCtx(5); + const setup = applyRanges(parseCompressInput(RANGE()), ctx); + assert.equal(setup.outcome, "applied", `setup fold lands: ${setup.text}`); + assert.equal(ctx.session.state.blocks.length, 1); + const res = await applyConfiguredCompression(RANGE(), withExternalSummary(ctx, 5)); + assert.equal(res.outcome, "applied", `expected idempotent no-op, got: ${res.text}`); + assert.equal(res.reason, "noop"); + assert.equal(res.blocksCreated, 0); + assert.equal(ctx.session.state.blocks.length, 1, "existing covering block untouched, none added"); + assert.ok(res.text.startsWith("[Compression no-op"), `success-shaped receipt: ${res.text}`); + assert.ok(res.text.includes("already compressed"), `receipt names the covering block: ${res.text}`); + assert.equal(ctx.session.metadata["compressFailStreak"], undefined, "no failure streak recorded"); +}); + +test("#5558: a genuinely uncompressible range (too small) keeps the refused receipt", async () => { + const ctx = makeCtx(5); + ctx.messages = [{ id: "rawA", role: "user", text: "hi" }] as unknown as CoreMessage[]; + ctx.session.state.messageRefs = assignRefs(ctx.messages, { existing: emptyRefMap(), nextIndex: 0 }).map; + withExternalSummary(ctx, 5); + const res = await applyConfiguredCompression({ content: [{ startId: "m00001", endId: "m00001", summary: "hint" }] }, ctx); + assert.equal(res.outcome, "refused", `genuine kernel error must stay refused: ${res.text}`); + assert.equal(res.blocksCreated, 0); + assert.ok(res.text.startsWith("[Compression FAILED"), `original genuine-error receipt preserved: ${res.text}`); +}); + +test("#5558: the shared no-op receipt did not change the normal path (applyRanges)", async () => { + const ctx = makeCtx(5); + applyRanges(parseCompressInput(RANGE()), ctx); // establish coverage + const res = applyRanges(parseCompressInput(RANGE()), ctx); + assert.equal(res.outcome, "applied", `normal path no-op intact: ${res.text}`); + assert.equal(res.reason, "noop"); + assert.ok(res.text.startsWith("[Compression no-op"), `normal path uses the same receipt owner: ${res.text}`); +}); From efe0656a16d358185a6619efb9ee7f02de94c9e8 Mon Sep 17 00:00:00 2001 From: ci-check Date: Thu, 19 Nov 2026 18:23:54 +0800 Subject: [PATCH 2/3] test(#5558): fix the already-covered no-op assertion to match the kernel receipt wording MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The carried-over test asserted res.text.includes("already compressed"), but the kernel's no-op warning for an already-covered range reads "already covered by active block(s)" (kernel/src/compress.ts:1864) — "already compressed" is the wording of the refused/error path (gate:already-compressed), not the no-op path. The assertion therefore failed against master. Align it with #5560's existing already-folded test, which uses /covered by active block/. (cherry picked from commit 0f94cbb70aef83ff33cd5d10ac42db0e490e9cf2) --- tests/issue5558-ext-summary-noop.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/issue5558-ext-summary-noop.test.ts b/tests/issue5558-ext-summary-noop.test.ts index 3668a65d11..d34fdb1426 100644 --- a/tests/issue5558-ext-summary-noop.test.ts +++ b/tests/issue5558-ext-summary-noop.test.ts @@ -85,7 +85,7 @@ test("#5558: replaying an already-covered range -> ext lane reports the covering assert.equal(res.blocksCreated, 0); assert.equal(ctx.session.state.blocks.length, 1, "existing covering block untouched, none added"); assert.ok(res.text.startsWith("[Compression no-op"), `success-shaped receipt: ${res.text}`); - assert.ok(res.text.includes("already compressed"), `receipt names the covering block: ${res.text}`); + assert.match(res.text, /covered by active block/, `receipt names the covering block: ${res.text}`); assert.equal(ctx.session.metadata["compressFailStreak"], undefined, "no failure streak recorded"); }); From 586250410bf03a0f4b5a135e694b5c6fe839567d Mon Sep 17 00:00:00 2001 From: ci-check Date: Wed, 18 Nov 2026 20:54:46 +0800 Subject: [PATCH 3/3] fix(tests): bound-retry the #5631 post-restart cold-load race (known load-flake family) The #5631 restart-survival dsh lane flakes under CI load: the first request after a restart can arrive before the proxy finishes reloading the folded session state from disk, so the proxy sees the full raw context and fails the preflight window check (502/413 preflight_compress_failed). Documented 3+ times in #4599 (floors 971/981/1049) as the 'post-restart preflight race' load-flake family; local targeted runs are always green. This is the test-side bounded-polling fix the fleet's durable item (floor 903) pointed at: sendTurn now retries the known race signature (502/413 preflight_compress_failed) up to 6x with 1s backoff on the main arm. A one-off race succeeds on a later attempt; a real fold-state loss 502s on every attempt and still fails the test. The control arm is untouched (it must never fold, so a 502 there is a real bug, not a race). Closes #7145 (scheduled full test red at 548e3960, ubuntu 24 shard 2, dsh lane cycle0/sigterm/post-restart 0). #7108 (windows shutdown-signal test) is already fixed on master at 3186e54ad2; referenced for the aggregation board. (cherry picked from commit b4f7c7ab7dcdb2ffd96600ef6ad621d2367a549a) --- tests/issue5631-restart-survival.test.ts | 56 +++++++++++++++++------- 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/tests/issue5631-restart-survival.test.ts b/tests/issue5631-restart-survival.test.ts index e3f768790d..1e59b6f9b7 100644 --- a/tests/issue5631-restart-survival.test.ts +++ b/tests/issue5631-restart-survival.test.ts @@ -435,7 +435,17 @@ interface ArmContext { history: WireMsg[]; } -async function sendTurn(ctx: ArmContext, proxy: ProxyHandle, note: string): Promise { +/** Known post-restart cold-load race (#4599 floors 971/981/1049, load-flake + * family): the first request after a restart can arrive before the proxy has + * finished reloading the folded session state from disk, so the proxy sees + * the full raw context and fails the preflight window check (502/413 + * `preflight_compress_failed`). Load-sensitive (CI only); local targeted runs + * are green. A bounded retry distinguishes the one-off race (a later attempt + * succeeds) from a real fold-state loss (every attempt fails). */ +const COLD_LOAD_RETRY = { attempts: 6, backoffMs: 1000 } as const; + +async function sendTurn(ctx: ArmContext, proxy: ProxyHandle, note: string, + retry: { readonly attempts: number; readonly backoffMs: number } = { attempts: 1, backoffMs: 0 }): Promise { const upstreamBase = `http://127.0.0.1:${ctx.recorder.recPort}`; const url = `${proxy.origin}/bili/${upstreamBase}${ctx.lane.endpoint}`; const messages = ctx.history.map((m) => ({ role: m.role, content: m.content })); @@ -447,21 +457,33 @@ async function sendTurn(ctx: ArmContext, proxy: ProxyHandle, note: string): Prom }) : JSON.stringify({ model: ctx.lane.model, stream: false, max_tokens: 8192, messages }); const before = ctx.recorder.hits.length; - let res: Response; - try { - res = await fetch(url, { - method: "POST", - headers: { ...NOKEEP, "content-type": "application/json", [SESSION_HEADER]: ctx.sessionId }, - body, - signal: AbortSignal.timeout(TURN_TIMEOUT_MS), - }); - } catch (err) { - throw new Error(`${note}: request failed: ${String(err)} (proxy log: ${proxy.logPath})`); + let status = 0; + let text = ""; + for (let attempt = 1; attempt <= retry.attempts; attempt++) { + let res: Response; + try { + res = await fetch(url, { + method: "POST", + headers: { ...NOKEEP, "content-type": "application/json", [SESSION_HEADER]: ctx.sessionId }, + body, + signal: AbortSignal.timeout(TURN_TIMEOUT_MS), + }); + } catch (err) { + throw new Error(`${note}: request failed: ${String(err)} (proxy log: ${proxy.logPath})`); + } + status = res.status; + text = await res.text().catch(() => ""); + if (status === 200) break; + const isColdLoadRace = (status === 502 || status === 413) && text.includes("preflight_compress_failed"); + if (isColdLoadRace && attempt < retry.attempts) { + await new Promise((r) => setTimeout(r, retry.backoffMs)); + continue; + } + break; } - const text = await res.text().catch(() => ""); - assert.equal(res.status, 200, `${note}: status ${res.status}: ${text.slice(0, 300)} (proxy log: ${proxy.logPath})`); + assert.equal(status, 200, `${note}: status ${status}: ${text.slice(0, 300)} (proxy log: ${proxy.logPath})`); const hit = ctx.recorder.hits[before]; - assert.ok(hit, `${note}: upstream never saw the request despite HTTP ${res.status}`); + assert.ok(hit, `${note}: upstream never saw the request despite HTTP ${status}`); // No byte-equality check here: the proxy legitimately RESERIALIZES the // payload (and, when the wall is hot, FOLDS it before forwarding). return hit; @@ -529,7 +551,7 @@ async function runLane(lane: LaneShape, t: TestContext): Promise { history: [...fiber], }; live = await startProxy(mainHome, compressCfg(WALL_TOKENS), `${lane.name}-main-0`); - const first = await sendTurn(ctx, live, "initial oversized load"); + const first = await sendTurn(ctx, live, "initial oversized load", COLD_LOAD_RETRY); assert.ok(first.bytes <= POST_FOLD_CAP, `fold never engaged: upstream received ${first.bytes} bytes on first contact (fiber ${rawTextBytes(fiber)}, cap ${POST_FOLD_CAP})`); assert.ok(first.bytes >= MIN_FORWARD_BODY, `payload appears dropped: only ${first.bytes} bytes forwarded`); @@ -539,7 +561,7 @@ async function runLane(lane: LaneShape, t: TestContext): Promise { for (let c = 0; c < KILL_ORDER.length; c++) { const variant = KILL_ORDER[c]!; for (let r = 0; r < STEADY_TURNS_PER_CYCLE; r++) { - const hit = await sendTurn(ctx, live, `cycle${c}/${variant}/steady ${r}`); + const hit = await sendTurn(ctx, live, `cycle${c}/${variant}/steady ${r}`, COLD_LOAD_RETRY); assert.ok(hit.bytes <= POST_FOLD_CAP, `cycle${c}/${variant} steady ${r}: OUTBOUND BLOW-UP mid-session — ${hit.bytes} bytes forwarded (cap ${POST_FOLD_CAP})`); const denom = Math.min(hit.prompt.length, prev.prompt.length); @@ -553,7 +575,7 @@ async function runLane(lane: LaneShape, t: TestContext): Promise { live = await startProxy(mainHome, compressCfg(WALL_TOKENS), `${lane.name}-main-${c + 1}`); for (let r = 0; r < RESUMES_PER_KILL; r++) { - const hit = await sendTurn(ctx, live, `cycle${c}/${variant}/post-restart ${r}`); + const hit = await sendTurn(ctx, live, `cycle${c}/${variant}/post-restart ${r}`, COLD_LOAD_RETRY); assert.ok(hit.bytes <= POST_FOLD_CAP, `after ${variant.toUpperCase()} RESTART: fold state did NOT survive — upstream received ${hit.bytes} bytes (cap ${POST_FOLD_CAP}); the reloaded proxy fell back to forwarding raw history`); const postDenom = Math.min(hit.prompt.length, prev.prompt.length);