Repository navigation
fix(#2218/#1931): forward dsh plugin-lane session signal to relays (x-session-id + gated prompt_cache_key stamp) - #2240
Conversation
The built-in pi-lane acp_delegate surface reads its config from bili's own config file (pi.subagents section) instead of pi's acp.json. The four acp.json keys (delegate/delegatePrompt/displayUsage/debug) become a deprecated fallback: still read while the section is absent (one-time warning), ignored once it exists. prompt replaces delegatePrompt; debug is scoped to the sub-agent subsystem. The standalone package reads the same section through its own loader (billion-context-pi-subagents#5) — the file format is the contract, no shared code. Co-Authored-By: Claude <noreply@anthropic.com>
The docs-sync drift guard (#2107) caught hand-edited generated blocks — the quick-ref and env-map rows now come from the seed in website/config-reference/server.yaml like every other key; the narrative pi section (field table + env overrides) stays hand-written outside the generated blocks.
dsh desktop's only conversation identity is the bili-internal x-bili-plugin-conversation header, which no third-party upstream can read: header-keyed relays (workbuddy hub, sub2api openai wire) lost sticky routing and body-keyed relays (workbuddy panel) fell to a content digest, so every account migration froze the provider prefix cache (#2218 80% hit-rate sessions; #1931 seed-drift class). - buildForwardTarget: treat the plugin conversation header like 'no header' — forward the client affinity as x-session-id - prepareOpenai: stamp prompt_cache_key = conversation id for the plugin lane when the client sent none, gated to admin-rewritten or loopback destinations (strict direct APIs can 400 unknown body params, #1403); the client's own value always wins
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2317-pr.2240.0390c00This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2240.tgz
npm install -g packageInstall instructions are refreshed on each push. |
…p gate Review finding on 76c6fe9: isLoopbackAddress only matches 127.x/::1 literals, so an upstream configured as http://localhost:N would silently fail the destination gate and the body stamp would not fire — reproducing exactly the zero-signal absence this fix removes. The codebase already treats "localhost" as loopback in upstream-proxy.ts / launcher.ts / config.ts; align the gate locally (shared util untouched).
[bot] 🏷 PR #2240 Review 结论:代码侧通过;等新 head CI 转绿即可合并(4 个 test job 红为已知基线问题 #2238,非本 PR 引入) ① 是什么问题:dsh 桌面插件 lane 的请求到达第三方中转时零可用会话信号——其唯一身份载体是 bili 内部头 ② 什么原因导致的:bili 两条既有出站信号通路对插件 lane 恰好双双失效——(a) ③ 怎么修复的:双路互补、互不重叠——内部头视同"无头",把客户端亲和值原样转发为 ④ 是否有回归问题:触碰路径既有行为逐项清点—— ⑤ 是否破坏缓存:否。stamp 是顶层 body 参数 + 出站头,模型不可见,不进消息重建/压缩状态/session key;bili 自身前缀缓存、重试、去重、增量游标均不受影响。改善对象正是上游账号池粘性命中率(修复目标本身)。 ⑥ 是否改了设计方向:否。沿用既有 affinity 设计原则——「只转发客户端已提供的身份值」(session-id.ts doc + README);pck stamp 是插件 lane 的新出站载体而非新信号源,目的地类型门控防止污染严格直连 API。 ⑦ 是否引入新的配置:否。门控复用现有 providers/route 配置 + loopback 判定,无新 env var / config 项 / 默认值。 测试有效性(质量关):6 用例是真 e2e( 两个小发现:
CI 状态(关键):head 判定:根因定位准确、修在机制层而非症状层、门控保守、测试有牙——review 通过,待 CI 复跑绿后由人合并。 |
[bot] 🏷 CI 状态更新:最终 head 全部 25 个 lane 分支当前栈: |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.71-master.c23f365 # this exact build
npm install -g billion-context@master # always the newest merged build
|
是什么问题
dsh 桌面经 bili 连第三方中转(relay)时,上游侧拿到的会话信号为零,导致中转的账号粘性/缓存路由全部失效:
prompt_cache_key> 内容摘要;零信号的流量落到内容摘要,bili 折叠改写历史时种子漂移 → 换号丢缓存(ework 首报的「折叠点粘性种子漂移」机制,dsh lane 是其最坏情形——连段内稳定都没有)。根本原因(代码级)
dsh lane 的唯一身份信号是 bili 内部协议头
x-bili-plugin-conversation(与 markerx-bili-plugin成对,dsh-native.ts 构造)。两条既有通路对它全部失效:src/server.tsbuildForwardTarget 的x-session-id兜底:if (affinity && !clientConversationHeader(req.headers))——clientConversationHeader的名单第一项就是 x-bili-plugin-conversation(session-id.ts:69),所以插件头反而抑制了兜底;而第三方上游根本读不懂这个内部头 → header 路失效。src/agent/pi.tsstampPromptCacheKey 的 bodyprompt_cache_key注入:if (agent !== "omp") return([Bug] bili omp 扩展 stampPromptCacheKey 无条件注入顶层 prompt_cache_key —— 严格 schema 上游(opencode zen anthropic 端点)全量 400 #1403 门控)—— dsh 不是 omp → body 路也失效。探针实证(tests/zz-probe,本 PR 已转正为回归测试):dsh lane 请求到达 mock 上游时
x-session-id与 bodyprompt_cache_key双双为 undefined;对照普通客户端 + body pck 两信号俱全。workbuddy 侧读法(决定修复矩阵):
X-Conversation-Id/X-Session-Id等(不读 body pck)→ 靠头修复;ExtractKey只读 body(metadata→conversation_id→prompt_cache_key→内容派生),头完全不参与 → 靠 body 修复;如何解决
两处互补修复,互不重叠:
src/server.tsbuildForwardTarget):x-bili-plugin-conversation是 bili 内部头,上游读不到 → 视同"无头",把客户端亲和值照常转发为x-session-id(hub/sub2api 家族恢复粘性)。普通可读头(codexsession-id等)保持原抑制逻辑不变(不造重复头)。src/server.tsprepareOpenai + 新助手src/session-id.ts shouldStampRelayAffinityPck):插件 lane 持有身份、客户端没发自带prompt_cache_key时,把会话 id 盖进出站 bodyprompt_cache_key(panel 家族恢复粘性)。门控(三条件同时满足):客户端自带 pck 原样透传(openai lane 既有行为不变)。
副作用收益:本机 glm-proxy(读
x-session-id做粘性)同样恢复稳定账号路由。是否能合并
tests/issue2218-relay-affinity-signal.test.ts6 用例全绿:门控矩阵(6 断言)/普通客户端 body pck 回归(双信号)/dsh lane 双信号(loopback+无 route 腿)/客户端自带 pck 不覆盖/可读头不造重复 x-session-id 且不盖 pck。URL