Skip to content

fix: recognize the dsh title sidecar on the anthropic wire (#3149) - #3153

Merged
ranxianglei merged 3 commits into
ranxianglei:masterfrom
deshark42:2026-10-14_dsh-title-sidecar-anthropic
Oct 14, 2026
Merged

ranxianglei merged 3 commits into
ranxianglei:masterfrom
deshark42:2026-10-14_dsh-title-sidecar-anthropic

Conversation

@deshark42

Copy link
Copy Markdown

根因

isDshTitleRequest(#2503)只在 messages[] 里找 role === "system" 的条目。而 dsh 0.2.1-alpha.2 的原生(anthropic)lane 上,标题提示词走顶层 system 字段,messages[] 里只有那个 user blob → 谓词返回 false → 标题请求没被 sideRequestLike 拦下,于是参与 persona 锚定(src/server/handle.ts:832 的 dshPersona && !sideRequestLike),用标题 prompt 抢走了裸 key;真正的主回合随后 system 变化 + 历史不连续 → fork 到 |sub:<fp>(0.1.196 上是 src/persona-anchor.ts 的 fp 阶梯,master 上是 src/session-resolve.ts 的顺序解析,两者都会分叉)。

第二个后果同 #2156:标题先到时,宿主盖章的 compress / acp_status 会路由进那个幽灵空账本。

#2503 只覆盖了 OpenAI 形状 —— tests/dsh-title-sidecar-handle.test.ts 当时的注释写的是 "the OpenAI wire (dsh's actual shape)",对 dsh 原生 lane 并不成立。

修复

  • src/server/side-request.ts:isDshTitleRequest 改为读所有 wire 的 system 载体(顶层 system string / 文本块数组、instructions、systemInstruction.parts、messages[]/input[] 里 role=system|developer),与 estimateWireOverhead 的载体清单一致;no-tools veto 保留。
  • src/util.ts:载体扫描提为共享的 systemCarrierTexts(同样的 40 行此前已存在于 src/server/pi-subagent-channel.ts,所以这次不再往 side-request.ts 里复制第三份)。
  • 调用点不变:src/server/handle.ts:772(sideRequestLike)与 src/server/handle.ts:1659(dshTitleSidecar),仍由 x-bili-plugin: dsh + agent !== "main" 守门。

测试

  • tests/dsh-title-sidecar-handle.test.ts:anthropic wire 的端到端 —— 标题请求(顶层 system、无 tools、budget 4096)先到 → 逐字透传、不占 anchor、stats.requests = 0、无 |sub: 行;随后带 tools 的主回合拿到裸 key、stats.requests = 1。
  • tests/side-lane-truth-table.test.ts:11 行载体真值表(4 种 wire + developer 角色 + 三条闭合反例)。这一处同时满足 lane-guard(dsh 回归防护:泳道判定真值表 + 侧请求不变量 + dsh e2e lane + 运行时金丝雀 + lane-guard(5 项) #2170)"改了 side-lane 逻辑必须带专用 lane 套件"的要求。

影响面

  • 只有 dsh 受影响:两个调用点都在 x-bili-plugin === "dsh" 之后短路,其他客户端 / lane 行为不变。
  • 误判出口只有一个:无 tools 且 system 文本以那句固定标题文案开头。dsh 主回合必带 tools(会话 journal 的每个 request/header 都是 tools=1),isSideRequest 同款 no-tools veto 兜住;反例已入真值表。
  • 不改 config、不改 wire 形状、不改持久化格式。

验证

  • npm run typecheck 干净
  • 4 个 lane 套件 + 2 个 title 套件 + pi-subagent-channel:67 / 67
  • lane-guard 本地按 CI 片段复现 PASS;check-unused-exports / check-test-import-graph / config-surface-guard 通过

Fixes #3149

awork added 2 commits October 14, 2026 16:49
…erTexts (ranxianglei#3153)

Review follow-up on the ranxianglei#3153 fix: the PR hoisted the all-wire system-carrier
scan into src/util.ts so side-request.ts would not carry a third copy, but the
byte-identical private copy in src/server/pi-subagent-channel.ts (ranxianglei#2694) was
left behind. Two identical copies of a carrier list whose doc comments both
claim parity with estimateWireOverhead is a drift trap — point the channel
detector at the shared export instead (logic unchanged, zero behavior delta).
…le (ranxianglei#3153 review)

This PR retires tests/dsh-title-side-lane.test.ts (ranxianglei#2503); two of its pins
had no replacement — the isSideRequest budget-heuristic boundary around the
title body (rc.2 64 caught / alpha.2 4096 missed, the gap the text predicate
exists for) and the non-object guard on isDshTitleRequest. Move them next to
the new carrier table so the ledger does not shrink with the file.
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

Review 进度通报(代码审完,CI 跑完后补结构化八问结论):

代码审核 — 方向成立,根因修对了。

  • 根因属实:isDshTitleRequest(dsh 0.2.1 Alpha.2更新了检查适配情况 #2503)此前只扫 messages[] 里 role=system 的条目,dsh 原生(anthropic)lane 的标题提示词走顶层 system 字段 → 谓词漏判 → 标题请求参与 persona 锚定、抢裸 key / fork 出 |sub:<fp> 幽灵。
  • 修法打在源头:谓词改为读所有 wire 的 system 载体(与 estimateWireOverhead 的载体清单一致,已逐项核对 src/server/budget.ts),no-tools veto 原样保留;两个调用点(src/server/handle.ts:772 / :1659)不变,仍由 x-bili-plugin: dsh + agent ≠ main 守门。非 dsh 客户端零影响。
  • 测试有牙:anthropic wire 端到端(标题先到 → 逐字透传、不占 anchor、stats.requests=0、无 |sub: 行;主回合随后拿裸 key)+ 11 行载体真值表(4 种 wire + developer 角色 + 3 条闭合反例)。lane-guard(dsh 回归防护:泳道判定真值表 + 侧请求不变量 + dsh e2e lane + 运行时金丝雀 + lane-guard(5 项) #2170)要求也满足——改动落在 tests/side-lane-truth-table.test.ts(LANE_SUITE_RE 名单内)。

本地定向验证(全部通过): 8 个相关套件 78/78(dsh-title-sidecar-handle / side-lane-truth-table / dsh-title-side-lane / side-lane-invariants / fork-side-request-lane / side-request-isolation / dsh-persona-fingerprint / pi-subagent-channel)+ typecheck 干净。全量回归以远程 CI 为准。

我在你的分支上加了一个标注小修 commit(6db54b5f8,+2/−48,零行为变化):
PR 把载体扫描提为 src/util.ts 共享版时,src/server/pi-subagent-channel.ts(#2694)里那份逐字节相同的私有副本被留下了——同一份载体清单两份拷贝,doc 注释都声称与 estimateWireOverhead 对齐,是漂移陷阱。该 commit 把 channel 检测指到共享导出,删掉本地副本(typecheck + unused-exports + test-import-graph + 相关套件复验均绿)。如不想要这个 commit 说一声,我可以撤。

小事故披露: 推送过程中我误在主仓建了同名分支并误取消了本 PR 自己的 5 个 CI run(CI 测试矩阵等)——杂分支已删除,5 个 run 已全部 rerun,不影响最终结果。

CI(test 矩阵 + 各 lane)绿后我回八问结论。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

审查完成:可合并。CI 在当前 head 2333a4877 上全绿(41/41 check runs)。

分支现在是 3 个提交(透明起见列一下):

  1. 3104bdb89 作者原始修复(见 PR 描述)。
  2. 6db54b5f8 我审查时的顺手小修:pi-subagent-channel.ts 里还有一份与本次新提取的 util.ts 版逐字节同逻辑的私有 systemCarrierTexts(48 行),改成 import 共享版(+2/−48)。PR 描述说"不再往 side-request.ts 复制第三份",这份第二份顺手也消除了。
  3. 2333a4877 另一个 agent 的审查跟进:给真值表补了 2 个测试钉(isSideRequest 的 ≤200 budget 启发式边界、非 object 入参守卫)。小瑕疵:commit 注释写 "retires tests/dsh-title-side-lane.test.ts",但该文件并未删除,这两个钉与其中已有覆盖是重复添加。功能无影响(测试全过),不值得再触发一轮全量 CI 去改一行注释,故保留原样,仅在此记录。

八问:

  1. 是什么问题:dsh 原生(anthropic)lane 下,会话标题生成请求没被识别为 sidecar——它带着固定标题文案走了顶层 system 字段,而识别谓词只认 messages[] 里的 system 条目。后果:标题请求抢走裸会话 key、真正的主回合被 fork 到 |sub:<fp>(一个会话在 Web UI 显示两行),宿主盖章的 compress/acp_status 还会路由进那个空的幽灵账本。
  2. 什么原因导致的:dsh 0.2.1 Alpha.2更新了检查适配情况 #2503 的谓词只覆盖当时 dsh 实际使用的 OpenAI 形状。dsh 0.2.1-alpha.2 切到原生 anthropic lane 后,system 文本的载体位置从 messages[] 移到顶层 system 字段,谓词返回 false,side 请求于是参与了 persona 锚定。是载体覆盖面的缺口,不是锚定机制本身的错。
  3. 影响范围与严重程度:仅 dsh 0.2.1-alpha.2+ 的 plugin-native 用户(x-bili-plugin: dsh)。严重度:会话账本分裂——主会话落到 |sub:<fp> 且后续管理调用失败,对该场景算功能性损坏;其他客户端、其他 lane、其他 wire 形状不受影响。
  4. 怎么修复的:谓词改为扫描所有 wire 的 system 载体(顶层 system string/文本块数组、instructions、systemInstruction.parts、messages[]/input[] 里 role=system|developer),载体清单与既有的 estimateWireOverhead 对齐(我逐项核对过一致);no-tools veto 原样保留作误判兜底。两个调用点(handle.ts:772、:1659)不变,仍由 x-bili-plugin: dsh + agent !== "main" 双重守门。
  5. 回归问题:无。审过的既有行为逐项:①非 dsh 客户端——两个调用点先按 header 短路,行为不变;②dsh 主回合(带 tools)——no-tools veto 照旧拦下,反例已入真值表;③persona 锚定路径——识别出的 sidecar 走 raw-key 逐字透传(handle.ts:812/832/852/866 四个锚定分支全部以 !sideRequestLike 守门),主回合锚定逻辑未动;④标题生成等侧请求污染主会话状态:prepareAnthropic 缺 isTitleGen 守卫、快照无条件覆盖、survivedCount 每请求空转 #388 逐字透传路径未动;⑤pi-subagent channel——我的去重提交把私有副本换成共享版,逻辑等价性已对照原实现核验,该套件本地 26/26;⑥载体判定语义——旧实现把单条 system 消息的 parts 拼接后 startsWith,新实现逐载体独立 startsWith,唯一差异是"前缀横跨两个 part"不再命中,dsh 标题请求不存在这种形状(前缀在首个 part 开头)。高危模式(语义漂移、吞错、阈值/时序/输出格式变化)逐项过:均不涉及。
  6. 是否破坏缓存:不涉及(不触碰压缩/缓存/重试/增量游标;sidecar 依旧绕过 kernel 状态)。
  7. 是否改了设计方向:没有。纯谓词覆盖面扩展,对齐既有载体清单,架构/边界/数据流未转向。
  8. 是否引入新配置:没有。无新增 config/env/CLI flag/默认值。

验证:

结论:可合并,合并动作留给你。

@ranxianglei
ranxianglei merged commit 5ce3b78 into ranxianglei:master Oct 14, 2026
90 of 93 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.425-master.5ce3b78 (rolling master tag).

npm install -g billion-context@0.0.425-master.5ce3b78  # 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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] dsh 原生(anthropic)的标题请求未被 isDshTitleRequest 识别,同一会话在 Web UI 拆成两行

2 participants