From 00edf61b6a7676fec1a0bb44d105469120131829 Mon Sep 17 00:00:00 2001 From: ci-check Date: Tue, 17 Nov 2026 04:40:43 +0800 Subject: [PATCH] fix: name the oversized top-level field in the egress-fuse breakdown (#6957) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The #554 guard meter splits the outbound body into messages/tools/system/other, but the 'other' bucket was an opaque aggregate — a 1.6M-token 'other' (#6957, the dsh→official-DeepSeek wire put the mass in a top-level field bili's messages-only compression can never touch) told the operator a dimension was oversized without saying WHICH field, so the doom message's 'trim the oversized dimension' was unactionable and the session sat in an egress-fuse dead loop. estimateRawBodyBreakdown now tracks the top-level field(s) carrying the 'other' mass (otherTop, sorted desc, exhaustive over the bucket) and measuredBreakdownClause names the top-3 in the fuse/doom messages when 'other' carries real mass. Additive: total/messages/tools/system/other are unchanged, so the existing bucket tests and the regex-anchored doom-message tests keep passing. Also documents the #6956 market-disable path in dsh.bundle.patch.yml: the dsh plugin-market 'disable' toggle kills BOTH entries (bili-native AND the gate) at once, so the gate service never registers, the presets' inject latch is unsatisfiable, and the host reports preset-ptc as not-found, bricking new-conversation init. That is a DSH-side defect (an unsatisfiable inject must degrade, not hang); the supported off-switches are disabling bili-native only (#3662) or removing billion-context from bundles (#6972). Closes #6957 --- dsh.bundle.patch.yml | 9 ++++++ src/preflight.ts | 28 ++++++++++++---- src/server.ts | 11 ++++++- tests/raw-body-walk-depth.test.ts | 2 +- tests/side-request-isolation.test.ts | 48 +++++++++++++++++++++++++++- 5 files changed, 88 insertions(+), 10 deletions(-) diff --git a/dsh.bundle.patch.yml b/dsh.bundle.patch.yml index d7b815f249..c8ea4166b5 100644 --- a/dsh.bundle.patch.yml +++ b/dsh.bundle.patch.yml @@ -18,6 +18,15 @@ # disable the bili-compaction-gate entry itself: it carries the service the # presets wait on; to uninstall, remove billion-context from # dsh.profile.bundles instead. +# #6956: the dsh PLUGIN-MARKET "disable" toggle kills BOTH entries (bili-native +# AND the gate) at once — the gate service then never registers, the presets' +# inject [biliBasicCompactionPolicy] latch is unsatisfiable, and the host +# reports preset-ptc (the default) as not-found, bricking new-conversation +# init. That is a DSH-side defect (an unsatisfiable inject must degrade, not +# hang); the in-repo surface is this note + the docs/clients.md "Disabling vs +# removing" pointer. The supported off-switches are: disable bili-native ONLY +# (gate stays alive, #3662) or remove billion-context from bundles (uninstall, +# #6972). - insert: - id: bili-native name: billion-context diff --git a/src/preflight.ts b/src/preflight.ts index ebe8d88b87..1c6cbaff7b 100644 --- a/src/preflight.ts +++ b/src/preflight.ts @@ -515,40 +515,54 @@ export interface RawBodyBreakdown { tools: number; system: number; other: number; + /** #6957: the top-level field(s) carrying the "other" mass, sorted desc by + * tokens. Empty when "other" is 0 or the body is not a top-level object. + * Makes a 1.6M-token "other" actionable: the operator sees WHICH field. */ + otherTop: { field: string; tokens: number }[]; } export function estimateRawBodyBreakdown(parsed: unknown): RawBodyBreakdown { const buckets: [number, number, number, number] = [0, 0, 0, 0]; // messages, tools, system, other - const pending: [unknown, string | undefined, number][] = []; + const otherTop = new Map(); + const pending: [unknown, string | undefined, number, string | undefined][] = []; if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) { for (const [k, v] of Object.entries(parsed as Record)) { if (isNonModelTopLevelKey(k)) continue; const bucket = k === "messages" ? 0 : k === "tools" ? 1 : k === "system" ? 2 : 3; - pending.push([v, k, bucket]); + pending.push([v, k, bucket, bucket === 3 ? k : undefined]); } } else { - pending.push([parsed, undefined, 3]); + pending.push([parsed, undefined, 3, undefined]); } while (pending.length > 0) { - const [value, key, bucket] = pending.pop()!; + const [value, key, bucket, topField] = pending.pop()!; if (typeof value === "string") { - if (!key || !NON_TEXT_BODY_KEYS.has(key)) buckets[bucket] += defaultCountTokens(value); + if (!key || !NON_TEXT_BODY_KEYS.has(key)) { + const t = defaultCountTokens(value); + buckets[bucket] += t; + if (topField !== undefined) otherTop.set(topField, (otherTop.get(topField) ?? 0) + t); + } continue; } if (Array.isArray(value)) { - for (const item of value) pending.push([item, key, bucket]); + for (const item of value) pending.push([item, key, bucket, topField]); continue; } if (value && typeof value === "object") { - for (const [k, v] of Object.entries(value as Record)) pending.push([v, k, bucket]); + for (const [k, v] of Object.entries(value as Record)) pending.push([v, k, bucket, topField]); } } + const otherTopArr = [...otherTop.entries()] + .filter(([, t]) => t > 0) + .sort((a, b) => b[1] - a[1]) + .map(([field, tokens]) => ({ field, tokens })); return { total: buckets[0] + buckets[1] + buckets[2] + buckets[3], messages: buckets[0], tools: buckets[1], system: buckets[2], other: buckets[3], + otherTop: otherTopArr, }; } diff --git a/src/server.ts b/src/server.ts index 82cf750c8a..172c89f7c6 100644 --- a/src/server.ts +++ b/src/server.ts @@ -3787,7 +3787,16 @@ interface MeasuredOutbound { // operator WHERE (a 55.2 MiB #5000 body with 1.44 MiB of messages[] means the // mass is tools[], not a giant paste). export function measuredBreakdownClause(b: RawBodyBreakdown): string { - return `messages ~${b.messages.toLocaleString("en-US")} · tools[] ~${b.tools.toLocaleString("en-US")} · system ~${b.system.toLocaleString("en-US")} · other ~${b.other.toLocaleString("en-US")}`; + let s = `messages ~${b.messages.toLocaleString("en-US")} · tools[] ~${b.tools.toLocaleString("en-US")} · system ~${b.system.toLocaleString("en-US")} · other ~${b.other.toLocaleString("en-US")}`; + // #6957: when "other" carries real mass, name the specific top-level field(s) + // so the operator knows WHERE to look — a 1.6M-token "other" is only actionable + // if it says which field (the dsh→official-DeepSeek wire put the mass in a + // top-level field bili's messages-only compression can never touch). + if (b.other > 0 && b.otherTop.length > 0) { + const top = b.otherTop.slice(0, 3).map((e) => `${e.field} ~${e.tokens.toLocaleString("en-US")}`).join(", "); + s += ` (other: ${top})`; + } + return s; } export function measuredOutbound(prepared: { body: string | Buffer; parsedBody?: unknown }): MeasuredOutbound | undefined { diff --git a/tests/raw-body-walk-depth.test.ts b/tests/raw-body-walk-depth.test.ts index 3357d5277d..6e52446329 100644 --- a/tests/raw-body-walk-depth.test.ts +++ b/tests/raw-body-walk-depth.test.ts @@ -81,6 +81,6 @@ test("shallow plumbing: exclusion set, key inheritance and bucket split stay int test("non-object top-level bodies land whole in the other bucket", () => { const bd = estimateRawBodyBreakdown("plain string body"); - assert.deepEqual(bd, { total: t("plain string body"), messages: 0, tools: 0, system: 0, other: t("plain string body") }); + assert.deepEqual(bd, { total: t("plain string body"), messages: 0, tools: 0, system: 0, other: t("plain string body"), otherTop: [] }); assert.equal(estimateRawBodyTokens("plain string body"), t("plain string body")); }); diff --git a/tests/side-request-isolation.test.ts b/tests/side-request-isolation.test.ts index e14cdc10bd..bc8975aeed 100644 --- a/tests/side-request-isolation.test.ts +++ b/tests/side-request-isolation.test.ts @@ -3,7 +3,7 @@ import assert from "node:assert/strict"; import http from "node:http"; import { once } from "node:events"; import { defaultConfig, createInitialState, defaultCountTokens } from "acp-kernel"; -import { startServer, isSideRequest, isStructuredOutputCall, outputBudgetField, restoreOutputBudget, sideRequestGuard, resolveKnownOutputCeiling, _resetNoOutputCeilingWarningsForTest, _resetDshMidBandWarningsForTest, OUTPUT_RESTORE_ABSOLUTE_FLOOR } from "../src/server.ts"; +import { startServer, isSideRequest, isStructuredOutputCall, outputBudgetField, restoreOutputBudget, sideRequestGuard, resolveKnownOutputCeiling, _resetNoOutputCeilingWarningsForTest, _resetDshMidBandWarningsForTest, OUTPUT_RESTORE_ABSOLUTE_FLOOR, measuredBreakdownClause } from "../src/server.ts"; import { resolveSideLane, SIDE_REQUEST_MAX_TOKENS } from "../src/server/side-request.ts"; import type { ProxyOptions } from "../src/config.ts"; import { recordPluginRuntimeInfo, _resetPluginStateForTest } from "../src/plugin.ts"; @@ -618,6 +618,52 @@ test("estimateRawBodyBreakdown: splits the same total on the top-level field (#5 assert.equal(estimateRawBodyBreakdown("plain string").total, defaultCountTokens("plain string"), "bare string counts as other"); }); +test("estimateRawBodyBreakdown.otherTop: names the specific top-level field carrying the 'other' mass (#6957)", () => { + // The #6957 shape: a body whose mass rides a top-level field OTHER than + // messages/tools/system (the dsh→official-DeepSeek wire put ~1.6M tokens in + // an unknown top-level field). otherTop must name THAT field so the doom + // message is actionable. + const body = { + messages: [{ role: "user", content: "m".repeat(1_000) }], + tools: [{ type: "function", function: { name: "t", description: "d".repeat(1_000) } }], + system: "s".repeat(1_000), + // two "other" fields: the big one must sort first. + reasoning_history: "r".repeat(20_000), + metadata: "x".repeat(2_000), + }; + const b = estimateRawBodyBreakdown(body); + assert.ok(b.other > 0, "the two extra top-level fields land in the other bucket"); + assert.equal(b.otherTop.length, 2, "both 'other' top-level fields are named"); + assert.equal(b.otherTop[0].field, "reasoning_history", "the bigger field sorts first"); + assert.equal(b.otherTop[1].field, "metadata", "the smaller field follows"); + assert.ok(b.otherTop[0].tokens > b.otherTop[1].tokens, "sorted desc by tokens"); + // otherTop tokens sum to the other bucket (exhaustive within 'other'). + assert.equal(b.otherTop.reduce((s, e) => s + e.tokens, 0), b.other, "otherTop is exhaustive over the other bucket"); + // messages/tools/system fields never leak into otherTop. + assert.ok(!b.otherTop.some((e) => e.field === "messages" || e.field === "tools" || e.field === "system"), "named buckets stay out of otherTop"); + // a body with no 'other' mass has an empty otherTop. + const noOther = estimateRawBodyBreakdown({ messages: [{ role: "user", content: "m" }], system: "s" }); + assert.equal(noOther.otherTop.length, 0, "no other mass ⇒ empty otherTop"); + // a null body has an empty otherTop (no top-level object to name). + assert.equal(estimateRawBodyBreakdown(null).otherTop.length, 0, "null body ⇒ empty otherTop"); +}); + +test("measuredBreakdownClause: names the oversized 'other' field in the doom message (#6957)", () => { + // #6957: the doom message must say WHICH top-level field carries the "other" + // mass, so "trim the oversized dimension" is actionable. + const b = estimateRawBodyBreakdown({ + messages: [{ role: "user", content: "m".repeat(1_000) }], + system: "s".repeat(1_000), + reasoning_history: "r".repeat(20_000), + }); + const clause = measuredBreakdownClause(b); + assert.ok(clause.includes("other ~"), "the other bucket is still reported"); + assert.ok(clause.includes("reasoning_history"), "the oversized top-level field is named"); + // a body with no "other" mass gets no "(other: …)" suffix. + const noOther = estimateRawBodyBreakdown({ messages: [{ role: "user", content: "m" }], system: "s" }); + assert.ok(!measuredBreakdownClause(noOther).includes("(other:"), "no other mass ⇒ no field suffix"); +}); + test("inspectContextOverflow: exceed_context_size_error pattern + (A / B > W) window parse (#554)", () => { const llama = JSON.stringify({ error: { message: "exceed_context_size_error (198,277 / 198,661 > 150,528)" } }); const hit = inspectContextOverflow(400, llama);