Repository navigation
Description
dsh 长会话漂移综合治理:堵死原生压缩"本地落地"的最后漏窗 + 会话身份分叉可见化与自愈
范围声明:本 issue 全部修复落在 billion-context 仓内,dsh 侧不做任何改动(对方暂无配合能力)。dsh 侧遗留项在末尾单列、只记录不验收。
一、现象(两天内大量报告)
同一批用户报出两类互相纠缠的症状,均集中在 bili v0.1.211/v0.1.212 × dsh desktop 0.2.1-rc.x:
- 身份漂移:一个长会话的流量整体从主会话 id 挪到
<id>|sub:<hash>行;主行只剩 1 条消息,几百条请求全在子行。用户看到的直接后果:压缩状态错乱、acp/compress 工具引用失效、"像新开了一个会话,但开头是段 checkpoint 总结"。- 代表:DSH: If the first request of a session originates from a bypass call, compression for the entire session is permanently | DSH: If the first request of a session originates from a bypass call, compress for the entire session is permanently inv | DSH:会话首个… #5656(DSH 桌面,0.1.212)、[Research][dsh] The dsh session ID drifts as follows: sub-agents/auto-reviews each issue their own new ID, auto-compacti | [研究][dsh] dsh 会话 id 是这样漂移的:子代理/自动评审各发各的新 id,自动压缩落地不换 id,裸中继线上没有任何显式 id #5630(session-id 研究)、Fork adoption fails on multimodal parents, then degrades into a raw-history rebuild that the provider rejects (400 InvalidArgument) — the forked session stays unusable #5595(fork adoption 失败)
- 压缩失效 / 上下文炸窗:原生压缩要么永久失败(熔断),要么整段历史被"换题目"式重写后仍压不下去,最终上游 400(
prompt is too long)卡死。- 代表:[Bug][dsh] Model requests silently bypass the compression proxy (fail-open gate) — 927K-token prompt sent raw, 1-token reply, session bricked with 400 #5613(927K token raw 发送,模型只回 1 token)、dsh blew up due to context overflow. | dsh 上下文溢出炸了 #5653/Repeated compression just won't squeeze it down any further — the model itself says there's no more space. | 重复压缩压不下去 模型自己说没空间了 #5671(长会话溢出)、Bili skips compression in the DSH Remote scenario, with local fix and test attached | Bili 在 DSH Remote 场景下跳过压缩,附本机修复与测试 #5614(Go Remote 组合两字即超窗)、# Cache hit collapses to 1–12% for a whole generation, then the very next request returns to 100% — repeated 15× in one day #5608(缓存 hit 塌缩 1–12%)
打标全集(session漂移):#5571 #5608 #5614 #5630 #5653 #5656 #5671。
为什么新版本更严重,三个放大器叠加:
- dsh-compaction-basic 0.2.0-rc.2 起压缩调用改为重放整个影子区间(~1100+ 条消息),旧的"≤4 条消息"形态判据([dsh] 原生压缩拦截门的 SHAPE 信号(≤4 条消息)在 dsh-compaction-basic 0.2.0-rc.2 上恒假 → 压缩静默落地 → 1510 条 fold 锚点永久失配,连刷 166 条 no-anchor-match 且面板仍报 netSaved 355.9M #2193 修过的洞)之后又出现新的静默放行路径;
- dsh desktop 把内核打进 app bundle,profile 里没有 @deepseek-ai/* 包,而 bili 的 compaction-disable overlay latch 告警目前只对 bundling
dsh-web-app的 profile 发声——desktop 形态下 overlay 没挂住时完全静默; - dsh NEXT 每个 turn 重新盖章 system prompt(harness-state),persona tag 持续变化,把本可自愈的身份判定推入 fork 分支。
二、根因(两条独立机制 + 复合放大)
机制 A:会话身份 resolver 的确定性 fork(src/session-resolve.ts)
resolveSessionOrder(:234)对 tag 变化(tagChanged,:279)走四梯证据判断:①head 前缀+碎片全等(:285–291);②header 佐证模型切换(#2601/#2817,:293–298);③prefix-affinity 持久链(#2815,:301–307);④#4778 连续 ≥8 格同索引内容碎片对齐,且要求 incoming 不短于 recorded(:325–332)。四梯全失 ⇒ fork 到 <rawId>|sub:<fp16(tag)>(:355–358),且该动作在生产路径零日志(适配器 personaConversationOrder :457–459 只返回 key,丢弃 action/reason)。
fork 被触发的高频场景:
- DSH: If the first request of a session originates from a bypass call, compression for the entire session is permanently | DSH: If the first request of a session originates from a bypass call, compress for the entire session is permanently inv | DSH:会话首个… #5656 类:会话首请求是旁路调用(prompt 增强),它先认领了裸 id;主循环带着真实 system tag 到达 ⇒
tagChanged;主循环历史比旁路 blob 长但头是 user 而 recorded 头是 assistant ⇒ 梯①断(头碎片不等);通常无 model 切换(梯②断)、链深度不足(梯③断)、且 [bug][dsh] Goal auto-continuation forks the main conversation into an empty |sub: lane → ~6M-token preflight, session ne | [bug][dsh] Goal auto-continuation forks the main conversation into an empty |sub: lane → ~6M-token preflight, session never replies… #4778 的碎片对齐要求位置一致——主循环内容与旁路 blob 完全异质 ⇒ 梯④也断 ⇒ 确定性单点 fork,稳定收敛到同一个 |sub: 行。 - A∩B 复合(对应"新会话开头是 checkpoint 句"):若该 lane 此前发生过一次原生压缩落地,后续请求携带的是 [checkpoint, …保留尾],比 recorded 短 ⇒ 梯④长度门为假;同时新版 dsh 每轮 system 变化 ⇒
tagChanged成立 ⇒ 同样落入 fork,且 fork lane 的首条可见消息就是 checkpoint 句。这解释了为什么两类报告总是一起出现。
机制 B:原生压缩调用的"本地落地"漏窗(src/agent/native-intercept.ts)
bili 的原则(#3651/#1729):dsh 原生压缩的 summarize 调用必须被拒发——一旦落地,dsh 客户端会用 checkpoint 永久替换原始消息面,摧毁代理的压缩基底,不可逆。已覆盖的拦截面:server 路由门(:2043 路由调用)+ passthrough lane(:463)。未覆盖的:fetch patch 里所有降级为 DIRECT 直发的路径(directSendOrRefuse 的 6 个调用点 :1412/:1508/:1565/:1611/:1648/:1728)——当此刻没有活 proxy(bootstrap 失败/respawn 耗尽/proxy 死亡降级)或宿主未装 takeover gate(如 Go Remote adapter 进程,见 #5614),一次 marker 命中的压缩调用会原样打到上游:上游正常返回摘要 ⇒ dsh 客户端 frameSummary 打包 checkpoint ⇒ 本地写盘落地。billing 全程未见此调用,事后只能以 unannounced-rewrite banner 记账(#5684 已有实例)。现存代码对这种情况的注释自认:"a dead proxy — keeps #1117's direct semantics"(native-intercept.ts:1583–1593 一带),即明知会落地、故意放行。
三、方案(本 PR,四项,全在 bili 仓)
| # | 文件 | 改动 | 治什么 |
|---|---|---|---|
| P0-1 | src/agent/native-intercept.ts | directSendOrRefuse 单一 choke point 加判据:POST + 模型形态 URL + 可解码 body 含 48 字节 marker 嗅探 + 全文档 decisive 校验(末条 user 消息以 COMPACTION_INSTRUCTION 前缀开头,复用 server 侧 isDshCompactionCall)+ 此时无活 proxy ⇒ 本地 422 拒绝(x-bili-gate: dsh-compaction-refused,bili.log 落 error 行)。dsh 会按 "step compaction failed … continuing the turn" 继续本 turn,无副作用。marker 仅在正文提及(非末条 user 打头)绝不误伤;流式/不可读 body fail-open 维持现状并写明原因。 |
机制 B 全部 W 路径(死 proxy 降级、respawn 耗尽、无 gate 宿主)一次闭环 |
| P0-2 | src/agent/dsh-native.ts | compaction-disable overlay latch 检测(detectCompactionOverlayGap,纯结构检查)移出 web-app 专属分支,所有 profile 形态latch 失败都在启动时报 ARMED 警报(持久 log 行);latch 成功维持现有 info note。 |
desktop app-in-bundle 形态的静默武装盲区(#5684 clients=dsh desktop profiles) |
| P1-1 | src/session-resolve.ts + src/server/handle.ts | personaConversationOrder 适配器加可选回调,handle.ts 6 处调用点接入:derived-* / reanchor 动作落持久 [session-resolve] log 行(warn/info,含 old→new key 与 reason)。claim/continue 静默防 spam。 |
所有"会话突然多了一行 |
| P1-2 | src/session-resolve.ts | tagChanged 分支加第 5 梯(incoming 更短 + tailAligns(TAIL_WINDOW=8) + fragTailEquals 全等 ⇒ reanchor,不 fork)。与既有 tagless shorter-reanchor 分支(:406–408)严格同判据对称——8 格 sha256 尾部逐字节对齐在两个不同会话之间概率≈0。 | A∩B 复合场景(checkpoint 落地 + system 换新)不再确定性 fork |
设计依据沿用既定教义:MESSAGE-IDENTITY(只认字节级碎片等价,不做模糊相似);"要么一定压缩,或者一定拒绝"(#1884 owner 裁决,原文见 native-intercept.ts:1515 注释区)——原生压缩调用属于"落地即破坏"类别,没有第三个合法出口。
四、已知残留(本 PR 不解决,仅登记)
- 跨进程 patch 缺失:Bili skips compression in the DSH Remote scenario, with local fix and test attached | Bili 在 DSH Remote 场景下跳过压缩,附本机修复与测试 #5614 的 Go Remote 场景里 remote adapter 进程本身不装 fetch patch,P0-1 在那个进程里不存在。缓解:proxy 端 unannounced-rewrite 记账 + P1-1 日志让此类事件可定位;根治需要 dsh 让 remote 路径复用带 patch 的 fetch 链(dsh 侧,不配合则长期残留)。
- 流式 request body:fetch API 下无法窥探 ReadableStream body,fail-open 维持([omp-native] fetch recovery that lands on the same healthy origin is treated as give-up: BILLION_CONTEXT_PROXY is deleted for the whole process #2496 原则:body 必须保持可发)。dsh 现用字符串 JSON body,不受影响。
- dsh 工具 refs-stale(DSH: If the first request of a session originates from a bypass call, compression for the entire session is permanently | DSH: If the first request of a session originates from a bypass call, compress for the entire session is permanently inv | DSH:会话首个… #5656 的后半段):checkpoint 落地后 compress/acp_status 按裸 id 解析 ref 全 stale——属 dsh 客户端行为,需 dsh 用 conversations 映射跟随 live lane;P0-1 落地后此类事件本身大幅减少。
- # Cache hit collapses to 1–12% for a whole generation, then the very next request returns to 100% — repeated 15× in one day #5608 缓存 hit 塌缩:根因疑似身份漂移导致的 prefix 断裂,随 P1-1/P1-2 观察验证,单独跟进。
五、复现与验证
本地已搭最小复现床(mock OpenAI endpoint + dsh headless profile,32K 小窗口强制触发压力压缩):
- A(现状证明):裸 dsh(无 bili)中量多轮累积到阈值 ⇒ compaction/start→summary→end 全序列落地,checkpoint 作为 user/message 写入 session.v4.jsonl,正文开头即 "This is an automatically generated checkpoint condensing an earlier span…"。
- B(拦截闭环):同 profile 走 bili 车道(v0.1.212 独立实例)⇒ 三次压缩调用全部 422 拒发,session 零 compaction/summary 事件,dsh 照常完成主请求。证明常规车道闭环完好,dsh session automatically drifted to a new session. This is an automatically generated checkpoint condensing … | dsh会话自动漂移到 新会话 This is an automatically generated checkpoint condensing … #5517 类泄漏必来自机制 B 的漏窗路径。
- 回归:本 PR 新增 node:test(P0-1 choke point 五例:P0-2 非 web 形态警报;P1-1 回调日志;P1-2 第四腿 + 现有三梯不变),并入 CI 全套。
关联:#5517 #5630 #5656 #5613 #5684 #5614 #5653 #5671 #5608 #5571 #2193 #2360 #1729 #3354 #2474 #2709 #4778
Activity
[-]dsh 长会话漂移综合治理:堵死原生压缩本地落地的最后漏窗 + 会话身份分叉可见化与自愈[/-][+]dsh Long-Session Drift Comprehensive Remediation: Sealing the Last Leak Window for Native Compression Local Deployment + | dsh 长会话漂移综合治理:堵死原生压缩本地落地的最后漏窗 + 会话身份分叉可见化与自愈[/+]ranxianglei commentedon Nov 4, 2026
(ai: vllm-qwen/qwen3.8-27b)
查重:不重复。 本单是综合修复伞单,四个修复点(P0-1 native-intercept 咽喉点拒发 / P0-2 overlay latch 全形态告警 / P1-1 分叉日志可见化 / P1-2 tagChanged 第五梯)在 open+closed issue 与近期 PR 中均无对应实现。相邻条目已逐一核对无重叠:#5604(修 #5595 fork adoption 空 tool-call)、#5605(修 #5596 被拒 compaction 的 replay 输出预算)、#5592(sidecar stub ref-holding lane)、#5632(dsh session id 漂移形态研究,只读分析)——都不触碰本单的四条代码路径;#5656/#5630/#5613/#5614/#5653/#5671/#5608/#5571/#5517 是症状追踪单,保持打开,由本单收口机制面。
标签:bug / dsh / scope/wiring / p1(缺陷;dsh 车道;改动全部落在请求管道与身份解析接线层;p1——原生压缩落盘会不可逆销毁压缩基底、身份分叉让长会话压缩状态错乱直至 prompt-too-long 卡死,属核心承诺失灵)。
开工计划(一个 PR,Closes #5686):
directSendOrRefuse咽喉点加判定——POST + model 形 URL + 可解码正文 48B marker sniff +isDshCompactionCall全文决定性校验 + 此刻无活代理 ⇒ 本地 422(x-bili-gate: dsh-compaction-refused,复用服务端dshCompactionRefusal协议形 body,bili.log 记 error 行)。流式/不可读正文 fail-open 并写明理由。detectCompactionOverlayGap移出 web-app-only 分支,所有 profile 形态启动时 latch 失败都打持久 ARMED 告警行。personaConversationOrder加可选回调,handle.ts 六处调用点接入;derived-*/reanchor动作打[session-resolve]持久日志(含 old→new key + 原因),claim/continue 保持静默。配套新增 node:test(P0-1 咽喉点五例、P0-2 非 web 形态告警、P1-1 回调日志、P1-2 第四腿+既有三梯回归),本地定向验证后推 CI。已知残留(Go Remote 跨进程、流式正文 fail-open、dsh refs-stale、#5608 观察项)按 issue 要求只登记不修。
ranxianglei commentedon Nov 4, 2026
(ai: vllm-qwen/qwen3.8-27b)
四部分全部实现完毕,PR 已开:**#5691 #5686,分支
2026-11-05_dsh-drift-remediation,已 rebase 到当前 master c9ba485)。标签: bug · dsh · scope/wiring · p1(首条回复已打,理由:p1——核心承诺失灵类,原生压缩落地即永久破坏折叠基底 / 会话静默分叉成幽灵车道)。
查重: 不重复(首条回复已述:#5686 即总纲,症状单 #5656/#5630/#5595/#5613/#5614/#5653/#5671/#5608/#5571/#5517 保留为跟踪项,无在途 PR 覆盖这四部分)。
结构化八问
>=,而「落地压缩截断头部 + 宿主每轮重打 system」恰好产生更短的历史,被排除在所有阶梯之外,必走分叉兜底;且personaConversationOrder适配器只回传 key、丢弃 action/reason,分叉在日志里不可见。B 的根因是直发降级路径沿用了 「BUG」native-intercept 进程级 globalThis.fetch 补丁按 URL 形状接管所有模型流量,无关调用者(如 MemOS)被卷入宿主压缩流程 #1117「代理死了就走直连」语义,对绝不允许落地的压缩调用没有单独裁决(旧注释自认 "a dead proxy — keeps 「BUG」native-intercept 进程级 globalThis.fetch 补丁按 URL 形状接管所有模型流量,无关调用者(如 MemOS)被卷入宿主压缩流程 #1117's direct semantics")。directSendOrRefuse加裁决(POST + 模型形 URL + 48 字节 marker 嗅探 + 全文决定性校验[最后一条 user 消息以指令前缀开头,复用服务端isDshCompactionCall]+ 调用方传入的 noLiveProxy 标志 ⇒ 本地 422,x-bili-gate: dsh-compaction-refused,bili_final);流式/表单/不可解析体保持 fail-open 并逐路径写明理由。P0-2 把detectCompactionOverlayGap纯结构探测从 web-app 专属分支扩到所有 profile 形态,挂不上即在启动时打 ARMED 告警(含 gap token 与 fix(dsh): profile 层 patch 其实可以关掉 web profile 的原生自动压缩(#1772 结论修正)+ 一个会静默清空整个 preset 的写法坑 #2474 处置配方),挂得上保持原被动 trace。P1-1 适配器加可选onResolve回调,handle.ts 六个 persona 调用点接线:derived-*分叉打 warn、reanchor打 info,均带旧→新 key 与原因;claim/continue 保持静默防刷屏。P1-2 tagChanged 分支新增第五条再锚定阶梯,与既有 tagless 短历史再锚定阶梯严格对称(严格更短 + tailAligns(8) + fragTailEquals 尾格逐字相等 ⇒ 锚迁移回 raw id),八格 sha256 尾对齐跨不同会话概率≈0。验证状态:typecheck 干净;定向套件在 rebase 后头部全绿(native-intercept、dsh-native、dsh-compaction-guard、issue3354、persona lineage/fork/continuity/fingerprint 等 219/219,含新文件
tests/issue5686-dsh-long-session-drift.test.ts14 例);全量判定以 CI 为准,CI 红了先看 #4599。已知残留(issue 内登记、不在本 PR):跨进程补丁缺失(Go Remote,#5614)、流式请求体 fail-open(dsh 现用字符串 JSON)、落地后 dsh tool refs-stale(#5656 后半)、#5608 缓存命中观察待 P1-1/P1-2 上线后看数据。收工判定:开发完成,等 review + CI 绿灯,合并权在你。
ranxianglei commentedon Nov 4, 2026
综合治理已提交:PR #5692 — P0-1 直发choke点本地拒发(422)+P0-2 overlay告警全形态泛化+P1-1 fork可见化日志+P1-2 tagChanged短尾reanchor自愈腿。tsc干净,新增/改写测试全绿(dsh-native.test.ts的部分环境红已在stash基线验证非本PR引入,CI终裁)。
fix: alarm on compaction-disable overlay gap for unintrospectable dsh…
ranxianglei commentedon Nov 4, 2026
🔶 需要决策
(ai: vllm-qwen/qwen3.8-27b)
背景一句话: 同一 scope(#5686 四部分治理)出现了两个并行 PR——我先开的 #5691(17:34Z),你转发的这条评论指向的 #5692(18:16Z,晚 42 分钟,同 base c9ba485)。两者我逐文件对比过了。
待决问题: 保留哪个、关闭哪个(关闭权在你,我不关任何 PR)。
已做的处置(不等决策):
duplicate标签 + 留了逐部分对比评论(duplicate of [PR] fix: dsh long-session drift comprehensive remediation (#5686) #5691);c37bc7289推上 [PR] fix: dsh long-session drift comprehensive remediation (#5686) #5691 分支(带回归钉,typecheck+定向套件本地绿,CI 重跑中),[PR] fix: dsh long-session drift comprehensive remediation (#5686) #5691 描述加了吸收说明。吸收后 [PR] Plug the last gap in silent deployment of dsh native compression + session fork visibility/self-healing (#5686) | 堵住 dsh 原生压缩静默落地的最后漏窗 + 会话分叉可见化/自愈 (#5686) #5692 不再携带任何独有内容。逐部分对比:
dshCompactionRefusal(含bili_final,与 #2490 终局拒绝契约一致)state.origin === undefined(未来新增直发点自动覆盖,不用逐点接线);自造拒绝体,缺bili_final;且recover()在无 respawn hook 的宿主上不清 origin,该窄类宿主的发送失败降级路径会漏拒test车道 skipped,无全套判定选项与代价:
推荐:A。 不决定的默认行为:两个 PR 都保持 open,无破坏性后果;你合并时只能合一个,另一个自然作废。
fix: refuse decisive dsh compaction on the signed built-in passthroug…
Merge pull request #5692 from ranxianglei/ranxianglei/2026-11-05_dsh-…
ranxianglei#5686 P0-1/P0-2/P1-1/P1-2: dsh drift consolidation — close…
Merge upstream/master (0aace2f): adopt ranxianglei#5683 unprompted-co…
#5719: sessionid+msgid last-resort identity rung — re-anchor instead …
fix: correct stale rung ordinal — #5686 shorter-tail rung is the sixt…
merge: resolve origin/master into PR #4883 (keepCommandCompact)
fix: reanchor tag-changed shorter replays whose logical tail survived…
fix: correct stale rung ordinal — #5686 shorter-tail rung is the sixt…