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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Versions follow the merge of a `*_release-v*` branch; CI publishes to npm on tag
- **系统架构文档体系落地(owner 指令 2026-11-08):`docs/architecture/` 成为实时维护的架构枢纽**:新增 `docs/architecture.md` / `docs/architecture.zh-CN.md` 总枢纽(整体架构图中英双版转正 + 8 模块总表),首个样板模块页 `docs/architecture/storage.{md,zh-CN.md}`(统一存储:职责/原理/工作机制/硬不变量,配模块图中英双版)。文件级地图 `reference/architecture.md` 补齐 125 个缺失条目(新存储层 / marker / fastpath / lanes 等全部新模块)并升级为 CI 强制全量覆盖。新增 CI 车道 `architecture-docs`(`tools/check-architecture-docs.mjs`):地图覆盖全 `src/` 文件、总表↔页面成对、图 svg 优先 + png 备选齐备、SVG 基础良构(未转义 `&` 曾让英文图线上破图)。AGENTS.md「Documentation Layout」新增实时维护规则:改结构 ⇒ 同 PR 更新页 + 图 + 总表。其余 7 个模块页(pipeline / lanes / kernel / identity / fastpaths / webui / update)同一 PR 全部补齐——总表 8 行全 ✅(每页 = 中英双版文档 + 中英双版图)。

### Fixed
- **The log/publish secret scrubber now catches JSON-quoted credentials and Groq/Hugging Face keys.** `redactSecretsInText` (every log line, and via `redactForPublish` the diagnostics blob that lands in public GitHub issues) required `:`/`=` right after the key name, so the JSON/dict shape upstream error bodies and config dumps use — `"api_key": "…"`, `"password": "…"`, `'access_token': '…'` — slipped through unless the value happened to start with a known prefix such as `sk-`. An optional quote after the key name now matches it; `gsk_…` (Groq) and `hf_…` (Hugging Face) keys, both on the public-host list, are masked like `sk-…`. Usage-count keys (`"prompt_tokens"`, `"tokens"`, `"max_tokens"`) stay verbatim. Regression: `tests/log-mask.test.ts`.
- **超窗请求不再裸发上游:三道转发闸按「真实出站体」计量(#5000 #4543 #5885),未压缩大请求纳入 32MiB 成本带准入(#5794)**:旧判据只量「消息核心文本的字节」,看不见 system/tools/tool_calls 参数——#5000 的 55.2MiB 体(84 个工具)与 #4543 的 4.1MiB CJK 体(1,121,674 tok vs 1M 窗口)都能让全部闸门沉默,然后「转发一次取证」把必然 400 的体真发出去烧钱。现在三个「转发仲裁点」(压缩后再检、#1839 仲裁臂、出站熔断)改按出站体的**逐字符 token 计量**(system+tools+arguments+messages,CJK 感知,#554 侧车道同源尺子)对照**真实模型窗口**本地 413,不再裸发;取证探针闸保持 #2490 字节契约不动(那里的一次 400 是设计内的证据回路,见 #2313/#1001);图片体不进判死——计量器补排 responses 车道的 `image_url` 键(此前把截图 base64 当文本量,40MB 截图体被量成 ~10M token,误杀 #3701 的 WS shed 重发与 #857 的图片计费仲裁转发),判死只比文本量,图片单独超窗仍走 #496/#1800 上游计费仲裁。另:成本准入旧阈值 = 5GiB 收件上限,2 槽位预算形同虚设,#5794 的 51.2MiB/轮未压缩请求(每轮独占事件循环 5.5–7.2s、占本机 CPU 54.6% → 747s FATAL 自重启)从此被拦;未压缩体现在按 32MiB 成本带准入(运维显式调低收件上限仍逐字节生效)。tests:issue4079/issue4185/request-body-budget 新增实测档 e2e 与 32MiB 顺序用例;既有 89+67 用例全绿,#857/#3701/#496/图片与计量相关 173 用例回归全绿。#5885 的 modelContextLimit 被忽略属独立缺陷,另行跟进。
- **dsh 闸门:必然被上游拒绝的超窗请求不再裸发直连(#5613 安全网 ①②③)**:`none`/`threw` 归属车道(如经网关的 ds-harness-remote)上的超窗历史请求,旧行为二选一——要么按乐观的 bytes/4 估算判「不超窗」而直接裸发上游(实测计费偏差≈×1.14,估算系统性偏低;真实现场把 max_tokens 挤到 1、乃至上游 400 后整会话报废),要么即便超窗也没有任何持续留痕(只记第一行之后全静默)。现在双档计价:原有 bytes/4 下限继续标记「必然超窗」,另加 ×1.14 校准估算档(会话 ledger 实测偏差,常数 `CALIBRATED_TEXT_TOKEN_RATIO`,src/util.ts),过线即本地 422 拒绝而不是骑 #1117 去赌上游——小体量的合法直通语义(sidecar 短调用等)逐字节保留,未知尺寸流式体保持 fail-open。每次裸发 DIRECT 现在都带体积(`this body N B`)或「尺寸未知、超窗熔断未跑」明示,按 首次/状态变化/每第10次 落 durable 日志(bili.log,[dsh-client] 通道)——连续泄漏环路从此必有痕。tests/dsh-native.test.ts:#2924/#4068 双臂升级为双档断言+校准边界钉(3,508,768 B 直通 / 3,508,772 B 拒)、新增留痕节拍回归、#4111/#4912 谓词改名对齐。
- **全量压缩与 persona 文本漂移同轮发生时,主会话不再分叉到 `|sub:` 副车道(#5719)**:dsh 全量压缩 checkpoint(#3733 authored checkpoint,把整段历史头替换成一条 user 消息)与系统提示漂移(如 dsh 重启后 GUI 端口重分配写进 system prompt)落在同一轮时,既有的全部位置型 re-anchor 逃生结构性不可达——被记录的尾部按定义已被抹掉、incoming 比记录更短、压缩后首个模型步零 assistant——于是活着的会话确定性地分叉到 `<id>|sub:<fp16(新tag)>`:父车道记录冻结、副车道从零起步(resume-inheritance miss)、事故当天又触发 3 次再压缩 + 1 次 REFUSED turn + 2 次 max-tokens 截断。根因=判定器要求一种全量压缩按定义抹掉的字节级续接证据,而唯一能存活压缩的自足证明——bili 自己铸造的 checkpoint 内嵌的 `conv="<rawId>"` 自声明——从未被读取。现在 tagChanged 分支最前新增 E5 级:**第一条** user 消息携带我方 `\x3cbili-snapshot v1 …\x3e` 身份头且其 conv 与当前 id 逐字相等 → 直接 re-anchor 回主车道(record() 同步更新 tagHash,后续请求即普通 continue)。外部 persona 引用 checkpoint 的情形照旧分叉:要么根本到不了判定层(sideRequestLike 门,#4438),要么标记 conv 不符 / 不在第一条 user 消息。**旧行为→新行为**:该形状从「必然分叉」变为「带自声明时 re-anchor 回主车道」;无标记的形状逐字节不变(回归测试钉住每一既有 rung 的 reason 文案)。tests/issue5719-self-checkpoint-reanchor.test.ts(验收标准 1/2/3 + 四种 wire 形状 + foreign-quote 边界)。
Expand Down
6 changes: 5 additions & 1 deletion src/log-mask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,11 @@ export function redactSecretsInText(text: string): string {
return text
.replace(/\b(bearer|basic)\s+([A-Za-z0-9._~+\/=-]{8,})/gi, (_m, scheme: string, tok: string) => `${scheme} <masked ${tok.length} chars>`)
.replace(/(?<![A-Za-z0-9])(?:sk|xai)-[A-Za-z0-9_-]{8,}/g, "<masked key>")
// Groq (gsk_…) and Hugging Face (hf_…) keys, both on PUBLIC_HOST_SUFFIXES.
.replace(/(?<![A-Za-z0-9])(?:gsk|hf)_[A-Za-z0-9]{20,}/g, "<masked key>")
.replace(/(?<![A-Za-z0-9])AIza[A-Za-z0-9_-]{20,}/g, "<masked key>")
.replace(/eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{4,}\.[A-Za-z0-9_-]{4,}/g, "<masked jwt>")
.replace(/(\b(?:api[_-]?key|access[_-]?token|auth(?:orization)?|secret|passwd|password|token)\b\s*[:=]\s*)(["']?)([A-Za-z0-9._~+\/=-]{8,})\2/gi, (_m, pre: string, q: string, val: string) => `${pre}${q}<masked ${val.length} chars>${q}`);
// The optional quote after the name covers JSON/dict keys ("api_key": "…"), the shape
// upstream error bodies and config dumps use; without it only key=value / key: value matched.
.replace(/(\b(?:api[_-]?key|access[_-]?token|auth(?:orization)?|secret|passwd|password|token)\b["']?\s*[:=]\s*)(["']?)([A-Za-z0-9._~+\/=-]{8,})\2/gi, (_m, pre: string, q: string, val: string) => `${pre}${q}<masked ${val.length} chars>${q}`);
}
33 changes: 33 additions & 0 deletions tests/log-mask.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,39 @@ test("redactSecretsInText: scrubs credential-shaped tokens from free-form text (
for (const s of negatives) assert.equal(redactSecretsInText(s), s, `must stay verbatim: ${s}`);
});

test("redactSecretsInText: JSON-quoted credential keys and Groq/Hugging Face keys are scrubbed", () => {
// A quote between the key name and the colon ("api_key": "…") used to stop the key=value
// rule, so a value without a known key prefix reached the log and the diagnostics blob.
assert.equal(
redactSecretsInText('{"error":{"message":"invalid","api_key":"0123456789abcdef0123"}}'),
'{"error":{"message":"invalid","api_key":"<masked 20 chars>"}}',
);
assert.equal(
redactSecretsInText('{"user":"alice","password":"hunter2hunter2"}'),
'{"user":"alice","password":"<masked 14 chars>"}',
);
assert.equal(
redactSecretsInText("{'access_token': 'ya29.a0AfH6SMBx3kL9ZqWv'}"),
"{'access_token': '<masked 23 chars>'}",
);
assert.equal(
redactSecretsInText("Invalid API Key: gsk_8fJ2kLmN4pQrS7tUvW9xYz1aBcDeFgHiJkLmNoPqRsTuVwXyZ012"),
"Invalid API Key: <masked key>",
);
assert.equal(redactSecretsInText("auth failed for hf_AbCdEfGhIjKlMnOpQrStUvWxYz12345678"), "auth failed for <masked key>");
const negatives = [
'{"prompt_tokens":1234,"completion_tokens":5678}',
'{"tokens": 1234}',
'{"token":"abc"}',
'{"max_tokens":4096}',
"hf_hub_download failed",
"gsk_short",
];
for (const s of negatives) assert.equal(redactSecretsInText(s), s, `must stay verbatim: ${s}`);
const once = redactSecretsInText('{"api_key":"0123456789abcdef0123"}');
assert.equal(redactSecretsInText(once), once, "a second pass is a no-op");
});

test("maskIpsInText: non-loopback IP literals scrubbed from free-form text (#1718)", () => {
assert.equal(maskIpsInText("connect ETIMEDOUT 203.0.113.5:8443"), "connect ETIMEDOUT <private-host>:8443");
assert.equal(maskIpsInText("upstream refused 192.168.1.50:443 after 3 retries"), "upstream refused <private-host>:443 after 3 retries");
Expand Down
Loading