Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
8a0fe77
feat(perf): #5460 P1 — realtime telemetry into perf.sqlite (DB modes …
Nov 1, 2026
ea210e8
fix: #5460 route perf-telemetry degrade warnings through the tee logger
Nov 1, 2026
1c39d9a
docs: #5460 register BILI_PERF_TELEMETRY in CONFIGURATION.md (en+zh)
Nov 1, 2026
664ffad
fix(perf): #5460 review — pure-JSON (legacy) storage mode stays froze…
Nov 1, 2026
037d901
fix(perf): #5460 review — enforce the one-shot degrade contract on op…
Nov 1, 2026
f4a76fc
fix(perf): #5460 review — synchronous=NORMAL for perf.sqlite (hot-pat…
Nov 1, 2026
f18e30e
refactor(perf): #5460 review — compute outbound byte length once in l…
Nov 1, 2026
5482bec
test(perf): #5460 review — pin the 200k-row retention cap end-to-end
Nov 1, 2026
49b0ec7
test(perf): #5460 review — correct retention expectation to the sweep…
Nov 1, 2026
a195ca0
fix(perf): #5460 resolve the SQLite engine through the shared storage…
Nov 1, 2026
dfbb8b3
feat(perf): #5460(P2) bili bench + fixture-gen — hermetic record-only…
Nov 1, 2026
e3ee985
test(perf): #5460(P2) fixture determinism + bench report math + CLI p…
Nov 1, 2026
0fcf305
docs(perf): document bili bench / fixture-gen surface for config-surf…
Nov 1, 2026
bc0e3c7
chore(cli): restore original help-block indentation on unchanged lines
Nov 1, 2026
07578ea
docs(perf): register BILI_PERF_TELEMETRY in the config-docs seed so t…
Nov 1, 2026
7c35967
refactor(perf): drop internal-only exports flagged by check-unused-ex…
Nov 1, 2026
ee49ab5
fix(perf): release perf.sqlite handle on store close (Windows EBUSY, …
Nov 13, 2026
c7a640e
test(perf): make closeQuietly-release test deterministic against leak…
Nov 15, 2026
fc115a9
docs(arch): register bench.ts / perf-fixture.ts / perf-telemetry.ts i…
Nov 15, 2026
e3998e6
fix: #5460(P2) review — help indentation, stray blank lines, fixture-…
Nov 15, 2026
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ Versions follow the merge of a `*_release-v*` branch; CI publishes to npm on tag
- **The full-resend watermark fastpath (#5403/#5418) passed its §7.4 human review and ships behind the 5% experimental cohort** (owner ruling 2026-11-02: default off, small cohort first; the web switch + one-time intro notice ship alongside): plugin-lane chat-completions turns whose prefix is byte-stable skip the full history re-parse/re-pin on hit (the #5403 OOM producer), any doubt still falls back to the untouched full-parse path per turn. Force either direction per install with `rollout.features.pluginFullResendWatermark: true|false` (or a percent) or `BILI_ROLLOUT_PLUGIN_FULL_RESEND_WATERMARK=1|0`.
- **The silent-direct oversized guard (#5405) defaults to 8 MiB and honors `BILI_SILENT_DIRECT_MAX_MB`.** The missing-slot / unattributed arms count RAW body bytes — base64-inflated media included — so an in-window session carrying even one medium image died at 2 MiB with a retryable 422 that could never succeed; the runaway multi-MB prompts the guard exists for are tens of megabytes or more. Default raised 2 → 8 MiB (owner ruling, #5826 release review); installs can lower it back per machine (megabytes, >0; invalid values fall back to the default).

### Added

* **#5460(P2):性能基准夹具与 `bili bench`(只记录不判)**。`bili fixture-gen --seed K --msgs N --shape openai|anthropic` 把参数当纯函数吐出纯合成对话(同 seed 字节级相同、零隐私面;S-small 50 / S-med 2k / S-large 2万条≈80MiB 复刻 #5403 形状)。`bili bench <scenario>` 在一次性 XDG 目录+随机端口里拉起真代理、对进程内确定性假上游(复用 e2e-dsh hermetic 手法)按 dsh 插件车道的全量重发形状逐回合回放夹具,结束后读子进程 perf.sqlite 产出 JSON 工件:`total_ms` p50/p95/max/mean、进出站字节、内存 HWM、回合错误清单。**只记录不判**:指标再慢也 exit 0,只有 harness 失败(服务起不来/全回合失败/采集未武装)才 exit 1——容差带判定与基线 ratchet 留给 P3(`--rounds 3` 中位数支持已就位)。内置 6 个场景(core×5 + nightly×1 S-large);PR 级 CI 零 perf job(owner 定),FULL/夜间接线在 P3。tests/issue5460-perf-bench.test.ts(夹具确定性/哨兵不变量/S-large 尺寸锚/统计数学/CLI 解析;端到端 smoke 门控 ACP_TEST_BENCH=1,需先 build)。
* **#5460(P1):实时性能采集落地(SQLite 存储)**。近期所有性能事故(#5403 OOM×6、#4528 主线程卡死、#5385 前缀钉死)都是用户先发现、CI 零预警。现在 DB 存储模式(sqlite/mysql)下每处理一个请求,就在会话目录旁的新小库 `perf.sqlite` 落一行(消息数/进出字节/本地耗时/会话号),另有每 30 秒一条内存水位采样(rss/heap/external)——OOM 类事故从此有爬坡曲线可查。写路径与服务完全隔离:任何写失败只停采集(一次性警告),绝不影响服务;纯 JSON 存储模式冻结零足迹(owner 定)。`BILI_PERF_TELEMETRY=0` 整体关闭。后续:P2 场景夹具+`bili bench`(只记录不判)、P3 基线容差带接 FULL/夜间 CI(普通 PR CI 零性能 job)、P4 `/stats`+Web 面板性能页+外部看门狗——跟踪单 #5460。

### Fixed

- **压缩失败提示里的 compress 调用示范改用官方字符串形态。** 两处面向模型的文案仍演示已退役的 `content` 原生数组形态(schema 早已只收字符串,严格校验的主机会直接拒调):`tierActionHint` 的 tier 蒸馏/凝缩建议(`kernel/src/compress.ts`,恰好挂在「已压过该区间」收据后面——弱模型刚被拒、最容易照抄的时刻)与断路器 armed 后的 format reminder(`src/stream.ts`)。两处均改为与 `compress` 工具 schema 及 nudge 示例一致的 `content: "b1–b5 optional topic\nsummary markdown..."` 字符串形态;`docs/plugin-protocol.md` 的 `/__bili/plugin/tool` 请求示例同步改为字符串并补注(JSON 编码数组放在同一字符串内仍被接受)。回归:`kernel/tests/regression-bili-470.test.ts`(示例文案钉住)、`tests/issue4812-armed-breaker-short-receipt.test.ts`(新 reminder 断言 + 旧数组措辞负向断言)。
Expand All @@ -54,6 +59,8 @@ Versions follow the merge of a `*_release-v*` branch; CI publishes to npm on tag

- **中断后/usage 丢失后的「幻影紧急压缩」:本轮拿不到计费样本时,压力档压缩延后一轮再决定**:中断的流(用户 ESC)或上游短 TTL 缓存把 usage 报告弄丢时,本轮的「计量表针」只能落回字符级本地估算——它量的是即将被改写丢掉的入站字节,实测比真实计费高约 3 倍(0.1.212 当天两起真实现场:ESC 的会话从 9478 跳成 228376、长跑会话被连续两轮注入 153% 幻影压力带,徒劳改写并烧掉前缀缓存)。此前这种坏表针直接按 EMERGENCY/OVER-LIMIT 扣扳机。现在:内核收到以「估算值」计量的压力带读数(宿主标记 tokenCountSource="estimate")时,本轮压力档注压延后一轮——下一次请求必然带着新鲜计费报告,拿真数再决定,代价≈0;计费级读数("usage")与不传 source 的老调用方字节不变,非压力档(增长/节拍)完全不受影响,硬溢出兜底臂全程照旧武装。宿主侧提前广告臂(emergencyNudge)同步镜像该位,不会拿着同一个坏读数抢跑。逃生阀:`compress.requireUsageSampleForPressure: false` 恢复旧的估算驱动行为。tests:kernel/tests/nudge-pressure-no-sample-hold.test.ts(6 例)、tests/nudge-pressure-no-sample-armed.test.ts(3 例);kernel 既有套件 1582/1582 绿。
- **External-summary mode no longer reports protected or already-folded ranges as failed compression.** An unchanged kernel preview now returns the normal idempotent no-op or kernel-error receipt without a paid summarizer call; validated internal probe summaries prevent an irrelevant submitted-hint length from blocking that receipt. Probe-created blocks with no recoverable content still refuse rather than folding an unreviewed hint. Regression: `tests/external-summary-runtime.test.ts` (24/24).

- **#5460(P1 评审发现):Node <22.5 上整个 CLI 不再因性能采集找不到 SQLite 而启动即死。** P1 的 perf.sqlite 在模块顶层直接 `import "node:sqlite"`——该内置模块 Node ≥22.5 才有,而 package.json 仍声明 engines >=20;静态导入让**整个进程**在模块加载期崩溃(不可用的是全部 bili,不只是遥测)。现在与 index.db 走同一条引擎解析链(`openSqliteDatabase`:builtin node:sqlite → 宿主 better-sqlite3 → 自下载,#2833/#2845):老 Node 自动落到原生引擎,全缺时按既有契约一次性警告、只降级停用遥测,服务可用性不受影响;同时满足 dist 自包含门禁(零新增外部 specifier)。
* **#5412: 异步存储后端的「压缩冻结会话」现在也能自愈。** #5408 事故(一个会话连续 17 次摘要漂移后被保护机制冻住、8 小时无人知晓)的主修复 #5409 只教了同步存储路径(SQLite 直写)自救:漂移挂起期间保存会自动升级为全量重导入并清掉索引里的残留行。异步路径(opt-in 网络后端,如 mysql)那份孪生代码没搬——同样被冻住的会话在那上面永远救不回来,每次保存都重写不完整视图、下轮采样继续漂移。本 PR 在 `src/storage/shadow.ts` 的异步入队路径补上同一行对齐(`completeLog = hasRawTail || driftedSessions.has(id)`),行为与同步路径逐字一致;回归测试同时钉住正门(latch 挂起的折叠保存清掉外来行)与负门(未挂起保存不清扫)。
- **中断频繁的会话压缩提醒几乎不触发,积到几十万 token 才压一次(#5415,0.1.210 引入)**:#5293 的修复把每次用户中断后的增长参照点直接抬到当前读数,连「中断前已实测的真实增长」也一起清零;高频中断的客户端(实测一份日志 4.5 小时 85 次中断)永远攒不到增长台阶,30 万可压内容 idle 数小时,最后一次性压 33 万。现在吸收时把被清零的实测增长记入「欠账」(`nudge.absorbedDebt`)并累计吸收次数(`nudge.absorbCount`),两者都只在**第 2 次起**的中断后生效:单次中断字节级保持 #5293 的安静(不打扰用户刚改的主意——欠账再多也不当场弹提醒);第二次中断才证明会话是「高频中断型」而非「改主意」,欠账从此与新增量一起计入增长台阶,恢复 209 时代的节奏。另加「大积压排水」兑底:欠账>0 且可压量≥2×阈值且当前无未消化提醒时不再等增长台阶(与 #194 同哲学);无欠账/单次中断的会话决策字节不变。压缩成功时欠账与计数随其它基线一起清零;idle 日志同步显示 `growth X + absorbed Y across N aborts < floor Z`(单次中断显示 `held (single abort, #5293)`)便于排查。tests:kernel/tests/issue5415-absorb-debt-nudge.test.ts(欠账付台阶/单次中断钉死不弹/排水兑底/忽略提醒不重发/无欠账字节不变/压缩后清账+清计数);tests/issue5415-absorb-debt.test.ts(吸收记账算术、欠账+计数、累次累计、参照点已越过 anchor 不记账也计数、陈旧 flag 丢弃)。
- **长会话每回合把 Node 主线程卡死十几秒、网页面板冻结(#5337)**:每回合的压缩筛查把历史切成若干可折叠单元,逐个跑「能否折叠」判定——而每次判定都从零重扫全量消息数组(id 查找无索引,五处线性 `.find()`/`includes`),还重复重算全套整史统计(受保护/过期工具调用集合、工具配对表、末尾锚点、完整性预扫)。总工作量≈单元数×全史长度=历史规模平方级,且同步跑在主线程:2.3万条核心消息实测单回合约17秒(事件循环被占死,请求排队;#5304 同签名报告)。修复=把这批 O(n) 推导提升为每轮筛查**一次**构建(`buildProjectionShared`)、共享给同一轮所有单元;id→序号一次性建表替五处线性查找;「已丢弃」成员判断从 includes-in-some 改为 Set。判定逻辑本身一字未动(#3236 单一判定纪律),只是输入到达判定的方式变了。同机同语料实测:2万条消息完整推荐链 9028ms→约572ms(≈16×),回落到线性量级。单次调用路径(apply/report)保持原有内联计算,输出逐字节不变。kernel v0.0.175。tests/issue5337-shared-screening.test.ts(共享/非共享投影逐字段等价+降级边界一致+n=20000 耗时上界钉);既有 issue3406 曲线钉与 #3236 一致性回归不变。
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,15 @@ bili --bin /path/to/client # launcher: spawn this exact client binary instead

Flags override env vars and the config file. `bili --help` lists them all.

### Performance tooling (`bili bench` / `bili fixture-gen`, #5460)

Record-only performance harness: `bili bench <scenario>` boots the real proxy as a child process against an in-process deterministic fake upstream in throwaway XDG dirs (random ports, auto-update off), replays a seeded fixture as sequential full-resend rounds (the dsh plugin lane's traffic shape), then reads the child's `perf.sqlite` (#5460 P1) and prints a JSON artifact — `total_ms` p50/p95/max/min/mean, inbound/outbound byte totals, memory HWM, per-round errors. **It records, never judges:** slow metrics still exit 0; only harness failures (server never ready, every round failed, telemetry did not arm, mid-run crash) exit 1. Tolerance bands / baseline ratchet / FULL+nightly CI wiring are follow-ups (#5460 P3). `bili bench` with no scenario lists the catalog: `smoke-openai-tiny`, `proxy-append-openai-s-small`, `proxy-append-openai-s-med`, `proxy-append-anthropic-s-med`, `proxy-compress-openai-s-med` (declares a 16K window to force fold density), `proxy-append-openai-s-large` (~80 MiB fixture mirroring #5403 — nightly tier).

```bash
bili bench proxy-append-openai-s-med --rounds 3 --out report.json # --keep-workdir keeps the throwaway dir; --dist PATH picks which dist/index.js to boot
bili fixture-gen --seed 42 --msgs 2000 --shape anthropic > fx.json # pure function of seed/msgs/shape: same input ⇒ byte-identical output; --out FILE writes instead of stdout
```

### Remote agents (`--host`)

By default the proxy binds `127.0.0.1` and only accepts loopback connections. To serve agents on other machines: `bili --host 0.0.0.0` (or your LAN IP); remote agents point their model `baseURL` at `http://<this-host>:<port>/bili/…`.
Expand Down
9 changes: 9 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,15 @@ bili --no-auto-update # 本次启动禁用自动更新

参数优先级高于环境变量和配置文件。`bili --help` 列出全部。

### 性能工具(`bili bench` / `bili fixture-gen`,#5460)

只记录不评判的性能基准:`bili bench <scenario>` 把真实代理作为子进程拉起,对着一次性 XDG 目录里的进程内确定性假上游(随机端口、自动更新关闭)重放种子 fixture(顺序全量重发回合,即 dsh 插件车道的流量形状),再读子进程的 `perf.sqlite`(#5460 P1),输出 JSON 产物 —— `total_ms` p50/p95/max/min/mean、入站/出站字节总量、内存 HWM、逐回合错误。**它只记录、不评判**:指标慢照样 exit 0;只有 harness 故障(服务始终未就绪、全部回合失败、遥测未武装、运行中崩溃)才 exit 1。容差带 / 基线棘轮 / FULL+nightly CI 接线是后续工作(#5460 P3)。不带 scenario 的 `bili bench` 列出全部场景:`smoke-openai-tiny`、`proxy-append-openai-s-small`、`proxy-append-openai-s-med`、`proxy-append-anthropic-s-med`、`proxy-compress-openai-s-med`(声明 16K 窗口逼出折叠密度)、`proxy-append-openai-s-large`(约 80 MiB fixture,镜像 #5403 形状 —— nightly 档)。

```bash
bili bench proxy-append-openai-s-med --rounds 3 --out report.json # --keep-workdir 保留一次性目录;--dist PATH 指定拉起哪个 dist/index.js
bili fixture-gen --seed 42 --msgs 2000 --shape anthropic > fx.json # seed/msgs/shape 的纯函数:同输入 ⇒ 字节级一致;--out FILE 写文件而非 stdout
```

### 远程 agent(`--host`)

默认绑定 `127.0.0.1`,只接受本机连接。要给其他机器上的 agent 用:`bili --host 0.0.0.0`(或局域网 IP);远程 agent 把模型 `baseURL` 指向 `http://<本机>:<端口>/bili/…`。
Expand Down
1 change: 1 addition & 0 deletions docs/configuration.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@
| `BILI_STORAGE_ARCHIVE_AFTER_DAYS` | integer | 365 | — | GC 年齢スウィープウィンドウ (日) (#3463): これより長くアイドル状態のセッションはアーカイブされる (単一のアーカイブログ (archive/archive.jsonl) に 1 行の JSON が追記 + トombstone 行 + コンテンツ/メディア参照の解放)。0 で年齢スウィープを無効化; 手動エントリ POST /__bili/storage/gc は常に実行される。設定ファイルキー storage.archiveAfterDays が永続形式である。 |
| `BILI_STORAGE_QUICK_CHECK` | string | on | — | オープン時のストレージ整合性セルフチェック (#4175): すべての index.db オープン時にマイグレーション前に PRAGMA quick_check を実行; このブートのスキャンによって破損が証明された場合、何も自動的に移動、コピー、再構築されない (自動回復は #4609/#4626 時代に撤回: BILI_STORAGE_JSON_WRITER=off ではインデックスが唯一の永続コピーであり、自動的な移動または再構築では完全なデータ回復を保証できないため) かつ bili はそれでも起動する — JSON エンベロープからサーブし、手動修正 (バックアップしてから index.db/-wal/-shm を手動で退避し、再起動 — 新しいインデックスは JSON エンベロープから再構築される) を名指しする大きくて実行可能なアラームを発する。成功した PASS はキャッシュされ、後の起動で再スキャンをスキップする; FAIL 判定は決して永続化されない (2026-10-30 オーナーポリシー): ランタイム/バックグラウンドの発見はアラームのみ (大きなログ + ランタイムステータス、プロセスはサーブを継続 — jsonWriter が on の間に書かれた JSON エンベロープが回復ソースのまま) であり、すべてのブートは現在のファイルセットの新しいスキャンから再決定するため、古いバージョンが残した古い FAIL が将来のブートをブロックすることは決してない。自動リネーム/修復もレガシー専用フォールバックもない: レガシー専用で続行すると、JSON エンベロープが死んだインデックスから永遠に分岐する (決して調整不能)。一時的なオープン失敗 (SQLite エンジンなし / CANTOPEN / 読み取り専用 / バックエンド DSN) は、実行可能なエラーで bili が大きく起動を拒否する — 環境問題に対するサイレントレガシーフォールバックもない (2026-10-30 オーナーポリシー; ライブな第二ライターがこの拒否リストを 2026-10-31 に残した — 1 つのローカルディスク index.db を共有することはサポートされるトポロジーであり、情報提供のみ、決してブロックしない); 真に JSON のみでサーブしたいデプロイは明示的に設定する (BILI_STORAGE_UNIFIED=legacy — 未設定はピュア SQLite のデフォルトであり legacy ではない)。チェックのコストが重要なブート時感度の高い巨大デプロイでのみ 0 を設定する。 |
| `BILI_SNAPSHOT_SHADOW` | boolean | true (on) | — | スナップショットレンダリングのシャドウ観測可能性(#3756 のフォローアップ): アームされたターンごとに送信スナップショットビューを計算するが使用せず、レガシー送信との差分を分類し、セッションごとのカウンターを Web パネルおよびスナップショットシャドウ診断トピックに表示する。0/false/off で無効化、1/true/on で有効化、それ以外の場合は設定ファイルの snapshot.shadow ブール値が適用される(デフォルトは on)。レンダリングレーン自体はロールアウトゲート(BILI_ROLLOUT_SNAPSHOT_RENDER)で制御されるため、シャドウレーンは送信バイト列を変更しない - これは後日のロールアウトを切り替えるためのドライラン証拠である。 |
| `BILI_PERF_TELEMETRY` | boolean-ish | on | — | #5460 リアルタイム性能テレメトリのキルスイッチ。DB ベースのストレージモード(sqlite/mysql)ではデフォルトで有効: 処理された各リクエストについて 1 行と 30 秒ごとのメモリ水位サンプルを index.db の隣にある perf.sqlite に書き込む —— 独立したファイルで、ユーザー自身のストアとクラッシュ/サイズで分離; 純 JSON ストレージモードは凍結されており、決して収集しない。0/false で収集を完全に無効化。テレメトリのオープン/挿入失敗は収集を劣化させる(警告 1 回 + dead フラグ)だけで、サービスには決して影響しない。 |
| `BILI_CONFIG_FILE` | string | unset (XDG config path) | — | 設定ファイルのパスを上書きする(パスの再配置)。スラッシュ `/` を含まない名前(NAME)のみは命名設定 `<configDir>/NAME.json` を選択します。名前が誤っている場合は利用可能な名前を列挙して即座にエラーとなり、明示的なパスが誤っている場合は従来の空設定の挙動を維持します。 |
| `BILI_SESSIONS_DIR` | string | unset (XDG state path) | — | セッションレコードの保存先(パスの再配置)。 |
| `BILI_ENCRYPTION_KEY` | string | unset | — | 暗号化された永続化ペイロード用の鍵材料(シークレット)。 |
Expand Down
Loading
Loading