diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 080dc4fc71..986036e0f5 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -498,7 +498,7 @@ Top-level keys that control how the proxy listens and behaves globally. - **Status:** ACTIVE - **Description:** The config-file surface of the #1884 re-sign arm (body-covering signatures; today Huawei CodeArts APIG's `SDK-HMAC-SHA256`). Detection is SHAPE-based, not a name whitelist (#2090): any `Authorization` scheme token naming an HMAC construction, or any request header ending in `-signature` / `-content-sha256`, marks the request as body-signed — every gateway invents its own header set (the dsh free-model plugin ships `x-ofm-signature`), and a closed list kept missing new shapes into silent upstream 401s that surfaced as "invalid credentials" in other plugins' UIs. What happens next depends on whether bili CAN re-sign the scheme: - **Built-in scheme with a resolvable credential** (dsh codearts account pool): the zero-config re-sign arm — on dsh it discovers enabled `codearts` accounts from `$DSH_HOME/jet-hub/state.json` through the credentials service and re-signs every egress body it produces, so compression works on signed upstreams out of the box. The built-in key's defaults ARE that behavior, which is why keying by scheme does not make this a Huawei-shaped field. - - **Every other detected scheme** (SigV4, gateway-invented headers): there is NO credential source anywhere in bili and NO re-signer implementation, so bili **refuses it — always** (owner binary-contract ruling, #2090: signed requests are either RE-SIGNED+COMPRESSED or REFUSED, never passed through unsigned). The 403 names the scheme and says plainly that no configuration can make the link work yet; each refusal is remembered in `resign-pending.json` under the state dir (`~/.local/state/billion-context/`) and replayed as a `[resign] … UNRESOLVED` banner at every later start (the dsh agent lane warns at plugin load too) until bili ships the scheme's re-signer. `passthrough` settings are INERT for these schemes — the reminder clears itself only when the branch is un-deployed (`enabled: false` / `BILI_RESIGN=0`, restoring pre-resign rewrite handling where the upstream will likely 401 again). + - **Every other detected scheme** (SigV4, gateway-invented headers): there is NO credential source anywhere in bili and NO re-signer implementation, so bili **refuses it — always** (owner binary-contract ruling, #2090: signed requests are either RE-SIGNED+COMPRESSED or REFUSED, never passed through unsigned). The 403 names the scheme and says plainly that no configuration can make the link work yet; each refusal is remembered in `resign-pending.json` under the state dir (`~/.local/state/billion-context/`) and replayed as a `[resign] … UNRESOLVED` banner at every later start (the dsh agent lane warns at plugin load too) until bili ships the scheme's re-signer. `passthrough` settings are INERT for these schemes — the reminder clears itself only when the branch is un-deployed (`enabled: false` / `BILI_RESIGN=0`, restoring pre-resign rewrite handling where the upstream will likely 401 again). Since v0.1.186 (#2260) such dead keys are additionally named once per dead-key set by an `[acp-config]` warning at config load, so the 403 body is no longer the only signal. This block is for the failure/override paths — env vars win over the file for every field: - `enabled: boolean` — kill switch for that scheme; `false` unloads the arm end to end (pre-fix behavior: signed bodies ride the normal rewrite path and fail upstream with 401). Env `BILI_RESIGN=0` wins. @@ -513,10 +513,10 @@ Top-level keys that control how the proxy listens and behaves globally. ```jsonc { - "resign": { - "sdk-hmac-sha256": { "passthrough": true }, - "aws4-hmac-sha256": { "passthrough": true } - } + "resign": { + "sdk-hmac-sha256": { "passthrough": true }, + "aws4-hmac-sha256": { "passthrough": true } // inert until bili ships its re-signer (#2090) — named once at config load + } } ``` diff --git a/CONFIGURATION.zh-CN.md b/CONFIGURATION.zh-CN.md index 65f0fd4fac..c3899ac632 100644 --- a/CONFIGURATION.zh-CN.md +++ b/CONFIGURATION.zh-CN.md @@ -498,7 +498,7 @@ - **状态:** ACTIVE - **说明:** #1884 重签臂的配置文件面(body 级签名;今天就是华为 CodeArts APIG 的 `SDK-HMAC-SHA256`)。检测是**形状判定**而非名字白名单(#2090):任何命名了 HMAC 构造的 `Authorization` 方案 token,或以 `-signature` / `-content-sha256` 结尾的请求头,都把该请求标记为 body 已签名 —— 每个网关都自造一套头(dsh 免费模型插件就是 `x-ofm-signature`),封闭名单会不断漏掉新形状,变成静默的上游 401,并在别的插件界面里显示成「凭据无效」。接下来发生什么取决于 bili 能否重签该方案: - **内置方案且能解析出凭据**(dsh codearts 账号池):零配置重签臂 —— 在 dsh 上它通过 credentials 服务从 `$DSH_HOME/jet-hub/state.json` 发现启用的 `codearts` 账号,并对自己产出的每个出站 body 重签,签名上游上的压缩开箱即用。内置键的默认值**就是**这套行为,所以按方案分键并不把这个字段做成华为特殊设计。 - - **其他任何被检测到的方案**(SigV4、网关自造头):bili 内部**既没有凭据来源,也没有重签器实现**,所以 bili **一律拒收**(owner 二元契约拍板,#2090:签名请求要么重签+压缩、要么拒绝,绝不无签名放行)。403 文案指明方案名并明说「目前没有任何配置能让这条链路工作」;每次拒收都会记进 state 目录下的 `resign-pending.json`(`~/.local/state/billion-context/`),此后每次启动 bili 都会打 `[resign] … UNRESOLVED` 横幅列出未解决项(dsh agent lane 在插件装载时也会警告),直到 bili 补上该方案的重签器。这些方案的 `passthrough` 设置**无效**——提醒只在分支被卸载(`enabled: false` / `BILI_RESIGN=0`,恢复 pre-resign 改写处理、上游大概率又 401)时自动清除。 + - **其他任何被检测到的方案**(SigV4、网关自造头):bili 内部**既没有凭据来源,也没有重签器实现**,所以 bili **一律拒收**(owner 二元契约拍板,#2090:签名请求要么重签+压缩、要么拒绝,绝不无签名放行)。403 文案指明方案名并明说「目前没有任何配置能让这条链路工作」;每次拒收都会记进 state 目录下的 `resign-pending.json`(`~/.local/state/billion-context/`),此后每次启动 bili 都会打 `[resign] … UNRESOLVED` 横幅列出未解决项(dsh agent lane 在插件装载时也会警告),直到 bili 补上该方案的重签器。这些方案的 `passthrough` 设置**无效**——提醒只在分支被卸载(`enabled: false` / `BILI_RESIGN=0`,恢复 pre-resign 改写处理、上游大概率又 401)时自动清除。自 v0.1.186(#2260)起,这类死键还会在配置加载时被一条 `[acp-config]` 警告点名(同一死键集合只报一次),403 文案不再是唯一信号。 本块只管失败/覆盖路径 —— 每个字段环境变量都优先于文件: - `enabled: boolean` —— 该方案的开关;`false` 整体卸载重签臂(回到修复前行为:带签名的请求照常改写、上游 401)。环境变量 `BILI_RESIGN=0` 优先。 @@ -515,7 +515,7 @@ { "resign": { "sdk-hmac-sha256": { "passthrough": true }, - "aws4-hmac-sha256": { "passthrough": true } + "aws4-hmac-sha256": { "passthrough": true } // 非内置方案无效(#2090)——配置加载时会被点名 } } ``` diff --git a/package-lock.json b/package-lock.json index 6e8d22dcdf..7a8747dff6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "billion-context", - "version": "0.1.185", + "version": "0.1.186", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "billion-context", - "version": "0.1.185", + "version": "0.1.186", "license": "MIT", "dependencies": { "zod": "4.1.8" @@ -45,25 +45,9 @@ "sharp": "^0.35.4" } }, - "../kernel-review": { - "name": "acp-kernel", - "version": "0.0.42", - "extraneous": true, - "license": "MIT", - "devDependencies": { - "@types/node": "^22.0.0", - "prettier": "^3.3.0", - "tsup": "^8.3.0", - "tsx": "^4.19.0", - "typescript": "^5.6.0" - }, - "engines": { - "node": ">=20" - } - }, "kernel": { "name": "acp-kernel", - "version": "0.0.103", + "version": "0.0.104", "dev": true, "license": "MIT", "devDependencies": { diff --git a/package.json b/package.json index 9a3168b6cc..a3cfb2e152 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "billion-context", - "version": "0.1.185", + "version": "0.1.186", "description": "A context-compression plugin — small context windows (a 100K context is enough), 5x fewer tokens, month-long single sessions (billions of tokens), and compression quality — for all agents: pi, OpenCode, Codex, Claude Code, and more. billion-context is all you need.", "type": "module", "main": "dist/index.js", diff --git a/release-notes/package.json b/release-notes/package.json index b993ee7878..1107dca885 100644 --- a/release-notes/package.json +++ b/release-notes/package.json @@ -9,8 +9,14 @@ }, "billionContextReleaseNotes": { "schema": 1, - "updated": "2026-10-05", + "updated": "2026-10-06", "releases": [ + { + "version": "0.1.186", + "date": "2026-10-06", + "tier": "critical", + "summary": "修复codex 启动器模式启动失败问题,修复claude code账号版本无法使用的问题,修复dsh重试不再泄漏挂死的代理子进程(#2187)。" + }, { "version": "0.1.185", "date": "2026-10-05", diff --git a/src/config.ts b/src/config.ts index a7a6a3a73e..c469c346ba 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1649,6 +1649,7 @@ export function loadConfigFile(): FileConfig { const obj = parsed as Record; normalizeLegacyAllowDshCompaction(obj); warnUnknownTopLevelKeys(obj); + warnInertResignPassthrough(obj); value = obj as FileConfig; } else { value = {}; @@ -1745,6 +1746,53 @@ export function resolveResignSettings(env: NodeJS.ProcessEnv = process.env, prov return { enabled, passthrough, credentialRef }; } +// #2260(B)/#2090: pre-v0.1.186 configs may carry `passthrough: true` under a +// NON-built-in scheme key. Since the compress-or-refuse contract the unsigned +// pass-through exists ONLY for sdk-hmac-sha256 (both guard sites gate on it), +// so such a key is inert while its requests stay refused — "my opt-in does +// nothing". Name the dead key(s) at config load instead of letting the 403 +// body be the only signal. Dedup by dead-key signature (#1815 style): re-warn +// when the set changes, stay quiet while it stays fixed or empty. +let inertResignPassthroughSignature: string | null = null; +export function warnInertResignPassthrough(obj: Record): void { + const inert: string[] = []; + const consider = (map: unknown, providerBlockFor: (key: string) => ResignFileSettings | undefined): void => { + if (!map || typeof map !== "object" || Array.isArray(map)) return; + for (const [key, val] of Object.entries(map as Record)) { + if (key === RESIGN_BUILTIN_SCHEME) continue; + const block = val !== null && typeof val === "object" && !Array.isArray(val) ? (val as Record) : {}; + if (block["passthrough"] !== true) continue; + // Same enabled cascade as resolveResignSettings (env > provider > + // file > default-true), read straight off the parsed object so the + // hook never re-enters loadConfigFile (it runs mid-parse). + const fileBlock = ((obj.resign as Record | undefined) ?? {})[key]; + const providerBlock = providerBlockFor(key); + const enabled = process.env.BILI_RESIGN !== undefined + ? process.env.BILI_RESIGN !== "0" + : providerBlock?.enabled !== undefined + ? providerBlock.enabled + : fileBlock?.enabled !== false; + if (enabled) inert.push(key); + } + }; + consider(obj.resign, () => undefined); + const providers = obj.providers; + if (providers && typeof providers === "object" && !Array.isArray(providers)) { + for (const entry of Object.values(providers as Record)) { + if (!entry || typeof entry !== "object" || Array.isArray(entry)) continue; + const pmap = (entry as Record).resign; + if (pmap === undefined) continue; + consider(pmap, (key) => ((pmap as Record | undefined) ?? {})[key]); + } + } + inert.sort(); + const sig = inert.join(","); + if (sig === "" || sig === inertResignPassthroughSignature) return; + inertResignPassthroughSignature = sig; + const list = inert.map((k) => `resign["${k}"].passthrough`).join(", "); + loggerLog("warn", `[acp-config] ${list}=true is INERT — since the #2090 compress-or-refuse contract, unsigned pass-through exists ONLY for the built-in scheme "${RESIGN_BUILTIN_SCHEME}"; those signed requests stay REFUSED until bili ships a re-signer for them. Restore pre-resign handling with resign[""].enabled=false or BILI_RESIGN=0 (the upstream will then reject the rewritten bodies).`); +} + /** #1660: the self-managed zone port base. Every launcher-spawned lane * binds here by default instead of an OS-assigned ephemeral port: a stable * origin survives instance death, and the proxy child's EADDRINUSE ladder diff --git a/src/server.ts b/src/server.ts index 5935c42fd3..4d33e37347 100644 --- a/src/server.ts +++ b/src/server.ts @@ -899,7 +899,7 @@ export async function startServer(opts: ProxyOptions): Promise { log( "warn", `[resign] ${entries.length} signed request scheme(s) were refused earlier and remain UNRESOLVED: ${list}. ` + - "Per the compress-or-refuse contract they stay refused until bili ships a re-signer for each of them — no configuration can pass a signed body through unsigned. Also listed in the web UI: http://${displayHost}:${actualPort}/__bili/ (Configuration → Signed upstreams). " + + `Per the compress-or-refuse contract they stay refused until bili ships a re-signer for each of them — no configuration can pass a signed body through unsigned. Also listed in the web UI: http://${displayHost}:${actualPort}/__bili/ (Configuration → Signed upstreams). ` + "Set resign[\"\"].enabled=false / BILI_RESIGN=0 only if you accept the upstream rejecting rewritten bodies.", ); } diff --git a/tests/issue2260-inert-resign-passthrough.test.ts b/tests/issue2260-inert-resign-passthrough.test.ts new file mode 100644 index 0000000000..19d8852900 --- /dev/null +++ b/tests/issue2260-inert-resign-passthrough.test.ts @@ -0,0 +1,132 @@ +import { test } from "node:test"; +import assert from "node:assert/strict"; +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; +import { loadRoutes } from "../src/config.ts"; +import { setLogCapture } from "../src/logger.ts"; +import { rmrf } from "./tmp-rm.ts"; + +type Captured = { level: string; msg: string }; + +const WARN_PREFIX = "[acp-config] "; + +function inertWarns(captured: Captured[]): Captured[] { + return captured.filter((e) => e.level === "warn" && e.msg.startsWith(WARN_PREFIX) && e.msg.includes("is INERT")); +} + +function captureLogs(): { captured: Captured[]; stop: () => void } { + const captured: Captured[] = []; + setLogCapture((level, msg) => captured.push({ level, msg })); + return { captured, stop: () => setLogCapture(null) }; +} + +function withConfigFile(body: string, fn: (file: string) => void): void { + const dir = fs.mkdtempSync(path.join(os.tmpdir(), "bili-issue2260-")); + const file = path.join(dir, "billion-context.json"); + fs.writeFileSync(file, body); + const prev = process.env.BILI_CONFIG_FILE; + process.env.BILI_CONFIG_FILE = file; + try { + fn(file); + } finally { + if (prev === undefined) delete process.env.BILI_CONFIG_FILE; + else process.env.BILI_CONFIG_FILE = prev; + rmrf(dir); + } +} + +// Seals BILI_RESIGN around fn: the enabled cascade reads it directly, and a +// CI shell that happens to export it would flip the guard-active premises. +function withSealedResignEnv(fn: () => void): void { + const prev = process.env.BILI_RESIGN; + delete process.env.BILI_RESIGN; + try { + fn(); + } finally { + if (prev === undefined) delete process.env.BILI_RESIGN; + else process.env.BILI_RESIGN = prev; + } +} + +// Module-level signature state is shared across these tests (one process per +// file); they are ordered so each step's premise holds: "" -> x-ofm -> "". +test("#2260(B)/#2090: inert non-builtin passthrough key warns once at config load", () => { + const { captured, stop } = captureLogs(); + try { + withSealedResignEnv(() => withConfigFile( + JSON.stringify({ resign: { "x-ofm-signature": { passthrough: true } } }), + () => { + const first = loadRoutes(); + let warns = inertWarns(captured); + assert.equal(warns.length, 1, `expected exactly 1 warning, got: ${captured.map((e) => e.msg).join(" | ")}`); + assert.ok(warns[0].msg.includes('resign["x-ofm-signature"].passthrough'), warns[0].msg); + assert.ok(warns[0].msg.includes('"sdk-hmac-sha256"'), warns[0].msg); + assert.ok(warns[0].msg.includes('enabled=false') && warns[0].msg.includes("BILI_RESIGN=0"), warns[0].msg); + + const second = loadRoutes(); + assert.equal(inertWarns(captured).length, 1, "identical dead-key set must not repeat the warning"); + assert.deepEqual(Object.keys(first), Object.keys(second), "routes must parse identically with or without the warning"); + }, + )); + } finally { + stop(); + } +}); + +test("#2260(B): builtin-scheme passthrough is live — no warning", () => { + const { captured, stop } = captureLogs(); + try { + withSealedResignEnv(() => withConfigFile( + JSON.stringify({ resign: { "sdk-hmac-sha256": { passthrough: true } } }), + () => { + loadRoutes(); + assert.equal(inertWarns(captured).length, 0, `no warning expected: ${captured.map((e) => e.msg).join(" | ")}`); + }, + )); + } finally { + stop(); + } +}); + +test("#2260(B): guard-disabled key is not dead — no warning", () => { + const { captured, stop } = captureLogs(); + try { + withSealedResignEnv(() => withConfigFile( + JSON.stringify({ resign: { "x-ofm-signature": { passthrough: true, enabled: false } } }), + () => { + loadRoutes(); + assert.equal(inertWarns(captured).length, 0, `no warning expected: ${captured.map((e) => e.msg).join(" | ")}`); + }, + )); + } finally { + stop(); + } +}); + +test("#2260(B): provider-scope inert key warns; changing the dead-key set re-warns", () => { + const { captured, stop } = captureLogs(); + try { + withSealedResignEnv(() => withConfigFile( + JSON.stringify({ providers: { "https://api.example.com/v1": { resign: { "aws4-hmac-sha256": { passthrough: true } } } } }), + (file) => { + loadRoutes(); + let warns = inertWarns(captured); + assert.equal(warns.length, 1, `expected exactly 1 warning, got: ${captured.map((e) => e.msg).join(" | ")}`); + assert.ok(warns[0].msg.includes('resign["aws4-hmac-sha256"].passthrough'), warns[0].msg); + + fs.writeFileSync(file, JSON.stringify({ resign: { "b-cryptosig": { passthrough: true } } })); + loadRoutes(); + warns = inertWarns(captured); + assert.equal(warns.length, 2, "changed dead-key set must re-warn"); + assert.ok(warns[1].msg.includes('resign["b-cryptosig"].passthrough'), warns[1].msg); + assert.ok(!warns[1].msg.includes("aws4-hmac-sha256"), "fixed key must not be re-listed"); + + loadRoutes(); + assert.equal(inertWarns(captured).length, 2, "stable dead-key set stays quiet"); + }, + )); + } finally { + stop(); + } +});