Skip to content

fix: reject byte-identical display-stub re-submission as compress summary (#2749) - #2754

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-11_pi-compress-stub-replay
Oct 15, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-11_pi-compress-stub-replay

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #2749

是什么问题

pi native/plugin 通道下,compress 调用参数中出现 ~200 字符、在语句/路径中间以省略号截断的"摘要",并被 minSummaryLength(50) 放行、折叠掉约 8 万 token。本 PR 定位了成因并加了一道 host 侧护栏。

归属判定(issue 验收项):JSONL 里的短片段是模型发出的,不是 bili/pi 改写了工具参数——pi 扩展经 forwardTool HTTP POST 把模型原始参数原样交给代理(src/agent/pi.ts:536),代理 handlePluginTool → executeProxyToolAsync → applyRanges → core.applyCompression 全程不改写摘要正文(仅 scrubLoneSurrogates)。促成因素是宿主信息丢失面:plugin 模式下历史 compress 调用的完整摘要被 hide-consumed.ts stub 成 200 字符(SUMMARY_STUB_CHARS=200),且 stripKernelSummaries(#1316)在 plugin 模式剥离全文 acp_summary 锚点——stub 成为模型对已折叠内容的唯一持久记忆。当后续 tier 蒸馏 / refold / 相邻折叠时模型只能看到 stub,就会把它当完整摘要再次提交;自 refold 变体还会用 stub 覆盖既有块的 canonical 摘要(静默缩小)。

怎么修复的

applyRanges(src/stream.ts)入口新增前置检查:从内核自己的出站重写结果(真实调用 hideConsumedCompressCalls(state, messages))收割当前对模型可见的 compress-call stub 集合,若本次提交的任一 range.summary 与其中某条逐字节相同,整次调用拒收(refused, reason stub-resubmission),回执指明命中的范围并给出恢复路径(decompress 源块 / search_context 后重新摘要),接入既有 #847 重复失败记录与 #2146 熔断计数。

行为变更(旧值→新值 + 原因)

场景 旧行为 新行为
提交的摘要与当前可见 display stub 逐字节相同 接受为新块摘要(大段历史折叠进截断片段) 拒收 + 指明恢复路径;不产生新块

这是有意的收紧:旧行为正是 #2749 报告的缺陷本身。其余所有提交路径(含 ±1 字符漂移副本)行为不变。

Config surface

无新增 env / config 字段 / CLI flag / 默认值。护栏无条件生效,无开关(与既有 applyRanges 各拒绝分支一致)。

边界与已知限制(如实披露)

  1. 内核侧等价实现未做:相同检查放在 kernel(acp-kernel)可额外覆盖 standalone billion-context-pi 等不经过 bili host 的消费方,但 Kernel Boundary rule 1 要求 owner 先批准再动 kernel/**。已在 issue 中提请 owner 决定是否立项;本 PR 先解决 bili 全通道(pi native / omp / opencode-native 等)。
  2. preflight 自摘要 lane 未覆盖:该 lane 的摘要是 bili 自己的 summarizer 生成的,不存在"复制可见 stub"的信息来源,风险≈0,故不加检查。
  3. ±N 字符漂移副本不拦:精确匹配契约的代价,换取零误伤;issue 明确禁止凭长度/省略号误拒。
  4. proxy 模式不受影响(ephemeral 调用不进客户端历史、acp_summary 锚点保留,[Bug] ACP: ≥2 compressed blocks render as multiple system messages → SGLang (vLLM-compatible) upstreams return 400 #377)。

Pre-flight

  • npm run typecheck:clean
  • node --import tsx --test tests/stub-resubmission-guard.test.ts:5/5 pass(canonical 完整性 pin、拒收、自 refold 拦截、合法摘要放行、harvest tripwire)
  • 定向相邻套件(stream.ts/applyRanges 触碰面 15 个文件):135/135 pass
  • 全量回归交由 CI

涉及文件:src/stream.ts(+68/-1)、tests/stub-resubmission-guard.test.ts(new, 257 行)。diff 每行均与本 PR 目的相关;未触碰 version / kernel/** / pi-subagents/**。

@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-11_pi-compress-stub-replay (aa90f3a)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3825-pr.2754.80089d1

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

Option B — Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei
ranxianglei force-pushed the 2026-10-11_pi-compress-stub-replay branch from 2baa14a to bdd7457 Compare October 11, 2026 08:00
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 PR #2754 review 结论:代码正确、设计合理、diff 干净。发现原分支落后 master 10 commit(其中 #2669 动了 applyCompression 所在内核模块),已按 §7.2 rebase 到 live master(干净无冲突),fresh CI 正在对含 #2669 的 master 复验。判定:可合并(待 rebased head 单测矩阵绿灯),合并留给 owner。

独立核验(非仅读 PR 描述)

  • 逐行读 diff:src/stream.ts +68/-1、tests/stub-resubmission-guard.test.ts(新,257 行)。
  • 核对全部符号作用域:ranges/trackLoop/recordCompressFailure/noteCompressLoopFailure/compressResult/COMPRESS_TOOL_NAME/parseCompressInput 在插入点均可达;插入点在 normalizeRangeOrder 之后、applyCompression 之前——位置正确。
  • 验证护栏核心假设:内核 stub = clampPrefix(summary,199)+"…"(kernel/src/hide-consumed.ts:113-117),而 clampPrefix(kernel/src/truncate.ts:16)至多回退一个 surrogate pair ⇒ stub 恒为 199 或 200 字符且以 U+2026 结尾。故 host 收割 band (len==199||200) && endsWith("…") 无假阴性——内核产出的每条 stub 必被收割;测试 5 将此契约钉死为 tripwire。
  • 归属链:pi execute 把模型原始 params 原样交 forwardTool(src/agent/pi.ts:554),代理 applyRanges→core.applyCompression 全程不改写摘要正文(scrubLoneSurrogates 仅用于 head/tail 预览,不进 canonical;compress-tool 解析路径不碰摘要文本)。bili 唯一的 200 字符截断是出站展示路径(hide-consumed),不回灌存储 ⇒ 存储里出现截断片段只能来自模型复制可见 stub 再提交。归属成立。
  • 双模式推理(§6):proxy 模式客户端历史不含 ephemeral compress tool-call ⇒ 收割集为空 ⇒ 护栏天然 plugin-mode-only,不误伤 proxy。

回归审查(②,逐项既有行为)

结构化八问

  1. 是什么问题:plugin 通道下模型对已折叠块的唯一持久记忆是约 200 字符展示 stub(全文锚点被 stripKernelSummaries 剥离,feat: pin acp-kernel 0.0.90 + wire refold-in-place into proxy decompress #1316);tier 蒸馏/refold 时把它当完整摘要再提交,minSummaryLength(50) 放行后大段历史被折叠进截断片段(自 refold 变体还会静默缩小既有块 canonical 摘要)。
  2. 什么原因导致的:宿主信息丢失面——hide-consumed 将保留可见的调用参数 stub 成 200 字符 + plugin 模式剥离全文锚点,叠加使 stub 成为唯一记录;「再次提交」这一步缺护栏。(非 bili 改写参数,见上归属链。)
  3. 影响范围与严重程度:所有 plugin 通道(pi native/omp/opencode-native)二次摘要场景可触发;canonical 存储不损坏(decompress/search 可恢复原文),坏在喂给模型的摘要永久降级直到重摘——属「特定条件下有问题」,非全面数据丢失。proxy 模式不受影响。
  4. 怎么修复的:applyRanges 入口前置检查——从内核自己的出站重写结果收割当前可见 stub 集合(非镜像常量,格式漂移不致护栏静默失效),提交的任一 range.summary 与其中某条逐字节相同则整次拒收(reason stub-resubmission),回执指明命中 m-ref 范围并给恢复路径(先 decompress/search_context 再重新摘要),接入 出现持续压缩失败,无法自动恢复 #847/dsh内部问题 出现这个错误后,重启dsh可以发消息 但陷入无限压缩失败 #2146。
  5. 是否有回归问题:无。仅新增一个前置分支,未改任何既有行为;正常短摘要/含省略号正文/±1 字符漂移副本一律放行(测试 4 钉死,遵守 issue「不得凭长度或省略号误拒」约束)。诚实披露一个理论边界:一条恰好 199/200 字符且以省略号结尾的合法短摘要是 stub 候选——但需模型再逐字节原样提交才触发,窗口极窄且该行为本身亦属退化,可接受。
  6. 是否破坏缓存:不涉及。不改消息重建/系统消息字节,拒绝路径不产生新块,不影响 prefix cache。
  7. 是否改了设计方向:不变,host 侧护栏,不动 kernel/**。提请 owner 决策:内核侧等价实现可额外覆盖 standalone billion-context-pi 等不经 bili host 的消费方,但 Kernel Boundary rule 1 要求先批准再动 kernel——是否立项由你定(同一机制域,未另开 issue)。已知边界如实披露:①±N 字符转录漂移副本按精确匹配契约不拦(换零误伤);②preflight 自摘要 lane 未覆盖(bili 自生成摘要,无可见 stub 信息来源,风险≈0)。
  8. 是否引入新配置:无。护栏无条件生效,与既有 applyRanges 各拒绝分支一致,无 env/config/flag/默认值。

行为变更披露(旧→新)

场景 旧 新
提交摘要与当前可见 display stub 逐字节相同 接受为新块摘要(大段历史折叠进截断片段/自 refold 静默缩小) 拒收 + 指明恢复路径,不产生新块

有意收紧,旧行为正是 #2749 报告的缺陷本身;其余所有提交路径(含 ±1 漂移副本)行为不变。

Rebase / CI

小修

无需顺手修项——diff 每行均与本 PR 目的相关,注释措辞与代码事实一致。

判定:可合并(待 rebased head 单测矩阵绿灯),合并操作留给 owner。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 CI 全绿,最终门禁通过(接续上一条 review):

  • rebased head bdd7457a1(基于 live master cccf47dce)27/27 check-runs 全部 success——含完整单测矩阵(ubuntu/windows × node 22/24,覆盖新增 tests/stub-resubmission-guard.test.ts),以及对本 PR 依赖的 kernel: selector screens live carriers; withdrawal judged on original array class (#2663) #2669 内核变更(kernel/src/compress.ts/state.ts)的复验。旧 head 的绿不覆盖这批内核改动,故以本次 rebased head 为准。
  • PR 状态已从 rebase 前的 mergeable_state: behind 转为 clean;diff 仍为 2 文件 +324/-1,未触碰 version / kernel/** / pi-subagents/**。
  • review 结论维持不变:可合并,合并操作留给 owner。

#2754

@ranxianglei
ranxianglei force-pushed the 2026-10-11_pi-compress-stub-replay branch from bdd7457 to 7e67dd5 Compare October 15, 2026 14:31
@ranxianglei
ranxianglei merged commit 1336fc7 into master Oct 15, 2026
24 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.460-master.1336fc7 (rolling master tag).

npm install -g billion-context@0.0.460-master.1336fc7  # 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.

[严重]t2压缩被截断为200字

1 participant