Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ This index is generated from `website/config-reference/*.yaml` — edit the seed
| `compress.reasoningGuard` | object | off | — | Auto-repair of reasoning-lattice truncation on gpt-5.x/6.x (up to 3 continue-nudge rounds). |
| `compress.outputSteering` | object { enabled?, verbosityLevel?, effortRouting? } | enabled false · verbosityLevel 2 | — | Appends a conciseness directive to the system-prompt tail; clamps mechanical continuation requests. |
| `compress.priceProfile` | { w?, r?, q? } | unset (registry, kernel fallback {1, 0.1, 4}) | — | w/r/q ratios normalized to the input price (write/cache-read/output); report-only — never affects triggers or the wire. |
| `compress.externalSummary` | object | opt-in (disabled) | — | Sends compression summaries to separately configured models referenced from the providers table; whole-chain replace semantics at all three compress levels. |
| `compress.acknowledgePromptsRisk` | boolean | false | — | Must be true before custom prompts take effect. |
| `compress.absorb.enabled` | boolean | false | — | Enable the absorb distillation block. |
| `compress.absorb.minToolTokens` | number | 1000 | — | Minimum estimated token size of a tool result eligible for absorption. |
Expand Down
1 change: 1 addition & 0 deletions CONFIGURATION.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@
| `compress.reasoningGuard` | object | off | — | gpt-5.x/6.x 推理格截断自动修复(最多 3 轮继续提示)。 |
| `compress.outputSteering` | object { enabled?, verbosityLevel?, effortRouting? } | enabled false · verbosityLevel 2 | — | 向系统提示词尾部附加简洁度指令;只收紧机械延续请求。 |
| `compress.priceProfile` | { w?, r?, q? } | unset (registry, kernel fallback {1, 0.1, 4}) | — | w/r/q 相对输入价的比率(写入/缓存读/输出);仅供报告,不影响触发条件或线上行为。 |
| `compress.externalSummary` | object | opt-in (disabled) | — | 把压缩摘要交给 providers 表引用的独立配置模型;三级 compress 均为整链替换语义。 |
| `compress.acknowledgePromptsRisk` | boolean | false | — | 必须先置 true,自定义 prompts 才会生效。 |
| `compress.absorb.enabled` | boolean | false | — | 启用 absorb 蒸馏块。 |
| `compress.absorb.minToolTokens` | number | 1000 | — | 可被吸收的工具结果的最小估算 token 大小。 |
Expand Down
39 changes: 29 additions & 10 deletions scripts/config-surface-guard.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,36 @@ function namedTypeBodies(src) {
}

// Extract the quoted identifiers of `const <varName> = new Set([ ... ]);`.
// Anchored on the initializer, NOT the first mention of the name: a
// use-before-declaration earlier in the file would otherwise hijack the scan,
// and the naive first-`]` stop then lands inside whatever bracketed text
// follows (e.g. a template literal's `[${…}]`), producing phantom members
// (#3680 review: the route-root warning call site preceded the declaration
// and the extraction collapsed to one empty string).
export function extractStringSet(src, varName) {
const i = src.indexOf(varName);
if (i < 0) throw new Error(varName + " not found");
const open = src.indexOf("[", i);
const close = src.indexOf("]", open);
const inner = src.slice(open + 1, close);
const out = [];
const re = /["']([^"']+)["']/g;
let m;
while ((m = re.exec(inner))) out.push(m[1]);
return out;
const m = new RegExp(`(?:const|let|var)\\s+${varName}\\s*=\\s*new\\s+Set\\s*\\(\\s*\\[`).exec(src);
if (!m) throw new Error(varName + " not found");
const open = m.index + m[0].length - 1;
let depth = 0;
let inStr = null;
for (let i = open; i < src.length; i++) {
const c = src[i];
if (inStr) { if (c === inStr && src[i - 1] !== "\\") inStr = null; continue; }
if (c === "'" || c === '"') { inStr = c; continue; }
if (c === "[") depth++;
else if (c === "]") {
depth--;
if (depth === 0) {
const inner = src.slice(open + 1, i);
const out = [];
const re = /["']([^"']+)["']/g;
let mm;
while ((mm = re.exec(inner))) out.push(mm[1]);
return out;
}
}
}
throw new Error("unbalanced Set literal for " + varName);
}

// ---- config-file leaf extraction --------------------------------------------
Expand Down
26 changes: 25 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,26 @@ function warnInertRoutingFields(key: string, obj: Record<string, unknown> | null
);
}

/** #3675: compress-block keys written on the ROUTE ROOT (URL lane or named
* entry) are silently dropped by parseRouteEntry — the same silent-inert
* class as the #1469 routing fields, one level down. Recognition is
* COMPRESS_SETTING_FIELDS (defined below; kept in sync with
* parseCompressSettings): every member is inert at a route root, and none of
* them may be added to parseRouteEntry's whitelist while this warning exists.
* Dialing recipes are skipped — their own parser rejects unknown root fields
* loudly (parseNamedProviderRecipe throws → chain disabled with a warning),
* so a second signal here would only add noise. */
function warnCompressOnlyFieldsAtRouteRoot(key: string, obj: Record<string, unknown> | null): void {
if (!obj) return;
if (obj.baseUrl !== undefined || obj.api !== undefined) return;
const misplaced = Object.keys(obj).filter((f) => obj[f] !== undefined && COMPRESS_SETTING_FIELDS.has(f));
if (misplaced.length === 0) return;
warnNamedProviderOnce(
`route-root-compress:${key}:${misplaced.join(",")}`,
`providers."${key}" carries compress-block keys [${misplaced.join(", ")}] at the route root — they are inert there (move them under providers."${key}".compress to apply)`,
);
}

/** True when the providers-map key is itself a URL lane (http/https/mitm
* scheme — mitm:// is the README-documented lookup key for MITM traffic).
* Anything else is a NAMED key (provider id): routing-inert on its own,
Expand Down Expand Up @@ -1127,6 +1147,10 @@ export function loadRoutes(env: NodeJS.ProcessEnv = process.env): ProviderRoutes
if (!route) return;
const obj = value && typeof value === "object" && !Array.isArray(value) ? value as Record<string, unknown> : null;
const urlLike = isUrlLikeKey(key);
// Before the bind branch on purpose: these keys are inert even on a
// validly bound alias — parseRouteEntry never parses them, so the
// fold onto the target lane cannot carry them.
warnCompressOnlyFieldsAtRouteRoot(key, obj);
if (obj && "bind" in obj) {
const bind = obj.bind;
if (typeof bind !== "string") {
Expand Down Expand Up @@ -2003,7 +2027,7 @@ const COMPRESS_SETTING_FIELDS = new Set([
"visibilityMarkers", "rules", "injectTool", "injectNudge",
"acknowledgePromptsRisk", "absorb", "ccr", "search",
"prompts", "promptPack", "reasoningGuard", "outputSteering", "priceProfile",
"reconcile", "streamSummary",
"reconcile", "streamSummary", "externalSummary",
]);

// Deduped per unique key set per process (same pattern as
Expand Down
14 changes: 14 additions & 0 deletions tests/config-surface-guard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
stripComments,
extractConfigLeaves,
extractCliFlags,
extractStringSet,
runChecks,
} from "../scripts/config-surface-guard.mjs";

Expand Down Expand Up @@ -70,6 +71,19 @@ test("a planted undocumented CLI flag is caught", () => {
assert.ok(!missing.includes("--port"), "documented flag must not be flagged");
});

test("extractStringSet anchors on the initializer, not an earlier mention (#3680)", () => {
// The route-root warning call site preceded the COMPRESS_SETTING_FIELDS
// declaration, and its message carries `[${…}]` — the old first-mention +
// first-`]` scan collapsed to one empty string there.
const src =
"function warnMisplaced(key: string): void {\n" +
' const misplaced = Object.keys(key).filter((f) => f !== undefined && COMPRESS_SETTING_FIELDS.has(f));\n' +
' log(`carries compress-block keys [${misplaced.join(", ")}] at the route root`);\n' +
"}\n" +
'const COMPRESS_SETTING_FIELDS = new Set([ "tiers", "modelContextLimit" ]);\n';
assert.deepEqual(extractStringSet(src, "COMPRESS_SETTING_FIELDS"), ["tiers", "modelContextLimit"]);
});

test("stripComments keeps string contents, drops comments", () => {
const out = stripComments('let a = "// not a comment"; // real comment\n/* block */ let b = "x";');
assert.ok(out.includes('"// not a comment"'), "string content must survive");
Expand Down
98 changes: 98 additions & 0 deletions tests/named-provider-bind.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,104 @@ test("web config API round-trips named entries verbatim (no silent drop)", async
assert.deepEqual(loadRoutes()["https://api.anthropic.com"]?.compress, { maxContextLimitPct: 0.75 });
});

test("compress-block keys at a URL route root warn instead of sitting silently (#3675)", (t) => {
const warnings = captureWarnings(t);
withConfigFile(t, {
"https://cap.example": {
modelContextLimit: 1000000,
outputHeadroomMaxPct: 0.15,
models: { m1: { context: 200000 } },
},
});
const routes = loadRoutes();
assert.deepEqual(Object.keys(routes), ["https://cap.example"]);
assert.equal(routes["https://cap.example"].models?.m1?.context, 200000);
assert.equal(routes["https://cap.example"].compress, undefined);
assert.equal(warnings.length, 1);
for (const needle of ['"https://cap.example"', "modelContextLimit", "outputHeadroomMaxPct", '.compress']) {
assert.ok(warnings[0].includes(needle), `warning should mention ${needle}: ${warnings[0]}`);
}
});

test("bound alias: compress-block keys at its root stay inert through the fold and warn (#3675)", (t) => {
const warnings = captureWarnings(t);
withConfigFile(t, {
capBridge: {
bind: "https://cap-bound.example",
modelContextLimit: 500000,
nudgeGrowthTokens: 77777,
compress: { maxContextLimitPct: 0.7 },
},
});
const laneRaw = loadRoutes()["https://cap-bound.example"] as Record<string, unknown> | undefined;
assert.ok(laneRaw);
assert.equal((laneRaw.compress as Record<string, unknown> | undefined)?.maxContextLimitPct, 0.7);
assert.equal(laneRaw.modelContextLimit, undefined);
assert.equal(laneRaw.nudgeGrowthTokens, undefined);
assert.equal(warnings.length, 1);
for (const needle of ['"capBridge"', "modelContextLimit", "nudgeGrowthTokens"]) {
assert.ok(warnings[0].includes(needle), `warning should mention ${needle}: ${warnings[0]}`);
}
});

test("named entry whose only fields are compress-block keys: previously zero warnings, now one (#3675)", (t) => {
const warnings = captureWarnings(t);
withConfigFile(t, {
capLonely: { outputHeadroomMaxPct: 0.2 },
});
const routes = loadRoutes();
assert.ok("capLonely" in routes);
assert.equal(warnings.length, 1);
assert.ok(warnings[0].includes('"capLonely"') && warnings[0].includes("outputHeadroomMaxPct"), warnings[0]);
});

test("dialing recipes keep their own loud rejection — no duplicate route-root warning (#3675)", (t) => {
const warnings = captureWarnings(t);
withConfigFile(t, {
glmLane: {
baseUrl: "https://glm.example",
api: "openai",
apiKeyEnv: "GLM_KEY",
models: { g1: { contextWindow: 100000 } },
modelContextLimit: 1000000,
},
});
loadRoutes();
assert.deepEqual(warnings, []);
});

test("route-root compress-key warning fires once per signature across reloads (#3675)", (t) => {
const warnings = captureWarnings(t);
withConfigFile(t, { "https://cap-reload.example": { modelContextLimit: 250000 } });
loadRoutes();
loadRoutes();
loadRoutes();
assert.equal(warnings.filter((w) => w.includes('"https://cap-reload.example"')).length, 1);
});

test("route-root externalSummary warns like every other compress-block key (#3876)", (t) => {
const warnings = captureWarnings(t);
withConfigFile(t, {
capSum: { externalSummary: { enabled: true, targets: ["glm/glm-4.9-flash"] } },
});
const routes = loadRoutes();
assert.ok("capSum" in routes);
assert.equal(routes["capSum"].compress, undefined, "the inert root field must not leak into a compress block");
assert.equal(warnings.length, 1);
for (const needle of ['"capSum"', "externalSummary", ".compress"]) {
assert.ok(warnings[0].includes(needle), `warning should mention ${needle}: ${warnings[0]}`);
}
});

test("externalSummary under compress (the right place) produces no route-root complaint (#3876)", (t) => {
const warnings = captureWarnings(t);
withConfigFile(t, {
capSumOk: { compress: { externalSummary: { enabled: false } } },
});
loadRoutes();
assert.ok(!warnings.some((w) => w.includes("externalSummary")), `no route-root complaint expected for a correctly placed chain: ${warnings.join(" | ")}`);
});

test("web config API still rejects legacy, invalid-proxy, and non-object entries", async (t) => {
captureWarnings(t);
withConfigFile(t, {});
Expand Down
10 changes: 10 additions & 0 deletions website/config-reference/compress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,16 @@ entries:
desc_zh: "w/r/q 相对输入价的比率(写入/缓存读/输出);仅供报告,不影响触发条件或线上行为。"
site_en: "<code>priceProfile</code> — <span class='mech'>w / r / q</span> ratios normalized to the input price (write / cache-read / output); unset ⇒ models.dev $/Mtok registry rows, kernel fallback {1, 0.1, 4}. Report-only — never affects triggers or the wire."
site_zh: "<code>priceProfile</code> —— <span class='mech'>w / r / q</span> 相对输入价的比率(写入/缓存读/输出);未设置 ⇒ 取 models.dev $/Mtok 注册表行,内核兜底 {1, 0.1, 4}。仅供报告,不影响触发条件或线上行为。"
- key: compress.externalSummary
type: object
default: "opt-in (disabled)"
group: compress
id: co.es
render: obj-item
desc_en: "Sends compression summaries to separately configured models referenced from the providers table; whole-chain replace semantics at all three compress levels."
desc_zh: "把压缩摘要交给 providers 表引用的独立配置模型;三级 compress 均为整链替换语义。"
site_en: "<code>externalSummary</code> — optional chain of external summary models, each target a \"provider/model\" reference into the <code>providers</code> table; disabled unless <code>enabled</code> is true, targets tried in order with fall-through (<span class='mech'>enabled, targets, budget {totalTimeoutMs, targetTimeoutMs, maxSummaryBytes}, concurrency, autoFold, autoFoldTargetTokens</span>). Whole-chain replace semantics at all three compress levels."
site_zh: "<code>externalSummary</code> —— 可选的外部摘要模型链,每个目标为指向 <code>providers</code> 表的 \"provider/model\" 引用;<code>enabled</code> 为 true 才启用,目标按顺序尝试、失败落到下一个(<span class='mech'>enabled, targets, budget {totalTimeoutMs, targetTimeoutMs, maxSummaryBytes}, concurrency, autoFold, autoFoldTargetTokens</span>)。三级 compress 均为整链替换语义。"
- key: compress.acknowledgePromptsRisk
type: boolean
default: "false"
Expand Down
1 change: 1 addition & 0 deletions website/docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ <h3 data-i18n="d.cf.t_compress">compress — every knob</h3>
<li data-i18n-html="co.rg"><code>reasoningGuard</code> — auto-repair of reasoning-lattice truncation on gpt-5.x/6.x (≤3 continue-nudge rounds, marker "Continue thinking...") (<span class='mech'>enabled, maxContinue, maxTierN, markerText, base, offset, debugLog</span>).</li>
<li data-i18n-html="co.os"><code>outputSteering</code> — <span class='mech'>{ enabled? false, verbosityLevel? 2 (0–4), effortRouting? }</span>: appends a conciseness directive to the system-prompt tail; clamps mechanical continuation requests.</li>
<li data-i18n-html="co.pp"><code>priceProfile</code> — <span class='mech'>w / r / q</span> ratios normalized to the input price (write / cache-read / output); unset ⇒ models.dev $/Mtok registry rows, kernel fallback {1, 0.1, 4}. Report-only — never affects triggers or the wire.</li>
<li data-i18n-html="co.es"><code>externalSummary</code> — optional chain of external summary models, each target a "provider/model" reference into the <code>providers</code> table; disabled unless <code>enabled</code> is true, targets tried in order with fall-through (<span class='mech'>enabled, targets, budget {totalTimeoutMs, targetTimeoutMs, maxSummaryBytes}, concurrency, autoFold, autoFoldTargetTokens</span>). Whole-chain replace semantics at all three compress levels.</li>
<li data-i18n-html="co.apr"><code>acknowledgePromptsRisk</code> — must be true before custom prompts take effect.</li>
<!-- /bili:gen -->
</ul>
Expand Down
2 changes: 2 additions & 0 deletions website/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"co.rg": "<code>reasoningGuard</code> — auto-repair of reasoning-lattice truncation on gpt-5.x/6.x (≤3 continue-nudge rounds, marker \"Continue thinking...\") (<span class='mech'>enabled, maxContinue, maxTierN, markerText, base, offset, debugLog</span>).",
"co.os": "<code>outputSteering</code> — <span class='mech'>{ enabled? false, verbosityLevel? 2 (0–4), effortRouting? }</span>: appends a conciseness directive to the system-prompt tail; clamps mechanical continuation requests.",
"co.pp": "<code>priceProfile</code> — <span class='mech'>w / r / q</span> ratios normalized to the input price (write / cache-read / output); unset ⇒ models.dev $/Mtok registry rows, kernel fallback {1, 0.1, 4}. Report-only — never affects triggers or the wire.",
"co.es": "<code>externalSummary</code> — optional chain of external summary models, each target a \"provider/model\" reference into the <code>providers</code> table; disabled unless <code>enabled</code> is true, targets tried in order with fall-through (<span class='mech'>enabled, targets, budget {totalTimeoutMs, targetTimeoutMs, maxSummaryBytes}, concurrency, autoFold, autoFoldTargetTokens</span>). Whole-chain replace semantics at all three compress levels.",
"co.apr": "<code>acknowledgePromptsRisk</code> — must be true before custom prompts take effect.",
"cr.models": "Record of model name → <span class='mech'>{context?, output?, compress?, benefit?}</span>: declares each model's context window, output ceiling, and per-model compression overrides (benefit marks free-quota billing). Not a traffic filter.",
"cr.proxy": "Per-route outbound proxy URL; empty string = explicitly direct.",
Expand Down Expand Up @@ -336,6 +337,7 @@
"co.rg": "<code>reasoningGuard</code> —— gpt-5.x/6.x 推理格截断自动修复(≤3 轮继续提示,标记 \"Continue thinking...\")(<span class='mech'>enabled, maxContinue, maxTierN, markerText, base, offset, debugLog</span>)。",
"co.os": "<code>outputSteering</code> —— <span class='mech'>{ enabled? false, verbosityLevel? 2 (0–4), effortRouting? }</span>:向系统提示词尾部附加简洁度指令;只收紧机械延续请求。",
"co.pp": "<code>priceProfile</code> —— <span class='mech'>w / r / q</span> 相对输入价的比率(写入/缓存读/输出);未设置 ⇒ 取 models.dev $/Mtok 注册表行,内核兜底 {1, 0.1, 4}。仅供报告,不影响触发条件或线上行为。",
"co.es": "<code>externalSummary</code> —— 可选的外部摘要模型链,每个目标为指向 <code>providers</code> 表的 \"provider/model\" 引用;<code>enabled</code> 为 true 才启用,目标按顺序尝试、失败落到下一个(<span class='mech'>enabled, targets, budget {totalTimeoutMs, targetTimeoutMs, maxSummaryBytes}, concurrency, autoFold, autoFoldTargetTokens</span>)。三级 compress 均为整链替换语义。",
"co.apr": "<code>acknowledgePromptsRisk</code> —— 必须先置 true,自定义 prompts 才会生效。",
"cr.models": "模型名 → <span class='mech'>{context?, output?, compress?, benefit?}</span> 的记录:声明每个模型的上下文窗口、输出上限与逐模型压缩覆盖(benefit 标记免费额度计费)。不是流量过滤器。",
"cr.proxy": "本路由出站代理地址;空字符串 = 显式直连。",
Expand Down
Loading