Repository navigation
Description
Description *
Description
#1835 用来拒绝 dsh 原生压缩调用的双信号 AND 里,SHAPE 信号被钉死为「整请求 ≤ 4 条消息」(依据 #1727 观测的 2 msgs @ ~152K tokens)。DSH 0.2.0-rc.2 的 @deepseek-ai/dsh-compaction-basic 为了让摘要调用成为「上一次请求的真前缀」(复用上游 KV cache),把被遮蔽区间整段重放为消息前缀再追加压缩指令 —— 摘要调用实测 1121 条消息,于是 MARKER 真、SHAPE 假、AND 失败、门静默放行。
后果正是 #1835 正文自己论证的「不可逆」那一幕:checkpoint 落地,shadowedSeqs 永久遮蔽原始历史,bili 的 fold 覆盖一次性失去 1510 条内容哈希 ref,此后 6 小时里每一轮请求都刷同一条 [fold-reconcile] ... no anchor match(共 166 条),而同一会话在 /__bili/sessions 上仍报 netSaved 355,926,292。bili 侧全程零日志(grep -in compaction bili.log = 0 命中),用户不可能知道压缩基底已经没了。
bili version
0.1.184(运行中;磁盘已装 0.1.185,GET /__bili/status 报 stale:true、autoRestartOnUpdate:false)
Usage mode
plugin / native —— dsh-native(exports["."] = ./dist/agent/dsh-native.js),lane dsh,管理端点 http://127.0.0.1:18787。
Client and version
@deepseek-ai/dsh0.2.0-rc.2@deepseek-ai/dsh-compaction-basic0.2.0-rc.2- Node v22.22.2
Operating system
Debian GNU/Linux 12 (bookworm)(Linux,与 #2187 的 Windows 场景无关)
Upstream and model
本地 OpenAI 兼容网关:forward POST → http://<private-host>:12808/v1/chat/completions,provider:"sub"、model:"deepseek-v4.1-flash"、reasoningEffort:"high"、maxTokens:200000,会话 request/context 报 contextWindow:1000000(运行中一度改报 934464)。
Compression-related config
~/.config/billion-context/billion-context.json 全文:
{"providers": {}}即 allowDshCompaction 缺失 = 默认 OFF = 拦截门应当激活。无 dsh.* 键、无 env BILI_ALLOW_DSH_COMPACTION、web 配置未勾选任何开关;日志里也没有 [dsh-compaction] dsh native compaction ALLOWED via web config —— 门不是被人为打开的,是自己失效了。
根因
1. bili 侧:门的 SHAPE 条件(dist/index.js)
var DSH_COMPACTION_INSTRUCTION_PREFIX = "You are now acting as a compaction engine for this AI coding assistant";
var DSH_COMPACTION_MAX_MESSAGES = 4;
function isDshCompactionCall(protocol, parsed, messageCount) {
if (protocol !== "openai" && protocol !== "anthropic") return false;
if (messageCount === null || messageCount > DSH_COMPACTION_MAX_MESSAGES) return false; // ← 死在这里
const finalUser = lastUserMessageText(protocol, parsed);
if (finalUser === void 0) return false;
return finalUser.trimStart().startsWith(DSH_COMPACTION_INSTRUCTION_PREFIX);
}messageCount 即入站 body 的消息数:inboundMsgs = parsed.messages.length(或 parsed.input.length)。
门控点(src/server/dsh-compaction-guard.ts 的编译产物):
if (protocol !== null && opts.allowDshCompaction !== true && isDshCompactionCall(protocol, parsed, inboundMsgs)) { … 403 REFUSED … }MARKER 侧是好的:DSH 0.2.0-rc.2 的指令首句一字未改。SHAPE 侧是坏的:> 4 直接 return false,后面的 MARKER 根本不评估。
2. DSH 侧:摘要调用为什么不再是「2 条消息」
dsh-compaction-basic/lib/index.js 注释原文:
The summarization directive, delivered as the FINAL user message after the replayed conversation rather than as a distinct summarizer system prompt. Keeping the conversation's own system prompt, tools, and message prefix in front of it makes the auxiliary call a genuine prefix of the last routed request, so the provider's KV cache is reused instead of invalidated.
function buildSummarizationInput(session, shadowedSeqs) {
const header = session.requestHeader();
const head = systemHead(session, session.surface.nodes[0]);
const system = head === void 0 ? null : session.deriveEventMessage(head);
const regionMessages = shadowedSeqs
.map((seq) => session.deriveEventMessage(session.eventAt(seq)))
.filter((message) => message !== null);
return {
...(header?.tools === void 0 ? {} : { tools: header.tools }),
messages: system === null ? regionMessages : [system, ...regionMessages],
};
}即 messageCount = (system?1:0) + shadowedSeqs.length + 1,shadowedSeqs.length 就是被压缩掉的整段历史(本机这次 ≈1121)。≤4 在结构上不可能成立。
这不是「模板被改写」,而是宿主把一条版本相关的行为契约换掉了:#1835 的 SHAPE 是照 dsh ≤0.2.0-rc.1 的观测钉死的,rc.2 起摘要调用改为「真前缀重放 + 指令收尾」。原话 Both must agree; a reworded template degrades to today's behavior —— 今天是模板没改、形状改了,而 AND 的失效方向恰好是「静默放行」。
3. 门确实跑了、确实放行了
grep -in 'compaction' bili.log → 0 命中:既无 dsh native compaction call identified … — REFUSED,也无 ALLOWED via web config。
被放行的那次请求就在日志里,形态与「整段历史重放」吻合:
09:33:38.685 request: 1326 msgs, inbound=3.4MiB, outbound=503.4KiB ← 压缩前最后一次正常请求
09:33:44.683 (DSH) compaction/start compactionId=fbbadc2c-… turn=4
09:33:44.867 [warn] [fold-reconcile] resent history drifted: 175 covered id(s) missing with no anchor match — originals re-enter the wire unfolded (#1921)
09:33:44.888 request: 1121 msgs, inbound=2.8MiB, outbound=294.8KiB ← 摘要调用(门在这里放行)
09:34:17.093 [plugin] [acp-usage] input=87567 cached=3072 (cache hit 4%) ← 该调用的用量
09:34:17.125 (DSH) compaction/summary (61,523 字符, 以 "## Primary Request and Intent" 开头)
09:34:17.129 (DSH) compaction/end
09:34:17.239 [warn] [fold-reconcile] resent history drifted: 1511 covered id(s) missing with no anchor match
09:34:17.248 processTurn: 129 msgs ← 压缩后的新表面
量纲交叉验证:正常请求 1326 msgs → 3.4 MiB;该请求 1121 msgs → 2.8 MiB,线性折算 3.4 × 1121/1326 = 2.87 ≈ 2.8 MiB。而 bili 把 2.8 MiB 折成 294.8 KiB(≈87K tok),与 09:34:17.093 的 input=87567 吻合,进一步说明该 1121-msg 请求的响应就是摘要本身。
对照实验(同一会话文件):另有 19 条 compaction/prune,全部 time=1791192440275(= 09:27:20.275Z),形如 {"shadowedRange":{"start":N,"end":N},"shadowedSeqs":[N],"shadowedTokenCount":T}(T 从 2228 到 12491)—— 精确对应 bili 09:27:20.568Z 唯一一次成功重锚 reanchored 17 (17 by toolCallId, 0 by normalized identity)。机械剪枝(prune)可被重锚救回;摘要压缩(summary)不能 —— 这就是判据必须拦在摘要调用上的理由。
影响
- 不可逆的基底摧毁:
compaction/end之后原始消息再也不会进入任何一次请求,1510 条 ref 永远处于「账本说 covered、实际不在线上」。 - 观测完全失效:唯一的声音是同一句 warn 重复 166 次(09:34:17.239 → 15:33:24.393,175 → 1511 → 恒定 1510),没有一次升级为 error,也没有一次点名「宿主原生压缩落地」。
- 账本反向虚高:同会话仍报
netSaved 355,926,292 / grossSaved 357,501,178 / foldCount 44 / cacheHitPct 97,而真实覆盖已崩 —— 与 Session death spiral: fold drift → 0 compressible ranges → over-window fail-fast (window flip + missing max_tokens headroom as compounding factors) #1908 的死亡螺旋是同一枚硬币的两面(那次是 outbound≈raw 却报 0 compressible,这次是覆盖没了却照记节省)。 - 代价不对称被误判:放行一次的代价是永久的;拒绝一次只是 dsh 三条路径之一(压力自动压缩 / 溢出恢复 / 手动
/compact)失败一次并回落到 bili 自己的压缩。默认值应偏向拒绝。 - 同类风险外溢:
isDshCompactionCall/DSH_COMPACTION_INSTRUCTION_PREFIX/dshCompactionRefused只出现在dist/index.js(2 处),所有dist/agent/*-native.js里 0 处 —— 这套防护只有 dsh 有,而它刚刚被证明是按版本观测钉死的。
建议修法
P0 — 去掉/泛化 SHAPE,把判定建立在语义不变量上。 messageCount ≤ 4 是宿主的实现细节,不是压缩调用的定义:
- (a)
finalUser.trim() === COMPACTION_INSTRUCTION(全等于版本化模板,而非startsWith前缀)→ 几乎不可能误伤。 - (b) 前缀延拓判据:若最后一条 user 消息以
COMPACTION_INSTRUCTION开头,且它之前的 N 条消息与「本会话上一次已路由请求」的某个前缀逐字节相同,则判为摘要调用。DSH 的注释已把这条不变量说清("a genuine prefix of the last routed request"),且不随消息条数漂移。
P0 — 形状不匹配时不要静默放行。 保留 MARKER 的独立评估;MARKER 命中而 SHAPE 未命中时,至少打一条一次性日志:
[warn] [dsh-compaction] COMPACTION_INSTRUCTION is the final user message but the shape signal no longer matches (N=1121 msgs > 4) — a host-native compaction may be about to land and durably shadow the raw history (#1729). Refusing on first sight; set allowDshCompaction:true to opt in.
并建议在每会话首次直接按 #1835 路径拒绝(理由见影响 4,且 DSH 对拒绝有回落)。
P1 — 让「基底已毁」成为一等事件。 `fold-rec
bili version *
0.1.184
Usage mode *
Plugin native (bili plugin install …, runs inside the host process)
Client and version *
@deepseek-ai/dsh0.2.0-rc.2 -@deepseek-ai/dsh-compaction-basic0.2.0-rc.2 - Node v22.22.2
Operating system *
Debian GNU/Linux 12
Upstream and model *
model:"deepseek-v4.1-flash"、reasoningEffort:"high"、1m workbubby
Compression-related config (optional)
Log excerpt (strongly recommended)
/acp or acp_status output (optional)
Activity
ranxianglei commentedon Oct 5, 2026
[bot] 🏷 Triage 完成,根因已代码级确认,开工。
根因:
isDshCompactionCall(src/server/dsh-compaction-guard.ts)是两信号 AND——MARKER(末条 user 消息以指令首句开头)∧ SHAPE(总消息数 ≤4)。SHAPE 钉死在 rc.1 时代的流量观察(#1727:2 条 @ ~152K),失败方向是「停止拦截」。rc.2 把 summarize 调用改成把整个 shadowed region 作为消息前缀重放(你的日志:1121 条 / 2.8MiB)→ SHAPE 恒假 → 整个门静默放行、零告警。与你的日志时间线完全吻合:09:33:44.888 的 1121 条请求正是从门缝穿过的——若被拦下,此刻应有一条[dsh-compaction] ... REFUSEDwarn。修法方向:
产出:一个 PR 引用本 issue(Closes #2193)。netSaved 面板虚增(impact #3)属 cache-ledger 记账机制,我会评估是否纳入本 PR;不纳则按来源标记另立 issue。
ranxianglei commentedon Oct 5, 2026
[bot] 🏷 完成:PR #2201 已开(Closes #2193),待人工 review。
结构化七问:
范围外发现(已另立 issue):impact #3(netSaved 虚增)属 cache-ledger 记账完整性的另一机制域——
src/web/sessions-data.ts:470-477纯从 per-fold ledger 条目聚合、与覆盖状态零耦合,已带来源标记立项 #2202。impact #5(agent 侧缺口)查证为非问题:所有模型流量都经 proxy HTTP server,guard 覆盖两种压缩模式。本地验证:定向套件(guard / #2028 toggle / reconcile / fold-drift / config relocation)全绿 + typecheck + build;全量回归交 CI。不满足 auto-merge 条件(默认拦截行为变更 + 日志面变更),需人工合并:#2201
fix(#2193): reset fold-drift episode state on early exits
Merge pull request #2201 from ranxianglei/2026-10-05_dsh-compaction-g…
fix(ranxianglei#2193): marker-decisive dsh compaction guard + fold-dr…
fix: fold-reconcile drift alert false-positive under owner-deletion (#…
fix(#2360): dsh compaction gate on responses wire + coherent compress…
fix(#2360): dsh compaction gate on responses wire + coherent compress…
fix: rebase ACP state when codex's local auto-compaction replaces the…
fix(#2709): attribute framing-absent dsh native compaction via refusa…
test(#2709): pin refusal-ledger attribution wiring at the #2193 destr…
fix(#2709): attribute framing-absent dsh native compaction via refusa…
test(#2709): pin refusal-ledger attribution wiring at the #2193 destr…
4 remaining items
lane-decisions: migrate the four B-class name-gate bypasses + single …
lane-decisions: migrate the four B-class name-gate bypasses + single …
fix(reconcile): latch the epoch-confirm pause only when covered ids s…
fix: retire persistently-unmatched fold coverage after 3 evidence-les…
fix: classify the dsh request-image handle as a one-shot carrier (ran…
fix: classify the dsh request-image handle as a one-shot carrier (ran…
fix: retire persistently-unmatched fold coverage after 3 evidence-les…
fix: retire persistently-unmatched fold coverage after 3 evidence-les…
fix: retire persistently-unmatched fold coverage after 3 evidence-les…
dsh purpose: stop guessing which requests are auxiliary — the plugin …
fix: retire persistently-unmatched fold coverage after 3 evidence-les…
fix: exempt the dsh plugin lane and compaction calls from the 32 MiB …
fix: retire persistently-unmatched fold coverage after 3 evidence-les…
fix: retire persistently-unmatched fold coverage after 3 evidence-les…
fix: retire persistently-unmatched fold coverage after 3 evidence-les…