From 52bda58514bb0a76b70e6c399ea4e7ff0c65d222 Mon Sep 17 00:00:00 2001 From: ci-check Date: Sun, 25 Oct 2026 04:35:34 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20preflight=20fail-fast=20diagnoses=20?= =?UTF-8?q?=E2=80=94=20name=20headroom-reserved=20walls=20as=20the=20effec?= =?UTF-8?q?tive=20input=20budget,=20count=20attempted=20summary=20calls=20?= =?UTF-8?q?(#3663)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/preflight.ts | 22 +- src/server.ts | 32 +- ...ue3663-preflight-diagnostic-labels.test.ts | 336 ++++++++++++++++++ 3 files changed, 384 insertions(+), 6 deletions(-) create mode 100644 tests/issue3663-preflight-diagnostic-labels.test.ts diff --git a/src/preflight.ts b/src/preflight.ts index 4c90bf5c26..ed01f4aaee 100644 --- a/src/preflight.ts +++ b/src/preflight.ts @@ -1770,9 +1770,14 @@ export async function preflightCompress(deps: PreflightDeps, messages: CoreMessa const active = deps.session.state.blocks.filter((b) => b.active); return active.filter((b) => b.tier === 1).length >= 2 || active.filter((b) => b.tier === 2).length >= 2; }; - type TierRecoveryResult = { recovered: boolean; callsUsed: number; netSaved: number; honestDetail: string }; + type TierRecoveryResult = { recovered: boolean; callsUsed: number; attemptsUsed: number; netSaved: number; honestDetail: string }; const attemptTierRecovery = async (): Promise => { let callsUsed = 0; + // #3663: distillation dispatches committed, INCLUDING the ones that threw / + // timed out / came back unusable — callsUsed alone counts only completed + // folds, so a fully-failed recovery read as "0 summary call(s)" and hid + // the attempts the operator's logs show did happen. + let attemptsUsed = 0; let netSaved = 0; // #4227: the most recent measurement's nudge offer — pinned into the // distill fold's ctx so its receipt tail judges from the same @@ -1908,6 +1913,7 @@ export async function preflightCompress(deps: PreflightDeps, messages: CoreMessa break; } let outcome; + attemptsUsed += 1; // #3663: the dispatch is committed here — every post-dispatch exit (throw/unusable/drift/refuse/success) counts as an attempt try { outcome = await summarizeRange(deps, content, first.blockId, last.blockId, undefined, system); } catch (error) { @@ -1975,11 +1981,18 @@ export async function preflightCompress(deps: PreflightDeps, messages: CoreMessa : stopReason === "cap" ? `the bounded distillation call budget was reached after ${callsUsed} call(s)` : stopReason === "unavailable" ? "the distillation summary was unavailable" : "a distillation pass produced no further shrink"; + // #3663: state attempted-vs-completed when some dispatch failed — "0 summary + // call(s)" read as "nothing was tried" although the logs show calls that + // threw/timed out. Byte-identical to the historical phrasing when every + // dispatched call completed. + const callCountPhrase = attemptsUsed > callsUsed + ? `${callsUsed} of ${attemptsUsed} attempted summary call(s) completed` + : `${callsUsed} summary call(s)`; const honestDetail = - `futile round: folding compressible raw messages plus tier distillation (${callsUsed} summary call(s), net ~${netSaved} tokens saved) still leaves the payload ~${overBy} tokens over the window — ${why}. ` + + `futile round: folding compressible raw messages plus tier distillation (${callCountPhrase}, net ~${netSaved} tokens saved) still leaves the payload ~${overBy} tokens over the window — ${why}. ` + `These figures are measured on the post-fold wire view; the separately displayed context total additionally floors on the upstream usage baseline, which also bills the system prompt and tool definitions. ` + `Raise the model context window or restart the session.`; - return { recovered, callsUsed, netSaved, honestDetail }; + return { recovered, callsUsed, attemptsUsed, netSaved, honestDetail }; }; for (let round = 0; round < effectiveRoundCap; round++) { if (deps.signal?.aborted) { @@ -2957,7 +2970,8 @@ export async function preflightCompress(deps: PreflightDeps, messages: CoreMessa if (!tierRecoveryAttempted && eligibleForTierRecovery()) { tierRecoveryAttempted = true; const rec = await attemptTierRecovery(); - deps.log("info", `[preflight] tier-distillation recovery finished: ${rec.recovered ? "recovered" : "not recovered"}; ${rec.callsUsed} summary call(s), net ~${rec.netSaved} tok saved (#2952)`); + const recCallPhrase = rec.attemptsUsed > rec.callsUsed ? `${rec.callsUsed} of ${rec.attemptsUsed} attempted summary call(s) completed` : `${rec.callsUsed} summary call(s)`; + deps.log("info", `[preflight] tier-distillation recovery finished: ${rec.recovered ? "recovered" : "not recovered"}; ${recCallPhrase}, net ~${rec.netSaved} tok saved (#2952, #3663)`); if (!rec.recovered) { failure = { kind: "exhausted", detail: rec.honestDetail }; } diff --git a/src/server.ts b/src/server.ts index 2dd74daee8..9b0c84b27c 100644 --- a/src/server.ts +++ b/src/server.ts @@ -3283,6 +3283,31 @@ export function buildWindowShrinkNote(args: { return head + `it was aligned down to codex's own window perception; set compress.modelContextLimit explicitly if your upstream serves the larger window.`; } +/** #3663: label the wall the preflight fail-fast headline cites. When bili's own + * output-headroom reservation (handle.ts rewrites modelContextLimit in place and + * records NO shrink reason) is what sits between the cited wall and the model's + * native window, name it as the effective INPUT budget and point at the setting + * that controls it — calling that budget "the model window" made readers chase + * model metadata instead of compress.outputHeadroomMaxPct / max_tokens. Every + * other shape keeps today's wording byte-identical: operator/codex shrink reasons + * carry their own notes (#736), and a wall strictly below config.modelContextLimit + * means the stated-wall overflow arm (#3450) bound, not headroom. */ +export function buildEffectiveWallClause(args: { + limit: number; + configuredLimit: number; + nativeWindow?: number; + shrinkReason: "operator" | "codex" | undefined; +}): string { + const { limit, configuredLimit, nativeWindow, shrinkReason } = args; + const headroomShrunk = shrinkReason === undefined + && nativeWindow !== undefined + && limit === configuredLimit + && configuredLimit < nativeWindow; + return headroomShrunk + ? `the effective input budget ${limit} (model window ${nativeWindow}, ${nativeWindow - configuredLimit} tokens reserved for model output via compress.outputHeadroomMaxPct)` + : `the model window ${limit}`; +} + export async function preflightCompressIfNeeded( prepared: Prepared, runPrepare: () => Promise, @@ -3593,9 +3618,12 @@ export async function preflightCompressIfNeeded( const imageNote = imageTokens >= limit ? ` Images alone account for ~${imageTokens} tokens (≥ window ${limit}); compression cannot remove them — shrink or remove the images, or raise the window.` : ""; + // #3663: label the cited wall by what actually set it (native window vs + // headroom-reserved effective input budget) instead of always "model window". + const wallClause = buildEffectiveWallClause({ limit, configuredLimit: config.modelContextLimit, nativeWindow: resolvedNativeWindow, shrinkReason: windowShrinkReason }); const sizeClause = foldedTokens !== undefined && foldedTokens < tokenCount - ? `context ~${foldedTokens} tokens (down from ~${tokenCount} before preflight) exceeds the model window ${limit}` - : `context ~${tokenCount} tokens exceeds the model window ${limit}`; + ? `context ~${foldedTokens} tokens (down from ~${tokenCount} before preflight) exceeds ${wallClause}` + : `context ~${tokenCount} tokens exceeds ${wallClause}`; const rangesClause = rangesLeft !== undefined ? `, with ${rangesLeft} compressible range(s) still visible` : ""; // #736: when the wall is bili's own shrunken window, say so — "raise the // model context window" otherwise sends operators to the upstream when diff --git a/tests/issue3663-preflight-diagnostic-labels.test.ts b/tests/issue3663-preflight-diagnostic-labels.test.ts new file mode 100644 index 0000000000..bb55555d32 --- /dev/null +++ b/tests/issue3663-preflight-diagnostic-labels.test.ts @@ -0,0 +1,336 @@ +import assert from "node:assert/strict"; +import http from "node:http"; +import { once } from "node:events"; +import test from "node:test"; + +process.env.NODE_ENV = "test"; + +import { createCore, createInitialState, defaultConfig, defaultPrompts, type CoreMessage } from "acp-kernel"; +import type { ResolvedKernelConfig } from "../src/compress-settings.js"; +import type { Session } from "../src/session.ts"; +import { preflightCompress, type PreflightDeps } from "../src/preflight.ts"; +import { ConfiguredSummaryPlan } from "../src/external-summary-runtime.js"; +import { startServer, buildEffectiveWallClause } from "../src/server.ts"; +import type { ProxyOptions } from "../src/config.ts"; +import { SessionStore, _setStoreForTest } from "../src/persist.ts"; +import { getSession } from "../src/session.ts"; +import { _setForTest as setRegistryForTest } from "../src/registry.ts"; +import { normalizeUpstreamOrigin } from "../src/util.ts"; + +// #3663 facet B: the preflight fail-fast headline cited the headroom-reserved +// wall as "the model window N" even though N = native − output-headroom +// reservation (handle.ts rewrites modelContextLimit in place, records no shrink +// reason). Readers chased model metadata instead of the setting that controls +// the rejection (compress.outputHeadroomMaxPct / the request's max_tokens). +// buildEffectiveWallClause labels the cited wall by what actually set it; +// every non-headroom shape must stay byte-identical to the historical wording. + +test("#3663: buildEffectiveWallClause truth table (positive + all negative gates)", () => { + assert.equal( + buildEffectiveWallClause({ limit: 22_500, configuredLimit: 22_500, nativeWindow: 30_000, shrinkReason: undefined }), + "the effective input budget 22500 (model window 30000, 7500 tokens reserved for model output via compress.outputHeadroomMaxPct)", + "headroom-reserved wall must be labeled as the effective input budget with the native window and the controlling setting named"); + // Negative gates — each must keep the historical "the model window N" byte-for-byte: + assert.equal( + buildEffectiveWallClause({ limit: 30_000, configuredLimit: 30_000, nativeWindow: 30_000, shrinkReason: undefined }), + "the model window 30000", + "no reservation (configured == native) must not gain the headroom label"); + assert.equal( + buildEffectiveWallClause({ limit: 22_500, configuredLimit: 22_500, nativeWindow: 30_000, shrinkReason: "operator" }), + "the model window 22500", + "an operator shrink keeps its own #736 note; the wall clause stays historical"); + assert.equal( + buildEffectiveWallClause({ limit: 22_500, configuredLimit: 22_500, nativeWindow: 30_000, shrinkReason: "codex" }), + "the model window 22500", + "a codex alignment keeps its own #736 note; the wall clause stays historical"); + assert.equal( + buildEffectiveWallClause({ limit: 20_000, configuredLimit: 22_500, nativeWindow: 30_000, shrinkReason: undefined }), + "the model window 20000", + "a wall strictly below config.modelContextLimit means the stated-wall overflow arm bound (#3450), not headroom"); + assert.equal( + buildEffectiveWallClause({ limit: 22_500, configuredLimit: 22_500, nativeWindow: undefined, shrinkReason: undefined }), + "the model window 22500", + "without a resolved native window there is nothing to contrast — stay historical"); +}); + +// Integration: the label must survive the FULL path — request max_tokens → +// handle.ts output-headroom reservation (in-place modelContextLimit rewrite) → +// preflightCompressIfNeeded fail-fast. Harness cloned from +// tests/issue3645-calibrated-futility.test.ts (same mock upstream + boot shape). + +const WINDOW = 30_000; + +type Call = { summary: boolean }; +let CALLS: Call[] = []; + +function chatSse(text: string, finishReason: string): string { + const chunk = (delta: Record, finish: string | null): string => + `data: ${JSON.stringify({ id: "chatcmpl-1", object: "chat.completion.chunk", created: 1, model: "gpt-test", choices: [{ index: 0, delta, finish_reason: finish }] })}\n\n`; + return chunk({ role: "assistant" }, null) + chunk({ content: text }, null) + chunk({}, finishReason) + "data: [DONE]\n\n"; +} + +function mockUpstream(): http.Server { + return http.createServer((req, res) => { + const chunks: Buffer[] = []; + req.on("data", (c: Buffer) => chunks.push(c)); + req.on("end", () => { + CALLS.push({ summary: /TASK: The conversation segment below/.test(Buffer.concat(chunks).toString("utf8")) }); + res.writeHead(200, { "content-type": "text/event-stream" }); + res.end(chatSse("forwarded answer", "stop")); + }); + }); +} + +function proxyOptions(upstreamPort: number): ProxyOptions { + return { + port: 0, + host: "127.0.0.1", + upstream: "http://127.0.0.1", + routes: { [`http://127.0.0.1:${upstreamPort}`]: { models: { "gpt-test": { context: WINDOW } } } } as ProxyOptions["routes"], + modelContextLimit: WINDOW, + kernelConfig: defaultConfig(WINDOW, { + preserveRecentMessages: 2, + preserveRecentTokens: 1000, + protectedTools: ["bash"], + compress: { minCompressRange: 1000, maxSummaryLength: 20000, minSummaryLength: 50 }, + }), + compress: { injectTool: true, injectNudge: true }, + promptCache: { routing: "auto" }, + sessionHeader: "x-acp-session", + log: false, + debug: false, + passthrough: false, + autoUpdate: false, + mitm: { enabled: false, domains: [] }, + } as ProxyOptions; +} + +function bashPair(id: number, resultRepeat: number): Record[] { + return [ + { role: "assistant", content: null, tool_calls: [{ id: `call_${id}`, type: "function", function: { name: "bash", arguments: JSON.stringify({ command: "echo hi" }) } }] }, + { role: "tool", tool_call_id: `call_${id}`, content: `BASH_RESULT_${id}_payload_`.repeat(resultRepeat) }, + ]; +} + +async function boot(upstreamPort: number): Promise<{ proxyPort: number; cleanup: () => Promise }> { + _setStoreForTest(new SessionStore({ enabled: false })); + setRegistryForTest({}); + const upstream = mockUpstream(); + upstream.listen(0, "127.0.0.1"); + await once(upstream, "listening"); + const proxy = await startServer(proxyOptions(upstreamPort)); + await once(proxy, "listening"); + const proxyPort = (proxy.address() as { port: number }).port; + return { + proxyPort, + cleanup: async () => { + proxy.close(); + proxy.closeIdleConnections?.(); + await once(proxy, "close"); + upstream.close(); + upstream.closeIdleConnections?.(); + await once(upstream, "close"); + }, + }; +} + +function post(proxyPort: number, upstreamPort: number, session: string, messages: Record[], extraBody: Record): Promise { + return fetch(`http://127.0.0.1:${proxyPort}/bili/http://127.0.0.1:${upstreamPort}/chat/completions`, { + method: "POST", + headers: { "content-type": "application/json", "x-acp-session": session }, + body: JSON.stringify({ model: "gpt-test", stream: true, messages, ...extraBody }), + }); +} + +// #4185: an identified fresh session whose preflight ends in deterministic +// exhaustion forwards once for upstream arbitration — seed a settled usage +// baseline so these rows keep testing the LOCAL fail-fast contract. +function seedEvidence(upstreamPort: number, sessionId: string): void { + const s = getSession(sessionId); + s.stats.lastInputTokens = 100; + s.stats.lastInputTokensSource = "usage"; + s.stats.lastInputTokensOrigin = normalizeUpstreamOrigin(`http://127.0.0.1:${upstreamPort}`); +} + +test("#3663: headroom-reserved wall is labeled as the effective input budget end-to-end", async () => { + CALLS = []; + const upstream = mockUpstream(); + upstream.listen(0, "127.0.0.1"); + await once(upstream, "listening"); + const upstreamPort = (upstream.address() as { port: number }).port; + const p = await boot(upstreamPort); + try { + // Two hard-protected bash pairs (never foldable) sized so the payload sits + // OVER the headroom-reserved budget (30000 − min(8000, 0.25×30000)=22500) + // yet UNDER the native window: the rejection is governed entirely by the + // output-headroom reservation, exactly the reported shape. + const REPEAT = 1990; // bulk ≈ 12×1990 + 40 ≈ 23960 tokens + const sessionId = "issue3663-headroom-label"; + seedEvidence(upstreamPort, sessionId); + const resp = await post(p.proxyPort, upstreamPort, sessionId, [ + ...bashPair(1, REPEAT), + ...bashPair(2, REPEAT), + ], { max_tokens: 8000 }); + const body = await resp.text(); + let json: { error?: { code?: string; message?: string } }; + try { json = JSON.parse(body); } catch { assert.fail(`expected a JSON fail-fast error, got HTTP ${resp.status}: ${body.slice(0, 240)}`); return; } + assert.equal(resp.status, 413, `deterministic exhaustion must fail fast non-retryably: HTTP ${resp.status} ${body.slice(0, 240)}`); + assert.equal(json.error?.code, "preflight_compress_failed"); + const msg = json.error?.message ?? ""; + assert.match(msg, /context ~\d+ tokens exceeds the effective input budget 22500 \(model window 30000, 7500 tokens reserved for model output via compress\.outputHeadroomMaxPct\)/, + `headroom-reserved wall must be labeled as the effective input budget with the native window named (got: ${msg})`); + assert.ok(!msg.includes("exceeds the model window"), `must not call the reserved budget "the model window" (got: ${msg})`); + assert.equal(CALLS.filter((c) => c.summary).length, 0, "deterministic exhaustion spends ZERO summarization calls"); + } finally { + await p.cleanup(); + upstream.close(); + upstream.closeIdleConnections?.(); + await once(upstream, "close"); + } +}); + +test("#3663: without an output reservation the wall keeps the historical 'model window' label", async () => { + CALLS = []; + const upstream = mockUpstream(); + upstream.listen(0, "127.0.0.1"); + await once(upstream, "listening"); + const upstreamPort = (upstream.address() as { port: number }).port; + const p = await boot(upstreamPort); + try { + // Same shape, NO max_tokens → no headroom reservation → limit == native. + // Payload over the NATIVE window; the label must stay byte-historical. + const REPEAT = 2660; // bulk ≈ 12×2660 + 40 ≈ 31960 tokens > 30000 + const sessionId = "issue3663-native-label"; + seedEvidence(upstreamPort, sessionId); + const resp = await post(p.proxyPort, upstreamPort, sessionId, [ + ...bashPair(1, REPEAT), + ...bashPair(2, REPEAT), + ], {}); + const body = await resp.text(); + let json: { error?: { code?: string; message?: string } }; + try { json = JSON.parse(body); } catch { assert.fail(`expected a JSON fail-fast error, got HTTP ${resp.status}: ${body.slice(0, 240)}`); return; } + assert.equal(resp.status, 413, `deterministic exhaustion must fail fast non-retryably: HTTP ${resp.status} ${body.slice(0, 240)}`); + const msg = json.error?.message ?? ""; + assert.match(msg, /context ~\d+ tokens exceeds the model window 30000/, `no-reservation wall must keep the historical label (got: ${msg})`); + assert.ok(!msg.includes("effective input budget"), `no headroom happened — the budget label must not appear (got: ${msg})`); + } finally { + await p.cleanup(); + upstream.close(); + upstream.closeIdleConnections?.(); + await once(upstream, "close"); + } +}); + +// #3663 facet C: the tier-recovery detail counted only COMPLETED distillations +// (callsUsed), so a recovery whose summarizer failed/timed out read "0 summary +// call(s)" although the logs show the attempts happened. The detail must state +// attempted-vs-completed; the common case (every dispatched call completed) +// keeps the historical phrasing byte-for-byte. Harness cloned from +// tests/issue2952-preflight-tier-recovery.test.ts (direct preflightCompress). + +function filler(chars: number, tag: string): string { + const unit = `${tag} alpha beta gamma delta epsilon zeta eta theta iota kappa lambda mu nu xi omicron pi rho sigma tau upsilon phi chi psi omega `; + return unit.repeat(Math.ceil(chars / unit.length)).slice(0, chars); +} + +interface FixtureOpts { limit: number; blockCount: number; blockChars: number; tailChars: number; } + +// Builds a session whose history is already folded into `blockCount` tier-1 +// blocks (large summaries) plus a small foldable early message and a protected +// tail. The block mass dominates the payload, so the raw pool alone cannot +// close the deficit and the walk defers to tier distillation. +function buildFixture(o: FixtureOpts) { + const core = createCore(); + const config = defaultConfig(o.limit); + config.preserveRecentMessages = 1; + config.preserveRecentTokens = 0; + config.compress.minCompressRange = 100; + const messages: CoreMessage[] = [ + { id: "early", role: "user", contentType: "text", text: filler(500, "EARLY") }, + ]; + for (let i = 0; i < o.blockCount; i++) { + messages.push({ id: `u${i}`, role: "user", contentType: "text", text: filler(o.blockChars, `HISTU${i}`) }); + messages.push({ id: `a${i}`, role: "assistant", contentType: "text", text: filler(120, `HISTA${i}`) }); + } + messages.push({ id: "tail", role: "user", contentType: "text", text: filler(o.tailChars, "TAIL") }); + const turn = core.processTurn({ messages, state: createInitialState(), config: { ...config, modelContextLimit: o.limit * 1000 }, tokenCount: o.limit * 1000, renderTags: "text-only" }); + const foldCfg = { ...config, preserveRecentMessages: 0, preserveRecentTokens: 0 }; + let state = turn.state; + for (let i = 0; i < o.blockCount; i++) { + const ref = turn.state.messageRefs.byRaw[`u${i}`]; + const c = core.applyCompression({ messages, state, config: foldCfg, ranges: [{ startRef: ref, endRef: ref, summary: filler(o.blockChars, `BLK${i}`) }] }); + state = c.state; + } + const session: Session = { + id: "issue3663-preflight", meta: {}, metadata: {}, state, + stats: { requests: 1, tokensSaved: 0, inputTokens: 0, cachedTokens: 0, outputTokens: 0, cacheSamples: 0, lastInputTokens: o.limit * 4, compressCreditTokens: 0, contextTokens: o.limit * 4, retrieveCalls: 0, retrieveHits: 0, retrieveMisses: 0, storedBytes: 0, storeBytesSaved: 0, rangeRestores: 0 }, + pendingRetrievals: [], createdAt: Date.now(), lastSeen: Date.now(), blockContents: new Map(), inFlight: 0, persisted: false, + }; + return { core, config, messages, session }; +} + +async function startJsonUpstream(status: number, body: object): Promise<{ server: http.Server; url: string }> { + const server = http.createServer((_req, res) => { res.writeHead(status, { "content-type": "application/json" }); res.end(JSON.stringify(body)); }); + await new Promise((r) => server.listen(0, "127.0.0.1", () => r())); + const addr = server.address() as { port: number }; + return { server, url: `http://127.0.0.1:${addr.port}` }; +} + +function openAiBody(content: string): object { + return { choices: [{ message: { role: "assistant", content }, finish_reason: "stop" }] }; +} + +function makePlan(url: string): ConfiguredSummaryPlan { + return new ConfiguredSummaryPlan({ enabled: true, targets: [{ name: "sm", protocol: "openai", url, model: "sm", apiKey: "k" }] }); +} + +function makeDeps(core: ReturnType, session: Session, config: ResolvedKernelConfig, summaryUrl: string, logs: string[]): PreflightDeps { + return { + core, session, config, prompts: defaultPrompts, protocol: "responses", + url: "http://127.0.0.1:9/v1/chat/completions", headers: {}, model: "test", + externalSummary: makePlan(summaryUrl), log: (_l, m) => { logs.push(m); }, + }; +} + +test("#3663: a failed distillation dispatch is visible in the detail as an attempt, not '0 calls'", async () => { + const { core, config, messages, session } = buildFixture({ limit: 12_000, blockCount: 6, blockChars: 18_000, tailChars: 200 }); + const { server, url } = await startJsonUpstream(500, { error: { message: "summarizer upstream exploded" } }); + try { + const logs: string[] = []; + const result = await preflightCompress(makeDeps(core, session, config, url, logs), messages); + assert.ok(result.failure, `the fully-failed recovery must end in a failure verdict (got fitsWindow=${result.fitsWindow})`); + const detail = result.failure.detail ?? ""; + assert.match(detail, /0 of 1 attempted summary call\(s\) completed/, + `a dispatched-but-failed distillation must be counted as an attempt (got: ${detail})`); + assert.match(detail, /the distillation summary was unavailable/, `the unavailable cause must be named (got: ${detail})`); + // A failed dispatch surfaces either as a thrown relay error or as an + // unusable outcome (e.g. an upstream 500 body) — both stop recovery the + // same way and both must leave a warn trace. + assert.ok(logs.some((l) => /tier-\d->\d+ distillation (summary call failed|produced no usable summary)/.test(l)), `the warn log must record the failed dispatch (logs: ${logs.join(" | ")})`); + } finally { + server.close(); + } +}); + +test("#3663: completed-only recoveries keep the historical '(N summary call(s)' phrasing", async () => { + // Every distillation returns a summary just under maxSummaryLength (20000 + // chars → 19600 chars ≈ 4900 tokens): usable by the executor's length gates + // yet heavy enough that NO sequence of successful distillations can pull + // the payload under the 4800-token window — the round ends futile with + // every dispatched call COMPLETED, exactly the case that must read like it + // always did. (An over-cap summary is rejected as invalid before apply, + // which would exercise the failure path instead.) + const { core, config, messages, session } = buildFixture({ limit: 4_800, blockCount: 6, blockChars: 18_000, tailChars: 200 }); + const { server, url } = await startJsonUpstream(200, openAiBody(filler(19_600, "HEAVYSUMMARY"))); + try { + const logs: string[] = []; + const result = await preflightCompress(makeDeps(core, session, config, url, logs), messages); + assert.ok(result.failure, `heavy summaries can never close the gap — expect a failure verdict (got fitsWindow=${result.fitsWindow})`); + const detail = result.failure.detail ?? ""; + assert.match(detail, /\(\d+ summary call\(s\), net ~\d+ tokens saved\)/, + `completed-only recovery must keep the historical phrasing (got: ${detail})`); + assert.ok(!detail.includes("attempted"), `no dispatch failed — the attempted-vs-completed split must not appear (got: ${detail})`); + } finally { + server.close(); + } +}); From d146325542d32617a7b2d8b8910b554dfc7a091b Mon Sep 17 00:00:00 2001 From: ci-check Date: Sun, 25 Oct 2026 04:57:47 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20de-export=20ClientBuildCheck=20?= =?UTF-8?q?=E2=80=94=20internal-only=20type=20trips=20the=20unused-exports?= =?UTF-8?q?=20gate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Inherited master red (tip 146b34f27): the per-lane check shape is referenced only inside client-build-note.ts (callers use DSH_BUILD_CHECK structurally). Same one-line fix as PR #4606 commit 1 (#4599); drop this commit when rebased onto post-#4606 master. --- src/agent/client-build-note.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/agent/client-build-note.ts b/src/agent/client-build-note.ts index 8ca7e9ddaf..6c08149309 100644 --- a/src/agent/client-build-note.ts +++ b/src/agent/client-build-note.ts @@ -29,7 +29,7 @@ import path from "node:path"; import { isVersionNewer } from "../update.js"; import { logHostEvent } from "./host-log.js"; -export type ClientBuildCheck = { +type ClientBuildCheck = { /** Short human label used in the note text ("dsh", "pi", ...). */ label: string; /** The client's npm id, as shown in the note (@deepseek-ai/dsh, ...). */ From 7f4e0877dd1d043dc656a70e990e99d9f224ad60 Mon Sep 17 00:00:00 2001 From: ci-check Date: Sat, 14 Nov 2026 00:58:23 +0800 Subject: [PATCH 3/3] =?UTF-8?q?test(#3663):=20update=20#737=20e2e=20to=20t?= =?UTF-8?q?he=20relabeled=20headroom=20wall=20=E2=80=94=20'effective=20inp?= =?UTF-8?q?ut=20budget=207500',=20not=20'model=20window=207500'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The #3663 change (buildEffectiveWallClause) intentionally relabels a headroom-reserved wall from 'the model window N' to 'the effective input budget N (model window NATIVE, ... reserved ...)'. The pre-existing #737 e2e in tests/preflight-fail-fast.test.ts still asserted the old substring 'model window 7500', which no longer appears — the message now reads 'the effective input budget 7500 (model window 10000, 2500 tokens reserved ...)'. The test's intent (prove the headroom path was exercised: the cited wall is 7500, not the declared 10000) is preserved by asserting the new substring; the other #737 guards (no shrink note, no compress.modelContextLimit blame) are unchanged and still hold. --- tests/preflight-fail-fast.test.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/preflight-fail-fast.test.ts b/tests/preflight-fail-fast.test.ts index b2714dd509..9807182fe2 100644 --- a/tests/preflight-fail-fast.test.ts +++ b/tests/preflight-fail-fast.test.ts @@ -565,11 +565,13 @@ test("e2e #737: output-headroom-shrunk window (non-Anthropic, no operator overri assert.equal(json.error?.code, "preflight_compress_failed"); const msg = json.error?.message ?? ""; assert.ok(msg.includes("NOT forwarded"), `payload withheld (got: ${msg})`); - // Proves the headroom path was exercised: the reported window is the - // 7500 after the #896-capped headroom reservation (min(max_tokens, + // Proves the headroom path was exercised: the cited wall is the 7500 + // after the #896-capped headroom reservation (min(max_tokens, // outputHeadroomMaxPct·window) = min(4000, 2500) = 2500 off 10000), not - // the declared 10000. - assert.ok(msg.includes("model window 7500"), `effective window reflects headroom reservation (got: ${msg})`); + // the declared 10000. #3663 relabels that wall "the effective input + // budget" (naming the native window + the reservation) instead of + // "the model window". + assert.ok(msg.includes("effective input budget 7500"), `effective window reflects headroom reservation (got: ${msg})`); // Regression guard: the reduction here came from output-headroom, NOT an // operator setting — the shrink note must stay silent. assert.ok(!msg.includes("full window"), `no shrink note for a headroom-shrunk window (got: ${msg})`);