Skip to content
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Versions follow the merge of a `*_release-v*` branch; CI publishes to npm on tag
- Claude Code 子代理的 bili 调用不再路由到父会话:Task 子代理与父线程共用一个 MCP shim,启动时抓的绑定只指向父会话;子代理压缩错对象或永久 409。现在 shim 把 host 盖在每次 tools/call 上的 `_meta["claudecode/toolUseId"]` 转发为 body `toolCallId`,代理用它出站时记下的 id→会话映射直接路由到子代理自己的 lane(10 分钟 TTL);id 未知时行为与从前完全一致(#4580)。

### Added
- **`bili storage backup` / `bili storage repair`:index.db 的备份与恢复运维工具(2026-11-20 #7156 生产事故直接产物)**。那次事故里 3.2GB index.db 被证实损坏,恢复路径是一段手写的 .recover 等价脚本 + 手工文件手术——这两个手工动作现在是自带验证的一等命令:① `bili storage backup [--keep N]`——`VACUUM INTO` 在线一致性快照(不重写源、不取独占锁,proxy 在线可跑;#4612 的 `--vacuum full` 离线约束不适用),快照先过 quick_check 才算数,`<sessions>/backups/` 按 retention 留最新 N 份(默认 3);② `bili storage repair --from <backup.db>`——备份先验证(quick_check + sessions 表可读),坏库原地改名 `index.db.corrupt-<ts>` 隔离(含 -wal/-shm/.chk,证据保留),备份**拷入**不动原件,换装后再验一次并提醒重启;③ `bili storage repair` 不带 `--from` = 无备份 salvage:只读打开坏库,逐表灌入全新迁移库(按外键依赖序),坏页区间二分到单行、单行再逐列重读(坏溢出单元只 null 它自己那列,行内其余列保住——#7156 现场同款手法救回 50.6 万条消息/56 万条内容);WITHOUT ROWID 表(conversations/session_ext/kv_store/message_media)没有 rowid 可二分,整表原子拷贝(坏页在只读扫描时抛错→该表记为跳过);任何读不了的表都算丢失——exit 1 并在报告里逐表点名(skippedTables),绝不静默清空;自检 quick_check 过才换装。所有换装路径统一在另一活进程持有 `index.db.lock` 时拒绝(#4175 pid 纪律):隔离文件不能从活写者脚下被抽走;当前 index.db 通过 quick_check 时 repair 同样拒绝——健康索引不能被一份可能更旧的备份静默顶掉,真要回滚是手工改名的事。新模块 `src/storage-backup-repair.ts` + `src/cli.ts` 接线;README「Storage maintenance CLI」节;回归:tests/storage-backup-repair.test.ts(备份快照+retention、`--from` 换装、无备份 salvage、活写者拒绝、`--json`)。
- **消息身份公用设施(sessionid+msgid)的校验规则从「注释自律」升级为 CI 机械锁(#5826 release review 缺口修复,owner 裁定)**:id 卫生规则散落在六份副本(canonical `validateMsgIds` + dsh/incremental-client/pf-channel/fastpath/request-membership 五处镜像;镜像是结构性必需——注入宿主的 bundle 禁止 import server 模块),过去靠「keep in sync」注释同步。新增 `tests/msgid-rule-parity.test.ts`:每个拒绝类(非串/空/超长/保留前缀/空白与控制字符/U+200B/重复/宽度)逐一喂过每份副本并钉死当前判决,有意分歧按分歧钉死并注明理由;改任何一份规则必须先过该测试。同批收敛:`fastpath parseTailIds`(tail-ids 头服务端解码侧)补齐 canonical 保留前缀门——所有生产发射方本就预筛,此为单点收口纵深防御,判决方向更保守。配套文档地图 `docs/msgid-infrastructure.md` + `.zh-CN.md`(生产端→四种传输载体→六份校验副本→存储单一事实源→五个消费方→四条信任边界→改动清单);AGENTS.md KDD #17 声明其生产/消费来源,改动相关代码前先读。
- **#5825 身份信道接线:统一消费缝 + 六条车道。** 身份信道的服务端半边(信封 `msgIds`、全量重放 `biliMsgIds`/`biliLedgerSeqs`、统一存储 `(session_id, seq, msg_id)`、#5719 救援档)此前只服务 dsh;本 PR 按 issue #5825 的逐客户端结论把其余车道接进**同一条**消费缝,不做任何逐调用点单独取数(owner 裁定 2026-11-07:能接的都接、不再拆分)。新模块:`src/identity-harvest.ts`(注册表 + 门控:**env `BILI_IDENTITY_HARVEST`(缺省关,可点名车道)与灰度键 `rollout.features.identityChannelHarvest` 二者任其一即可使能、均默认关** × 回环来源 × 整轮退化纪律)+ 自包含适配器:`src/identity-claude.ts`(claude-code 转录 JSONL 尾部快照,sidechain/summary 行排除)、`src/identity-codebuddy.ts`(codebuddy conversation-id==文件名布局)、`src/identity-mcode.ts`(mcode/mavis runtime-state.sqlite 每轮只读快照)、`src/identity-goose.ts`(goose sessions.db `message_id` 行;`agent-session-id` 头已入会话识别低信任层)与 `src/identity-qwen.ts`(qwen-code `chats/<sid>.jsonl` git-log 转录;join 用官方 BYOK 文档示例头名 `x-opencode-session` 的 `${session_id}` 自定义头——用户自选其它名则安全退化)+ barrel `src/identity-sources.ts`。opencode **V2** 宿主侧接入:扩展在自己的 http-request hook 里读**当轮自己的**结构化消息铸 `x-bili-msg-ids` 请求头(同一事件取值零竞态;任一变体缺 id → 整份戳作废),服务端按 body 字段 > 该头 > 采集注册表 的优先级消费。pin/行链路补 openai wire 对等件(prepare-openai 与 prepare-anthropic 同款无条件剥除 + 灰度内钉住,命中水位快路径的轮次因窗口变短按构造不参与)。任何一处不判定 → 整轮回退接线前路径,绝不做部分映射。附带合并 #5825 决定 A:codebuddy 的 `x-conversation-id` 进入会话识别名单(低信任层)。crush(join 键是 xxh3 摘要且库在工程目录内)/ gemini-cli(仅装机级身份)/ hermes(线上零身份信号)/ iflow(产品已下线)四条按审计结论记闭合备忘,见 docs/identity-channels.md §2。默认零行为变化(两个使能方都缺省关 + 仅回环)。测试:`tests/identity-harvest.test.ts`(含夹具级 SQLite/JSONL 布局)、`tests/opencode-v2-msgids.test.ts`、`tests/msgid-header-channel.test.ts`、`tests/openai-msgid-pin.test.ts`(全链路集成:字段绝不上游 + 行带客户端 id)。文档 AGENTS.md 新增 KDD #18(与 #5826 msgid 基础设施条目相邻,合入时如编号冲突顺延)、docs/identity-channels.md/.zh-CN.md、website/config-reference 登记(env-only + rollout)。
- **`bili kiro`:Kiro CLI(AWS)启动器车道 / launcher lane for Kiro CLI.** Kiro 的模型调用是 `runtime.<region>.kiro.dev/v1/responses` 上的 Responses wire,每轮重放完整历史、bearer 鉴权、遵守 `HTTPS_PROXY`--现有 responses 管线即可压缩,只需处理两处网关差异:1网关只收 `user`/`assistant` 项,注入的 `developer` 压缩提示会被 400(`param: input[0]`)拒绝 → 对 Kiro 流量内置 `developer`/`system`→`user` 角色映射(最低优先级,`compat.roles` 与学到的角色仍按键覆盖;判官按原角色看待注入提示,不误报 I1);2Kiro 首项跨进程不字节稳定,`--resume` 会新建会话 → 提升 `metadata["kiro:conversation_id"]` 为会话 id(`kiro-<id>`,只覆盖内容指纹)。车道只 MITM 四个 `runtime.*.kiro.dev` 网关,合并 CA 同时写 `SSL_CERT_FILE`(Rust 外壳)与 `NODE_EXTRA_CA_CERTS`(Node 代理服务),回环走 `NO_PROXY`。实测(kiro-cli 2.37,真实账号):0 次 400,14 次独立启动(13 次 --resume)始终同一会话,折叠 16.4K token 后口令仍可召回,判官 clean fold verdict。新文件 `src/kiro.ts`,测试 `tests/kiro.test.ts` + `tests/launcher.test.ts`(runLaunch kiro);文档 CLIENTS.md / CLIENTS.zh-CN.md「Kiro CLI(AWS)」节、README 表格与启动器列表。
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -729,10 +729,21 @@ bili sessions restore <id> # bring an archived session back from the log l
bili sessions foreign-blocks # (#5312) list fold blocks whose covered messages never belonged to this transcript — dry-run; --apply reversibly archives them, --restore <sid>:<bid> brings one back
bili storage gc [--days N] [--vacuum full|incremental] [--dry-run]
# print the sweep plan (sessions past retention, zero-ref content rows, ~pages reclaimable), then run the same gc() the HTTP endpoint calls; --dry-run stops after the plan
bili storage backup [--keep N] # online-consistent index.db snapshot into <sessions>/backups/ (VACUUM INTO —
# never rewrites the source, no exclusive lock, safe while a proxy runs); the
# snapshot is quick_check-verified before it counts; keeps the newest N (default 3)
bili storage repair [--from f.db] # with --from: verify the backup (quick_check + readable sessions), quarantine the
# broken index.db IN PLACE (index.db.corrupt-<ts>, evidence kept), copy the backup in
# (the backup itself stays untouched), verify again; without --from: salvage the
# corrupt file row-by-row into a freshly-migrated schema (bisects broken page ranges
# to single rows; a corrupt overflow cell nulls its own column, the rest of the row
# survives). Both swap paths refuse to run while another live process holds index.db.lock.
```

`archive`/`restore`/`gc` require the unified store (`BILI_STORAGE_UNIFIED=sqlite|shadow|full` or `storage.unified` in the config file — the default is now pure sqlite) — legacy-only installs refuse with a hint. `--days` defaults to `storage.archiveAfterDays` (365). No scheduler: these run on demand. All commands accept `--json`.

**Backup & repair (#7156, 2026-11-20 production incident).** A 3.2 GB index.db proved corrupt (foreign second writer, #7156) and the only recovery path was a hand-rolled `.recover`-equivalent plus manual file surgery — those two manual moves are now the `backup`/`repair` commands above. Operational discipline that keeps the incident from recurring: run `bili storage backup` on a schedule (the retention flag is the only state it keeps), and keep **exactly one** long-lived bili process per sessions dir — a second live writer is the corruption mode, and every storage command now detects a live foreign writer and refuses rather than contending.

**Full vacuum is an offline operation on large databases (#4612).** `--vacuum full` (the default) rewrites the entire index.db under an exclusive write lock — O(db size), minutes to tens of minutes on multi-GB databases, with no intermediate progress (SQLite's VACUUM is atomic; it cannot be split). Running it while a proxy is serving from the same sessions dir starves that proxy's writes until its storage layer degrades, so `storage gc --vacuum full` **refuses to start when another live process holds the database** (`index.db.lock` pid discipline, #4175): the CLI exits 1 with an actionable message, the panel endpoint returns HTTP 409. Stop the other instance first (or wait for it to exit) and retry; for online-safe shrink use `--vacuum incremental`, which reclaims freed pages in short transactions without taking the exclusive lock. The zero-ref delete sweep itself is batched with per-batch progress output either way.

## Status
Expand Down
1 change: 1 addition & 0 deletions reference/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ billion-context/
│ ├── startup-failure-page.ts # Port-holding failure page when a launcher-spawned proxy dies (#5096)
│ ├── state-gc.ts # Opt-in retention GC for dump directories (size/age bounds) (#2412)
│ ├── state-hydration.ts # Single mergeState truth; persisted field list derived mechanically (#4242)
│ ├── storage-backup-repair.ts # bili storage backup / repair: verified index.db snapshot + corruption recovery (#7156)
│ ├── storage-maintenance.ts # bili sessions / bili storage gc CLI over store maintenance APIs (#3911)
│ ├── turn-separator.ts # Responses turn-separator id helpers, zero-dependency leaf (#2627)
│ ├── uncovered.ts # Uncovered-history audit: runs no active block can reach (#4331)
Expand Down
5 changes: 5 additions & 0 deletions scripts/live-files.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ export const LIVE_FILES = [
// the zone band is irrelevant; the entry is for the tripwire, like
// #5046/#4612.
"tests/storage-integrity-cache.test.ts",
// #7156: the only child is spawnSync("true") in freshDeadPid() — a
// guaranteed-dead pid for the stale-lock fixture; no ports, no servers,
// mkdtemp-isolated per test, so the zone band is irrelevant; the entry is
// for the tripwire, like #5046/#4612.
"tests/storage-backup-repair.test.ts",
];

/** Band width per live file: the zone ladder drifts +1 per EADDRINUSE retry;
Expand Down
Loading
Loading