Skip to content

[PR] fix: prompt_cache_key self-injection disabled by default, promptCache.routing one switch controls both wires (#5079) | fix: prompt_cache_key 自注入默认关闭,promptCache.routing 一个开关管住两条 wire (#5079) - #5112

Merged
ranxianglei merged 10 commits into
masterfrom
2026-10-29_pck-default-off
Oct 29, 2026

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

(ai: vllm-qwen/qwen3.8-27b)

Closes #5079

是什么

prompt_cache_key 只对少数中转站有用,而大量服务见到这个 header/body 字段会直接拒绝请求,这样的服务无法枚举。本 PR 把 bili 自己铸造的 key 默认关掉,并给出一个用户可见的开关(web UI + config + env),升级用户会收到一次性提示。

行为变更(旧 → 新,rule 4 披露)

# 变更 旧值 新值
1 promptCache.routing 默认值(两条 wire 同时生效) auto disabled
2 Chat wire 插件车道 body 盖章 无条件盖(未受 routing 控制) 受 routing 控制:disabled 不盖,auto/enabled 照旧全盖
3 插件车道上 body key == 绑定会话 id 的回显(dsh PI_CACHE_RETENTION=long 栈、omp 扩展盖章) 视为客户端 key 原样放行 识别为 bili 自家机制回显,受 routing 控制(disabled 剥除)
4 Responses wire 在真实 api.openai.com 上的注入(codex 直连官方场景) auto 下自动注入 disabled 默认下不再注入(退回内容路由;auto/enabled 恢复)
不变 客户端自己带的 prompt_cache_key(任何车道、任何模式) 原样转发 原样转发,不受影响
不变 egress A/B probe-and-remember(#2645/#3813) 探测到拒绝即记忆剥离 不受影响,所有模式下继续兜底
不变 入站身份提升(pck 作为会话身份来源,#2218 系) 生效 不受影响

config surface

没有新增配置形状——复用既有 promptCache.routing(file / ACP_PROMPT_CACHE_ROUTING env / web UI 三入口),仅翻转默认值 auto→disabled,并把它的管辖面从「Responses wire 注入」扩到「两条 wire 上 bili 自铸 key 的全部出口」。web 配置页新增快速配置下拉(disabled/auto/enabled),走既有 PUT /__bili/config 热应用路径(该路径现在也会刷新 opts.promptCache)。现有配置文件无需迁移:写了 auto/enabled 的保持原行为;没写的从「auto」变为「disabled」——这正是 issue 要求的策略反转。

升级提示(issue 要求:第一次升级到该版本要收到)

一次性通知,有效条件 = 生效 routing 为 disabled 且未被本实例关闭;关闭状态持久化(upgrade-notices.json,与 host-plugin 通知同一纪律):

  • web:概览页顶部横幅 + 关闭按钮(POST /__bili/notices/dismiss);
  • /acp:acp_status 输出一行 PCK SELF-STAMPING OFF BY DEFAULT (instance-level, #5079);
  • 启动日志:一行 info。

文案点名具体软件(按 issue 要求):workbuddy panel/hub(中转站类)、号池场景——这类上游按该 key 路由前缀缓存,不开启会导致流量随机路由、频繁不命中;直连官方 API 的用户可忽略。

测试

  • 新增 tests/issue5079-pck-default-off.test.ts:parsePromptCacheRouting 默认行、两条 wire 的判定矩阵(disabled/auto/enabled × 回显 vs 真客户端 key)、responses 显式 key 的身份源规则、notice 模块(XDG_STATE_HOME tmpdir)、真实代理出站断言(默认关→body 无 key 但 x-session-id 保留;回显被剥;客户端 key 原样;auto 恢复盖章)。正负成对。
  • tests/issue2218-relay-affinity-signal.test.ts 单测矩阵跟进新签名;两个非插件无 key 行的期望 keep-client→drop(删不存在的 key,行为等价)。
  • 定向验证:node --import tsx --test 跑 issue5079/issue2218/issue2645/issue3813 四套 = 100 pass / 0 fail;typecheck 0 error。全量回归交 CI。
  • 已核对全部 408 个测试 harness 均显式写 routing:"auto",默认翻转不会波及存量测试语义。

回归审查摘要

触碰路径的既有行为逐项过:客户端 key 通道(keep-client)、A/B 消融(drop)、Anthropic wire 剥离(#1403)、passthrough 逐字节转发、入站身份提升——均未改动且有测试钉住;唯一有意的行为变化即上表 1–4 项。

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-29_pck-default-off (d79232d)

Latest build — install this exact version

npm install -g billion-context@0.0.6748-pr.5112.d4ca00a

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Recent builds (commit → version)

commit version build
d79232d billion-context@0.0.6748-pr.5112.d4ca00a build
45109ef billion-context@0.0.6747-pr.5112.81aa01c build
b29e36e billion-context@0.0.6746-pr.5112.c13b044 build
2e26be5 billion-context@0.0.6741-pr.5112.dfef67f build
ceb92ca billion-context@0.0.6737-pr.5112.531333f build
994d31d billion-context@0.0.6731-pr.5112.3ee74c4 build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr5112.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix: prompt_cache_key 自注入默认关闭,promptCache.routing 一个开关管住两条 wire (#5079) [PR] fix: prompt_cache_key self-injection disabled by default, promptCache.routing one switch controls both wires (#5079) | fix: prompt_cache_key 自注入默认关闭,promptCache.routing 一个开关管住两条 wire (#5079) Oct 29, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

docs-sync 红 = 文档与代码默认值漂移。根因已定位并修好(本地已提交、已验证),但 push 被临时网络中断卡住,commit 尚未落到 PR 分支。

一句话:这个 PR(#5079)把 promptCache.routing 默认值从 auto 翻成 disabled,作者同步手改了 CONFIGURATION.md / CONFIGURATION.zh-CN.md,但漏掉了唯一事实源 website/config-reference/server.yaml(仍是 auto)。docs-sync 以 yaml 为准重新生成文档 → 又吐回 auto → 和已提交的 disabled 冲突 → 红。

七问:

  1. 是什么问题:docs-sync 门禁失败——由 yaml 生成的配置文档与已提交的文档不一致(drift)。
  2. 什么原因导致的:作者翻转了代码默认值并手改两份 md,却没同步 yaml 种子(单一事实源)。生成器读 yaml → 重新生成出旧默认 auto → 与 md 手改的 disabled 对不上。
  3. 影响范围与严重程度:仅构建门禁,零运行时/功能影响;不修则此 PR 合不了(门禁常红)。
  4. 怎么修复的:把 yaml 种子 promptCache.routing 默认值改为 disabled、en/zh 描述对齐到 PR 已提交的那版文案;重跑生成器后 4 个产物全部干净。已核对代码默认值确为 disabled(src/config.ts parsePromptCacheRouting),所以文档写 disabled 是对的,不是把文档改回去凑绿。
  5. 是否有回归问题:无。只动 yaml 种子 3 行,不改任何 TS/行为;本地已过 docs-coverage(188 env + 59 top-level keys 全覆盖)与 config-surface-guard(175 leaf fields)两道守卫。
  6. 是否破坏缓存:不涉及(纯文档元数据)。
  7. 是否改了设计方向 / 引入新配置:都不涉及——只是让文档追上 PR 本意要表达的默认值翻转。

当前卡点(非代码问题):GitHub 出站通道暂时中断(代理连接反复被重置),连续十余次 push / ls-remote 均失败;修复 commit 8747e5836 已在本地就绪但未推到 PR 分支。属环境瞬时故障,不需要 owner 拍板的设计决策。

下一步:出站恢复后 push 即绿(本 auto-fix lane 还有 attempt 2/2 会自动重试);无需你做任何操作。若长时间未恢复我会再补报。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

查重: 不重复——本 PR 就是 #5079 的实现(同线程已有 triage 批准与完成报告);相关历史 #2218/#2645/#2649/#5104 是同一 pck 机制族的前置 issue,不是平行工单。

标签: scope/wiring + p2 + dsh + codex(wire 改写面;策略翻转有绕行且带一次性提示,非可用性缺陷;dsh 回显机制与 codex 直连官方场景被点名)。

独立 review 进行中(未照抄 issue 结论,diff 逐文件重读)。已发现并在 PR 分支上直接修掉两处问题:

  1. docs-sync CI 红:PR 手改了 CONFIGURATION.md(+zh)生成的索引表/env 表,但没同步种子 website/config-reference/server.yaml(仍写 default: "auto" + 旧描述),生成器每次重跑都会把那 4 行翻回去 → docs-sync job 必红。已在本地复现并修种子,重新生成后与提交内容逐字节一致。
  2. parsePromptCacheRouting("auto") 被映射成 "disabled":src/config.ts 里新解析器只放行 enabled/disabled,显式写了 "auto" 的存量配置会被静默改写成新默认关——这违反 PR 自己承诺的「写了 auto/enabled 的保持原行为」,也是 PR 自带测试断言的直接矛盾(该用例在 PR head 上是红的)。已修:显式 auto 保持原义,缺省/未知值才落 disabled。

修复后定向验证:typecheck 0 error;issue5079/issue2218/issue2645×2/issue3813 五套 = 27 pass / 0 fail(PR 原 head 上是 26/1)。已 rebase 到当前 master(base 只动了 README,无冲突)。

GitHub 出站网络此刻抖动(push/fetch 间歇失败),推分支 + CI 全量结果稍后补报;CI 绿后给结构化八问最终结论。

@ranxianglei
ranxianglei force-pushed the 2026-10-29_pck-default-off branch 2 times, most recently from ceb92ca to 2e26be5 Compare October 29, 2026 08:00
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

审核进展(第二轮):上一轮 push 后 CI 主流程 test shards 红,拉日志定位到两处新问题——都是本 PR 引入的确定性缺陷,与 master 红绿无关。已修并推上分支(新 head b29e36e45)。

问题 1(严重):web 客户端 IIFE 里 const pb 同域重复声明,整个面板 JS 加载即崩。
src/web/client.ts 的嵌入式浏览器端代码是一个内联在 TS 文件里的 IIFE 字符串;renderBanners(d) 作用域里旧代码已有 const pb = $("plugin-advisory-banner"),本 PR 新增的 pck 通知块又用了 const pb = $("pck-notice-banner") → V8 加载时直接 SyntaxError: Identifier 'pb' has already been declared,所有基于 vm 加载该 IIFE 的 web 套件(web-routing / web-i18n / web-blog-route / web-handoff-roles / web-trajectory-brush)全灭。typecheck 抓不到它的原因:这段 IIFE 对 tsc 而言是字符串文本,tsc 只做 TS 层类型检查,字符串体内的标识符冲突不可见——所以本地 typecheck 绿、CI 静态门禁绿、一到跑测试才爆。已改为 nb(commit 717fa1f88)。

问题 2:tests/routing.test.ts 钉着旧默认值。
既有解析器测试断言 parsePromptCacheRouting("unknown") === "auto"(#5079 之前的回退语义),与新契约(unknown→disabled)矛盾,且与本 PR 自己的 issue5079 套件互相打架。PR 里「全部 harness 显式写 routing:auto」的排查覆盖了 harness 配置对象,漏了这个直接测解析器回退的单测。已更新为新契约(commit b29e36e45)。

**本地定向验证(新 head):**web 五套件 112 pass / 0 fail,routing 25/25,pck 家族(issue5079/2218/2645×2/3813)27/27,typecheck 0 error。CI 全局结果出来后再报;最终结论按结构化八问给。

ci-check and others added 10 commits October 29, 2026 17:09
…ng gates both wires (#5079)

The egress key was only useful to a minority of relay upstreams while a large unknown set of services hard-rejects requests carrying it, and that set cannot be enumerated. Flip the default of promptCache.routing from auto to disabled and make it the single switch for bili's OWN key emission on both wires: the chat-wire plugin-lane body stamp now honors it too (previously ungated), and a plugin-lane body key equal to the bound conversation id is recognized as bili machinery echoing back (dsh PI_CACHE_RETENTION stack, omp extension stamp) rather than client intent. Client-supplied keys still forward verbatim in every mode; the egress A/B probe-and-remember is untouched.
…UI switch (#5079)

Users upgrading onto relay/account-pool upstreams (workbuddy panel/hub, account pools) must know to re-enable routing or their prefix-cache affinity silently degrades to random routing. The notice is active while the effective routing is disabled and until dismissed per instance (state file upgrade-notices.json, same discipline as host-plugin notices): web banner with dismiss button (POST /__bili/notices/dismiss), acp_status line, and a startup log line. The web config page gains a quick-config switch (disabled/auto/enabled) hot-applied through the existing PUT /__bili/config path; PUT now also refreshes opts.promptCache.
…w signature

New suite covers parsePromptCacheRouting defaults, both wire decision matrices (disabled/auto/enabled incl. bili-owned echo vs genuine client key), the responses explicit-key echo rule with identity source, the pck-notice module under XDG_STATE_HOME tmpdirs, and live-proxy egress assertions (default-off strips the stamp but keeps x-session-id; echo stripped; client key verbatim; auto restores stamping). The issue2218 unit matrix adopts the routing/sessionId parameters; its two non-plugin no-key rows flip keep-client->drop (no-op normalization).
CONFIGURATION en/zh: default column and section rewritten for the disabled default, both-wires semantics, client-key rule, entry points. TECHNICAL-NOTES en/zh: policy-reversal section superseding #2649's default-on ruling. CHANGELOG: Unreleased entry with the old->new behavior disclosure.
…5079)

The docs-sync CI job regenerates CONFIGURATION.md(+zh) generated blocks
from website/config-reference/*.yaml and fails on drift. The #5079
default flip (auto -> disabled) was applied to the generated tables by
hand but the seed entry kept default "auto" plus the pre-#5079
descriptions, so every regeneration reverted those four lines. Update
the seed (default + en/zh descriptions) so the generator reproduces the
committed tables byte-for-byte.
parsePromptCacheRouting mapped every value other than enabled/disabled
to disabled — including an explicit "auto". That silently rewrote
existing configs that wrote routing:"auto" into the new default-off
posture, contradicting the #5079 migration promise (wrote auto/enabled
keeps pre-#5079 behavior; only configs that never set it change). The
PR's own new test asserts parsePromptCacheRouting("auto") === "auto"
and was red on this head. Accept "auto" as a valid value; absent and
unknown values still fall back to disabled.
The #5079 banner block re-declared const pb inside renderBanners(),
where pb already names the plugin-advisory banner element -> SyntaxError
(Identifier 'pb' has already been declared) at IIFE load, which took down
every vm-based web suite (web-routing/web-i18n/web-blog-route/
web-handoff-roles/web-trajectory-brush). The embedded IIFE is a string in
client.ts, so tsc never type-checks its body; renamed to nb.
The pre-existing parser test pinned the old fallback (unknown -> auto);
#5079 flips the default to disabled and the PR's own issue5079 suite
asserts the new contract, so this pin now follows it.
@ranxianglei
ranxianglei force-pushed the 2026-10-29_pck-default-off branch from 45109ef to d79232d Compare October 29, 2026 09:09
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

Review 完成,判定:可合。 最后一轮又发现并修掉了 2 处缺陷(#5、#6,见下),连同前两轮已报的 4 处,全部以独立标注 commit 修在 PR 分支上。最新 head d79232d97 已 rebase 到当前 master(master 新进的 3 个提交是 #5115 测试隔离,与本 PR 文件零重叠,rebase 无冲突)。本地:typecheck 0 error,定向套件 44/44 绿(issue5079/issue2218/routing/marker-render-contract + 其余 pck 套合计 27/27)。全量回归以本 head 的 CI 为准,绿了我补一条确认。

结构化八问

  1. 是什么问题:bili 会无条件给自己经中转发出的请求盖上自铸的 prompt_cache_key,而相当一部分上游服务见到这个字段直接拒请求(Power-Loss Restart Protection Fails to Auto-Recover billion-context Startup Failure on DSH — Troubleshooting Report | 断电重启保护无法自动恢复 billion-context 在 DSH 上启动失败 — 排查报告 #5104 实锤 400)。本 PR 把自注入默认关掉,一个开关 promptCache.routing 同时管住两条 wire。
  2. 什么原因导致的:[PR] fix(#2645): gate the openai prompt_cache_key stamp to loopback destinations #2649「auto-stamp by default」的设计假设未知服务会忽略这个字段,没有枚举出会整体拒绝 pck 的服务类——对拒绝型服务该假设不成立,可用性优先于缓存亲和。
  3. 影响范围与严重程度:拒绝型中转站用户升级后不再 400(可用性修复,直接受益);按该 key 路由前缀缓存的中转站(号池 / workbuddy panel/hub 类)若不开回 auto,流量随机路由、频繁不命中——有三通道一次性提示(web 横幅 + acp_status 行 + 启动日志)点名这类用户并给出开启方式;直连官方 API 不受影响。
  4. 怎么修复的:routing 管辖面从「Responses wire 注入」扩到「两条 wire 上 bili 自铸 key 的全部出口」;新增 bili 自家回显识别(插件车道 body key == 绑定会话 id 判为自家机制回显,受 routing 控制);客户端自带的 key 任何模式原样转发;一次性升级通知(关闭状态持久化,与 host-plugin 通知同纪律、独立文件不冲突)。
  5. 是否有回归问题:触碰路径的既有行为逐项过——客户端 key 通道 ✓、A/B probe-and-remember 兜底(openai wire: prompt_cache_key stamped unconditionally — breaks strict-schema upstreams (NVIDIA NIM 400), no config escape #2645/[review] v0.1.202 release-review leftovers: zcode watchdog recovery latency, responses lane ignores pck ablation memory, URL-image id churn, nudge low-water ratchet | 发版审核遗留小项(不阻塞) #3813,所有模式继续生效)✓、Anthropic wire 剥离([Bug] bili omp 扩展 stampPromptCacheKey 无条件注入顶层 prompt_cache_key —— 严格 schema 上游(opencode zen anthropic 端点)全量 400 #1403)✓、passthrough 逐字节转发 ✓、入站身份提升(上游侧失效导致缓存命中只有80%用的api反代 workbuddy glm5.3 #2218 系)✓、非插件车道「删不存在的 key」行为等价 ✓。唯一有意变更即 PR 正文表 1–4 项。另:PR 自身携带的 6 处潜在回归在 review 中全部拦下修复(下表),若不合入这些修复,合并后 CI 必红多套。
  6. 是否破坏缓存:不涉及——pck 是出站亲和信号不是缓存存储,前缀缓存机制本身未动,只是信号的默认开/关态变了。
  7. 是否改了设计方向:无新架构——复用既有 promptCache.routing,翻默认值 auto→disabled,扩管辖面;TECHNICAL-NOTES 已记录 supersedes [PR] fix(#2645): gate the openai prompt_cache_key stamp to loopback destinations #2649 裁决。
  8. 是否引入了新的配置:无新配置形状(file / env / web UI 三入口均为既有);upgrade-notices.json 只存用户关闭提示的意图,不存行为状态。

Review 发现并已修的 6 处缺陷(每处独立标注 commit)

前两轮已报过 #1–#4(seed 漂移、显式 auto 被解析吞掉、web 内嵌浏览器代码里重复声明变量导致整套 vm 测试崩、旧默认值测试钉未跟进),此处补最后两处:

# 缺陷 后果 修法
5 四处运行时代码裸读 opts.promptCache.routing(启动日志 / overview / chat wire / responses wire),但大量既有 harness 用不带 promptCache 段的 partial ServerOptions 起服务 TypeError 直接崩掉多套测试(announceListening 等) 新增 effectivePromptCacheRouting() 空安全 helper,统一走 parse 默认值兜底
6 新增的 /acp PCK 提示行没有登记进 acp_status 报告体消费契约的 section 白名单(src/marker/status-body.ts) marker-render-contract 红;生产上这行会被 body 消费者漏吃 白名单登记该行前缀 + 头部镜像注释同步

回归审查清单(②)

diff 触碰路径承担的既有行为:keep-client 通道、A/B 消融、Anthropic strip、passthrough、身份提升、PUT /__bili/config 热应用(PR 顺带补上了该路径对 opts.promptCache 的热刷新——此前改这个段要重启,现与其他字段一致,属 PR 已披露内容)、notice dismiss 永不改变 routing——逐项保持或已披露变更。高危模式(fail-fast 变吞错、阈值/时序漂移、输出格式漂移):未发现。

测试有效性(④)

新增 issue5079 套件正负成对且断言有牙:两条 wire 的判定矩阵(disabled/auto/enabled × 回显 vs 真客户端 key)+ 真实代理出站断言(port 0 / listen(0),确定性),bug 回归时抓得住;存量 5 套 pck 相关套件本地跑过 27/27。

判定:可合。 本 PR 属默认值/产品策略变更(AGENTS.md §7.4 must-stay-human),CI 绿后合并动作留给 @ranxianglei。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

CI 确认:head d79232d97 全绿——主 CI 的 11 个 test shard(ubuntu-22×3 / ubuntu-24×3 / windows-22×5)、docs-sync、全部 guard/static-gates 均 success,外加 13 条 e2e/辅助 lane 全 success(red-signal 为条件 lane,正常 skip)。前两轮报红的 shard 全部转绿。

Review 收工:可合,等 @ranxianglei 合并(默认值变更按 §7.4 留人工)。

@ranxianglei
ranxianglei merged commit 93598ec into master Oct 29, 2026
55 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.911-master.93598ec (rolling master tag).

npm install -g billion-context@0.0.911-master.93598ec  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant