Skip to content

fix: scope chain tag-detection to history; exempt cooperative plugins (#1197) - #1215

Closed
ranxianglei wants to merge 1 commit into
masterfrom
2026-09-24_fix-chain-fallback-false-positive
Closed

ranxianglei wants to merge 1 commit into
masterfrom
2026-09-24_fix-chain-fallback-false-positive

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Sep 23, 2026 •

Copy link
Copy Markdown
Owner

#1417 全批次深审定案:关闭——已被 #1213(0a1b068)取代(superseded)。

本 PR(chain 检测范围收窄)所属的检测路线已被 #1213 的 historyTextOf 修法落地;其后的链语义演进(advisory 降级 #1364 → chain checkpoint #1397/#1395)继续在活 PR 上推进。评论说明存档于 #1417 追踪板。

…#1197)

The #1086 content fallback scanned the whole request body for render tags, so a client-authored system/instructions block quoting a tag example (this repo's own AGENTS.md does; pi injects it) read as a bili->bili chain and a fresh session was passed through forever - compression silently off, /acp armed-idle. Scope the tag family to HISTORY message content (system/developer/instructions are client-authored, never bili products) and exempt cooperative plugin (x-bili-plugin) requests from the content fallback (plugin mode re-sends its own compress calls/results by design; real chains stay guarded by x-bili-hop).
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-24_fix-chain-fallback-false-positive (38e4201)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-1215

Each push to this PR publishes a new version under the pr-1215 npm tag.

Option B — Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 PR #1215 review(本 PR 带 ework-agent-pr 标记,按规矩核对代码 + CI,不重做)。结论:代码本身可以合并,但发现一个必须先处理的重复问题——#1213 是同一修复的并行实现,两条不能都合。

⚠️ 最重要的发现:与 #1213 重复

PR #1213(fix: chain content-fallback false positives — tags scoped to history, plugin-announced exemption (#1197))创建于 09-23 18:15Z,比本 PR 早 42 分钟,同样 Fixes #1197、同样的两层方案、改同样的三个文件,且 CI 同样全绿、base 同为当前 master。逐项对比:

#1213 #1215(本 PR)
server.ts 插件豁免 pluginAgentHeader(req.headers) !== undefined,语义相同 pluginAgent !== undefined(决策点即 per-request 头),语义相同
tags 族限定 history 可解析对象只扫 history;仅不可解析时整包回退 识别到容器扫 history;无容器的可解析 body 也保留整包回退(更保守,未知形状下保留旧检测网)
测试 既有 T1–T9 + detector + T10/T11 等价物 + T12(+198 行) 既有 T1–T9 + detector + T10/T11(+136 行)
CI / base 全绿 / 当前 master ✓ 全绿 / 当前 master ✓

关键差异在测试:既有 incidentBody()(T3 用的)不含字面 render tag,只 pin 了 tool-history 族的 server 级透传;而本修复重新限定的恰恰是 tags 族。#1213 的第二个 commit(review 驱动)补了 T12:foreign 客户端 history 携带真 render tag → byte-identical 透传 + 一次 warn + 不留状态,把被重限定的那一族钉死在 server 层;#1215 只在 detector 层断言了同场景(detectAcpArtifacts(inAssistant) === "tags"),server 决策线没有 family-specific 的端到端钉子(决策代码本身 family-agnostic,风险低,但覆盖确实薄一档)。

我的建议(明确,不是选择题):合并 #1213,关闭 #1215。 #1213 测试覆盖严格超集,其余功能等价;若 owner 更看重 #1215「未知形状保留旧检测网」的保守语义,那就先把 T12 移植进 #1215 再合它、关 #1213。关闭动作请 owner 拍板,我不代关。两条都别先合——同一代码区域,后合的那条会语义冲突。

#1215 本身的审查记录

① 原 issue 方向:#1197 floor 6 的根因链成立——ACP_TAG_RE.test(body.toString()) 整包扫描 + pi 把含字面 <acp …> 示例的 AGENTS.md 注入 system prompt = 新会话被永久误判 bili→bili 链。修复打在检测范围与协议豁免两个根因点上,不是遮症状。✓

② 回归清点(触碰路径的既有行为逐项判定):

  • detectAcpArtifacts 生产调用点唯一(src/server.ts:1494),artifactSeedHit 未动(仍整包预筛,hit 只多付一次 decode,语义保持);
  • history 内真 tag(assistant/tool-result)仍判 artifacts ✓(detector 测试钉住);system/developer/instructions/systemInstruction 不再计为证据 = 有意变更(PR 描述已披露 old→new);不可解析 body 整包回退不变 ✓(既有测试 line 91 钉住);tool-history 族零改动 ✓;
  • 非插件 + artifacts + 无本地状态 → 透传路径不变(T3 byte-identical 保持);x-bili-hop 守卫在 line 1115,先于内容回退决策,真链不受豁免影响 ✓;插件 + artifacts + 无本地状态 → 由透传变处理 = 有意变更,残留风险(hop 头被剥的插件双链)已在 PR 描述披露;
  • debug 日志分叉仅措辞;两种压缩模式均已推演(§6):插件模式是把 self-produced 待遇扩展到无本地状态的插件请求,与 Key Design Decision feat: bili CLI + debug in config + README rewrite #7 一致;proxy 模式只有 scoping 变化。

③ 代码:historyTagContainer 对四种 wire 形状正确(messages/input/contents 取容器,顶层 Anthropic system/Responses instructions/Gemini systemInstruction 按构造排除);role 过滤只剔容器内 system/developer 项;JSON.stringify 重编码后 ACP_TAG_RE(同时容忍转义/未转义引号)依然有效;决策点 pluginAgent 取自 per-request 头(line 1371,早于 line 1682 的 sticky 绑定),语义正确。

④ 测试有效性:T10/T11 断言有牙(修复前必挂:透传 ⇒ sha 相等 + 无 session + warn 触发三选二即挂);detector 测试四 wire 全覆盖含负例。缺口即上面说的 tags 族 server 级缺 T12。

⑤ diff 整洁度:3 文件、每行都与本 PR 目的相关,无空行/锁文件/生成物噪音。干净。

验证证据(rebased head 上实跑)

  • CI 全绿:test ubuntu 22/24、windows 22/24、codex zero-token preflight、version-guard、build-artifact —— 同时佐证「claude-native 3 失败是本机游离进程所致」(干净 runner 上通过);
  • 本地(pr-1215 == 当前 master base,0 commits behind):npm run typecheck 干净;node --import tsx --test tests/issue1086-chain-self-exemption.test.ts 16/16 pass。

顺带发现(不阻塞,两个 PR 都有此问题)

CONFIGURATION.md:567 与 CONFIGURATION.zh-CN.md:565 的 BILI_CHAIN_CONTENT 行没跟上本次行为变化:「carries compression artifacts ⇒ passed through verbatim」对插件流量已不准确(豁免),也没提 tags 只计 history。一行级 zh/en 同步小修;等 owner 定下留哪条 PR 后我直接在幸存分支上补 commit。

交付物核对

follow-up 均已按来源标记立项:#1217(pi -p 首请求缺 x-bili-plugin* 头,钩子注册竞态)、#1218(chain 判定透传时会话 /acp 仍显示 armed-idle)——正文均以 来源: ranxianglei/billion-context#1197 … 开头,合规 ✓。另注:#1217 已有对应修复 PR #1216。

按 §7.4,wire 行为变更类不在 auto-merge 范围,合并照例由人执行。

中文摘要:本 PR 修复了 #1086 链检测误伤(文档里的 tag 示例被当成压缩产物导致新会话被永久透传、压缩静默失效),代码与测试审查通过、CI 全绿、本地 16/16 验证过;但发现早 42 分钟的并行实现 #1213 与之重复且测试覆盖更完整(多一个钉住 tags 族透传的 T12),建议合并 #1213、关闭本 PR,请 owner 拍板。

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.

1 participant