Skip to content
Merged
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
10 changes: 5 additions & 5 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}
}
```

Expand Down
4 changes: 2 additions & 2 deletions CONFIGURATION.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` 优先。
Expand All @@ -515,7 +515,7 @@
{
"resign": {
"sdk-hmac-sha256": { "passthrough": true },
"aws4-hmac-sha256": { "passthrough": true }
"aws4-hmac-sha256": { "passthrough": true } // 非内置方案无效(#2090)——配置加载时会被点名
}
}
```
Expand Down
22 changes: 3 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
8 changes: 7 additions & 1 deletion release-notes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
48 changes: 48 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1649,6 +1649,7 @@ export function loadConfigFile(): FileConfig {
const obj = parsed as Record<string, unknown>;
normalizeLegacyAllowDshCompaction(obj);
warnUnknownTopLevelKeys(obj);
warnInertResignPassthrough(obj);
value = obj as FileConfig;
} else {
value = {};
Expand Down Expand Up @@ -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<string, unknown>): 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<string, unknown>)) {
if (key === RESIGN_BUILTIN_SCHEME) continue;
const block = val !== null && typeof val === "object" && !Array.isArray(val) ? (val as Record<string, unknown>) : {};
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<string, ResignFileSettings> | 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<string, unknown>)) {
if (!entry || typeof entry !== "object" || Array.isArray(entry)) continue;
const pmap = (entry as Record<string, unknown>).resign;
if (pmap === undefined) continue;
consider(pmap, (key) => ((pmap as Record<string, ResignFileSettings> | 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["<scheme>"].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
Expand Down
2 changes: 1 addition & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ export async function startServer(opts: ProxyOptions): Promise<http.Server> {
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[\"<scheme>\"].enabled=false / BILI_RESIGN=0 only if you accept the upstream rejecting rewritten bodies.",
);
}
Expand Down
132 changes: 132 additions & 0 deletions tests/issue2260-inert-resign-passthrough.test.ts
Original file line number Diff line number Diff line change
@@ -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();
}
});
Loading