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
2 changes: 1 addition & 1 deletion CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ Environment variables take precedence over the config file. They are useful for
| `BILI_SUBAGENT_SPLIT` | Set `0` to turn OFF Claude Code subagent session splitting (#970): by default, anthropic-wire requests carrying the `x-claude-code-agent-id` + `x-claude-code-parent-agent-id` pair (background subagents) get their own `<session>\|sub:<agent-id>` session — own lock chain and compression state — instead of queueing behind the main session's lock. Default is ON. `"subagentSplit": false` in the config file does the same; the env var wins. |
| `BILI_FORK_ADOPTION` | Set `1` to turn ON fork block-adoption (#629): when an anonymous (prefix-affinity) client forks its history mid-conversation (edit-and-resend / regenerate an earlier turn), the new session inherits the parent's compression blocks whose source content is fully present in the forked request — instead of restarting with zero compression state and re-folding the shared prefix from scratch. Default is OFF. `"forkAdoption": true` in the config file does the same; the env var wins. The adoptable inventory is logged on every anonymous fork even while disabled, so you can size the win before flipping it on. |
| `BILI_STABLE_SYSTEM_ANCHOR` | Set `1` to enable stable-system anchoring (#1085) — a **best-effort wire-layer fallback** for prefix caching: the root fix belongs client-side (the client owns its history and decides how to present instruction changes), this only stops the proxy from letting a changed head invalidate the whole cached prefix. **Plain-proxy mode only**: plugin-mode agents (`x-bili-plugin`) own their context management and are never anchored, so clients that already inject cache-friendly updates (e.g. claude-code-style system reminders) are not double-processed. When enabled, bili remembers each session's first-seen head system/instructions block and keeps re-sending those exact bytes even when the client's system prompt later changes. A **localized** change (a file-style edit sharing ≥70% of lines with the version in effect so far) appends a trailing `[System context update] …` user note carrying a compact line diff (`-` removed / `+` added; each note composes sequentially onto the previous one). A **non-localized** change (structural reshuffle, tool-def churn, timestamped banners, heads over 400 lines) is adopted outright — one deliberate cache miss beats appending noise that would mislead the model about its instructions. Churn guard: more than 8 accumulated notes likewise replace the anchor with the newest text and clear the log. The anchor and note log persist with the session and survive compression/compaction (session metadata, not kernel state). Known residual limitation: client-placed `cache_control` breakpoints may still misalign after a head swap. Excluded from anchoring: title-gen micro-requests (OpenAI/Google), Responses compaction-trigger requests, auto-mode classifier requests. Clients implementing their own variant (stable prompt + in-history updates) get zero extra injection — such updates pass through as ordinary history. Default is OFF. `"stableSystemAnchor": true` in the config file does the same; the env var wins. |
| `BILI_CHAIN_CONTENT` | Set `0` to turn OFF the ACP-artifact content fallback of bili→bili chain detection (#1086): when an inbound request carries compression artifacts (render tags / historical `acp_status`+`search_context` tool calls) but neither the `x-bili-hop` header nor local compression state for its session, it is passed through verbatim instead of being processed again (a middlebox may have stripped the hop header from a chained request). Default is ON. `"chainContentDetection": false` in the config file does the same; the env var wins. The `x-bili-hop` signal itself is unaffected by this switch. |
| `BILI_CHAIN_CONTENT` | Set `0` to turn OFF the ACP-artifact content detection of bili→bili chain awareness (#1086, advisory-only since #1357): when an inbound request carries compression artifacts (render tags / historical `acp_status`+`search_context` tool calls) but neither the `x-bili-hop` header nor local compression state for its session, bili records ONE advisory observation (a single `[chain]` warn, visible in `/acp`) and processes the request normally — the session establishes its own state. Historical ACP-shaped content is user-authored text (AGENTS.md examples, docs, pastes) far more often than a stripped-header relay, so it is no longer decisive; only the `x-bili-hop` header still forces byte-identical passthrough. Trade-off: a bili→bili relay that strips `x-bili-hop` may now double-process until signed request-bound chain proof lands (#1357 Phase 2/3). Set `0` to disable the detection itself (no observation, no warn). Default is ON. `"chainContentDetection": false` in the config file does the same; the env var wins. The `x-bili-hop` signal itself is unaffected by this switch. |
| `BILI_CHAIN_MAX_FUTURE_SKEW_MS` | Maximum future skew (ms) tolerated when validating a chain checkpoint's `issued-at` timestamp (#1395 step 2): a checkpoint stamped more than this far into the future is judged `stale` (replay / clock skew) even when its digest verifies. Default `120000` (2 min); non-numeric or non-positive values fall back to the default. Step 2 is shadow-only — these knobs tune verdict logging, never forwarding. |
| `BILI_CHAIN_RECENT_WINDOW_MS` | Recency window (ms) for chain-checkpoint validation (#1395 step 2): a checkpoint older than this is judged `stale`. Default `600000` (10 min); non-numeric or non-positive values fall back to the default. Step 2 is shadow-only — these knobs tune verdict logging, never forwarding. |
| `BILI_CONFLICT_SCAN` | Set `0` to disable third-party compression plugin detection (#1206). On by default: bili scans the client's own plugin/extension registries — opencode global + project `plugin` arrays, pi global + project `.pi/settings.json` `packages`, omp `config.yml` `extensions`, claude settings `enabledPlugins`/`plugins` + its plugins dir, kimi `plugins/installed.json`, hermes plugins dir, dsh profile dependencies — for another compressor co-resident with bili. Two tiers: **known conflicts** (`opencode-acp`, legacy `billion-context-pi`) and **keyword-suspected** entries (names matching compress / compact / acp / summar* / context*; bili's own entries are always skipped, and non-compression tools like `context7` do not match). Findings surface as launcher stderr lines before client start, a one-time proxy warn log on each session's first request, and the session's conflict ledger — visible in `acp_status`'s `COMPRESSION CONFLICTS` section, aggregated at `GET /__bili/stats` → `conflicts`, and shown as a web-UI banner. Runtime interference evidence (unannounced history rewrites #1001, orphan-block deactivations) feeds the same ledger. The scan is read-only, best-effort, 5-minute cached, and never blocks or modifies client config. |
Expand Down
2 changes: 1 addition & 1 deletion CONFIGURATION.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@
| `BILI_SUBAGENT_SPLIT` | 设为 `0` 关闭 Claude Code subagent 会话分流(#970):默认情况下,anthropic 线路上同时携带 `x-claude-code-agent-id` + `x-claude-code-parent-agent-id` 头的请求(后台 subagent)会获得独立的 `<session>\|sub:<agent-id>` 会话 —— 独立的锁链与压缩状态 —— 不再排在主会话的锁后面。默认开启。配置文件中设 `"subagentSplit": false` 效果相同;环境变量优先。 |
| `BILI_FORK_ADOPTION` | 设为 `1` 开启 fork 块继承(#629):匿名(prefix-affinity)客户端在会话中途分叉历史(编辑重发 / 从更早轮次重新生成)时,新会话直接继承父会话中"源内容在分叉请求里完整存在"的压缩块 —— 而不是从零开始、把共享前缀重新折叠一遍。默认关闭。配置文件中设 `"forkAdoption": true` 效果相同;环境变量优先。无论开关如何,匿名 fork 发生时日志都会记录可继承的块清单,便于先评估收益再开启。 |
| `BILI_STABLE_SYSTEM_ANCHOR` | 设为 `1` 开启稳定 system 锚定(#1085)—— **wire 层兜底(best-effort)**:根治在客户端(会话历史与指令变更的呈现方式由客户端决定),本开关只是阻止代理因头部变化而使整个已缓存前缀失效。**仅限 plain-proxy 模式**:plugin-mode agent(`x-bili-plugin`)自管上下文、永不参与锚定,避免对已自带 cache-friendly 更新注入的客户端(如 claude-code 的 system-reminder)做双重处理。开启后,bili 按会话记住客户端首次发送的头部 system/instructions 块并持续原样重发。**局部变更**(文件式编辑,与当前生效版本共享 ≥70% 行)追加末尾 `[System context update] …` user 注记,内含紧凑行级 diff(`-` 删除 / `+` 新增;每条注记顺序叠加在前一条之上)。**非局部变更**(结构性重排、tool 定义增删、带时间戳的 banner、超 400 行的头部)直接采用新文本 —— 一次有意的缓存失效好过追加会误导模型的噪声 diff。防抖保护:累积超过 8 条注记同样直接替换锚点为最新文本并清空日志。锚点与注记日志随会话持久化,不受压缩/compaction 影响(session metadata 而非 kernel state)。已知残留限制:客户端自放的 `cache_control` 断点在换头后仍可能错位。不参与锚定的请求:标题生成微请求(OpenAI/Google)、Responses compaction-trigger 请求、auto-mode classifier 请求。客户端自身已实现同类机制(稳定 prompt + 历史内更新)时零额外注入 —— 这类更新作为普通历史透传。默认关闭。配置文件中设 `"stableSystemAnchor": true` 效果相同;环境变量优先。 |
| `BILI_CHAIN_CONTENT` | 设为 `0` 关闭 bili→bili 链检测的 ACP 产物内容回退(#1086):当入站请求携带压缩产物(渲染标签 / 历史 `acp_status`+`search_context` 工具调用)但既无 `x-bili-hop` 头、本实例也无该会话的压缩状态时,请求被原样透传而不再次处理(中间设备可能已剥掉链路上的 hop 头)。默认开启。配置文件中设 `"chainContentDetection": false` 效果相同;环境变量优先。`x-bili-hop` 信号本身不受此开关影响。 |
| `BILI_CHAIN_CONTENT` | 设为 `0` 关闭 bili→bili 链感知的 ACP 产物内容检测(#1086,#1357 起为仅告警):当入站请求携带压缩产物(渲染标签 / 历史 `acp_status`+`search_context` 工具调用)但既无 `x-bili-hop` 头、本实例也无该会话的压缩状态时,bili 只记录一次告警性观察(单条 `[chain]` warn,可在 `/acp` 查看)并正常处理请求——该会话建立自己的状态。历史中的 ACP 形内容绝大多数是用户自撰文本(AGENTS.md 示例、文档、粘贴),而非被剥头的中继,因此不再作为决定性依据;只有 `x-bili-hop` 头仍强制字节级原样透传。代价:剥掉 `x-bili-hop` 的 bili→bili 中继在签名的请求绑定链证明落地前(#1357 Phase 2/3)可能被双重处理。设为 `0` 则关闭检测本身(不观察、不告警)。默认开启。配置文件中设 `"chainContentDetection": false` 效果相同;环境变量优先。`x-bili-hop` 信号本身不受此开关影响。 |
| `BILI_CHAIN_MAX_FUTURE_SKEW_MS` | 校验链检查点 `issued-at` 时间戳时容忍的最大未来偏斜(毫秒)(#1395 step 2):戳在比当前时间未来超过此值的检查点会被判为 `stale`(重放 / 时钟偏斜),即使其摘要校验通过。默认 `120000`(2 分钟);非数字或非正值回退到默认值。Step 2 仅影子模式——这些旋钮只调判定日志,绝不影响转发。 |
| `BILI_CHAIN_RECENT_WINDOW_MS` | 链检查点校验的近期窗口(毫秒)(#1395 step 2):早于此窗口的检查点被判为 `stale`。默认 `600000`(10 分钟);非数字或非正值回退到默认值。Step 2 仅影子模式——这些旋钮只调判定日志,绝不影响转发。 |
| `BILI_CONFLICT_SCAN` | 设为 `0` 关闭第三方压缩插件检测(#1206)。默认开启:bili 会扫描客户端自身的插件/扩展注册表 —— opencode 全局 + 项目配置的 `plugin` 数组、pi 全局 + 项目 `.pi/settings.json` 的 `packages`、omp `config.yml` 的 `extensions`、claude 设置的 `enabledPlugins`/`plugins` 及其插件目录、kimi `plugins/installed.json`、hermes 插件目录、dsh profile 依赖 —— 查找与 bili 并存的另一个压缩器。两个层级:**已知冲突**(`opencode-acp`、遗留 `billion-context-pi`,确定性判定)和**关键词疑似**条目(名称匹配 compress / compact / acp / summar* / context*;bili 自身条目永远跳过,`context7` 这类非压缩工具不会误报)。发现结果出现在:客户端启动前的 launcher stderr、每个会话首个请求的一次性代理 warn 日志、以及会话冲突台账 —— `acp_status` 的 `COMPRESSION CONFLICTS` 段、`GET /__bili/stats` → `conflicts`、Web UI 横幅。运行时干扰证据(未宣告的历史改写 #1001、孤儿块废弃)记入同一台账。「扫描只读、尽力而为、5 分钟缓存,绝不阻塞或改动客户端配置。」 |
Expand Down
10 changes: 6 additions & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,10 +590,11 @@ export type ProxyOptions = {
* fully-present compression blocks instead of restarting at zero.
* Enable with `forkAdoption: true` or env BILI_FORK_ADOPTION=1. */
forkAdoption?: boolean;
/** Content fallback of the bili→bili chain detection: when an inbound
/** Content detection of the bili→bili chain awareness: when an inbound
* request carries ACP artifacts (render tags / ACP tool-call history)
* but no x-bili-hop header and no local compression state for the
* session, pass it through verbatim instead of processing (#1086).
* session, record one advisory observation and process normally (#1086,
* advisory-only since #1357) — never verbatim passthrough.
* Default ON; escape valve via env BILI_CHAIN_CONTENT=0 or
* `chainContentDetection: false` in the config file (env wins). The
* x-bili-hop signal is unaffected by this switch. */
Expand Down Expand Up @@ -937,8 +938,9 @@ type FileConfig = {
* zero compression state. Default false; env BILI_FORK_ADOPTION=1/0
* wins over the file. */
forkAdoption?: boolean;
/** Set `false` to disable the ACP-artifact content fallback of the
* bili→bili chain detection (#1086); x-bili-hop stays active either way.
/** Set `false` to disable the ACP-artifact content detection of the
* bili→bili chain awareness (#1086, advisory-only since #1357);
* x-bili-hop stays active either way.
* Env BILI_CHAIN_CONTENT=0 wins over the file. */
chainContentDetection?: boolean;
/** Set `true` to enable the sticky head-system anchor (#1085, default
Expand Down
26 changes: 14 additions & 12 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,12 +686,14 @@ export function _chainVerdictMapForTest(): Map<string, ChainVerdict> {
return chainVerdicts;
}

/** #1218: the /acp panel rendered when a conversation is being passed through
* unprocessed. Every /acp surface (pi / dsh / opencode) displays `panel`
* verbatim, so the server renders the verdict once and all clients show it
* without agent-side changes. */
function chainPassthroughPanel(v: ChainVerdict): string {
return `⚠️ billion-context: this conversation is being PASSED THROUGH UNPROCESSED — judged an external bili chain by the content fallback (evidence: ${v.kind}, protocol ${v.protocol}). No local compression session exists, so compression is silently disabled for this conversation. Last passthrough: ${new Date(v.at).toISOString()}. If this is your own client, disable the content fallback (chainContentDetection=false, env BILI_CHAIN_CONTENT=0); see the [chain] warn in the bili log.`;
/** #1357 Phase 1: the /acp panel rendered when a conversation carried
* historical ACP content with no prior local state. That content is now
* ADVISORY-only — observed but NOT treated as a foreign chain, so the request
* was processed normally and the conversation owns its own compression session.
* Every /acp surface (pi / dsh / opencode) displays `panel` verbatim, so the
* server renders it once and all clients show it without agent-side changes. */
function chainAdvisoryPanel(v: ChainVerdict): string {
return `ℹ️ billion-context: this conversation carried ACP-shaped content (evidence: ${v.kind}, protocol ${v.protocol}) with no prior local compression state. Historical ACP content is advisory-only (#1357) — it was NOT treated as a foreign bili chain, so the request was processed normally and this conversation owns its own compression session. Last observation: ${new Date(v.at).toISOString()}. See the [chain] warn in the bili log.`;
}

export function handlePluginStatus(conversationId: string, res: import("node:http").ServerResponse, deps: PluginToolDeps, fallbackLatest = false): void {
Expand All @@ -716,15 +718,15 @@ export function handlePluginStatus(conversationId: string, res: import("node:htt
}
}
if (!session) {
// #1218: a chain/content-fallback verdict for THIS conversation means
// requests ARE arriving — passed through unprocessed — so the
// armed-idle notice would mislead ("no model request yet" is false).
// Answer 200 with a renderable panel; `phase` exposes the state for
// programmatic consumers.
// #1357 Phase 1: a content-fallback verdict for THIS conversation means
// requests ARE arriving and carried historical ACP content — now an
// ADVISORY observation (processed normally), so the armed-idle notice
// would mislead ("no model request yet" is false). Answer 200 with a
// renderable panel; `phase` exposes the state for programmatic consumers.
const verdict = chainVerdictFor(conversationId);
if (verdict !== undefined) {
res.writeHead(200, { "content-type": "application/json" });
res.end(JSON.stringify({ ok: true, conversationId, phase: "chain-passthrough", chain: verdict, panel: chainPassthroughPanel(verdict) }));
res.end(JSON.stringify({ ok: true, conversationId, phase: "chain-advisory", chain: verdict, panel: chainAdvisoryPanel(verdict) }));
return;
}
// Runtime-info protocol (#955): no session exists yet, but the client
Expand Down
Loading
Loading