Skip to content

[PR] fix: retrieval-only calls must not claim plugin ownership; return exported original inline (#2780) - #2793

Closed
ranxianglei wants to merge 1 commit into
masterfrom
2026-10-11_ccr-retrieval-ownership-export
Closed

ranxianglei wants to merge 1 commit into
masterfrom
2026-10-11_ccr-retrieval-ownership-export

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Problem

In remote proxy mode, two defects in how /__bili/plugin/tool handles acp_retrieve:

  1. Retrieval claimed full plugin ownership. A native retrieval-only adapter calling the endpoint triggered the evidence-based plugin-mode flip (pluginAgent="mcp"), suppressing the proxy's own compression tooling even though the adapter registered only the retrieve tool. Retrieval alone is not evidence of owning the compression tools.
  2. Large exported originals were undeliverable remotely. They were delivered as a pointer to a global <stateDir>/retrieve/<ref>.txt. Identical refs across sessions collide on that path (last writer wins → cross-conversation corruption), and a remote caller cannot read that local path at all.

Fix

  • Part 1 (src/plugin.ts): skip the plugin-mode flip when the executed tool is the CCR retrieve tool. Every other successful tool still flips, so the #760b evidence-based binding is fully preserved.
  • Part 2 (src/store.ts, src/proxy-tool-result.ts, src/plugin.ts): snapshot the exact original under the session lock and return it as an additive retrievalExport: { path, text } response field. The framed pointer text (body.result) and tool arguments are unchanged. The inline snapshot is captured independently of the shared export-file write, so it survives both a failed write and a cross-session ref collision.

Behavior changes (old → new)

Area Old New Why
Plugin ownership after acp_retrieve on an unbound wire-mode session flipped to pluginAgent="mcp" → next request stops injecting the ephemeral compression tools no flip → proxy keeps injecting its own compression tooling retrieval ≠ owning the compression tools; header-bound (full-plugin) sessions were already guarded and are unchanged
Large exported retrieve response result = pointer only; original reachable only via the local file (collides across sessions, unreadable remotely) same pointer plus additive retrievalExport.text carrying the exact original bytes each remote caller receives its own exact original regardless of the shared ref/file

Non-retrieval tools, header-bound (full-plugin) sessions, the model wire, and the framed tool-result text are all unchanged.

Config surface

None. No new config field, env var, or CLI flag. retrievalExport is a response payload field, not configuration.

Scope note (issue's host-integration question)

This PR is the backend fix only, exactly as the issue requested: it does not adopt any local native-tool registration bridge, Windows SSH helper, or transport/authentication contract. Those remain a separate maintainer decision.

Tests

New tests/issue2780-retrieval-ownership.test.ts (real proxy, anthropic wire mode):

  • retrieval-only call does not claim ownership and the proxy keeps injecting compress;
  • control: a non-retrieval tool (acp_status) still flips to plugin mode (#760b intact);
  • concurrent retrieves of the same ref number from two sessions holding different originals — each caller receives its own exact original via retrievalExport.

Verified against original source: tests 1 and 3 fail without the fix and pass with it. npm run typecheck clean; existing ccr-plugin + issue760-percall-conversation suites (which exercise the changed functions) green locally. Full regression runs in CI.

Closes #2780

…orted original inline (#2780)

A native retrieval-only adapter calling /__bili/plugin/tool triggered the
evidence-based plugin-mode flip (pluginAgent="mcp"), suppressing the proxy's
own compression tooling even though it registered only acp_retrieve. Retrieval
alone is not evidence of owning the compression tools, so skip the flip for the
retrieve tool only; every other successful tool still flips (#760b preserved).

Large exported originals were delivered as a pointer to a GLOBAL
<stateDir>/retrieve/<ref>.txt that identical refs across sessions collide on
(and a remote caller cannot read at all). Snapshot the exact original under the
session lock and return it as an additive retrievalExport response field; the
framed pointer text is unchanged.

Closes #2780
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-11_ccr-retrieval-ownership-export (5543b7e)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3067-pr.2793.44c1f7c

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-pr2793.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 #2793 review 完成。已拉取分支(5543b7e)逐文件核对代码、本地定向验证、确认 CI。结论:可合并(按 §7.4 触及 session-binding 逻辑,不可 auto-merge,需人工合并)。

审核过程(证据)

  • diff 共 4 文件 283+/6-:src/plugin.ts(flip 条件 + 响应字段)、src/proxy-tool-result.ts(retrievalExport? 类型)、src/store.ts(快照捕获)、新增测试 258 行。无跑题文件、无空行/重排噪音,diff 干净。
  • flip 点 src/plugin.ts:1781:新条件 typeof session.metadata.pluginAgent !== "string" && tool !== retrieveToolName(session)。首半句保留 → header-bound(全插件)会话不受影响;retrieveToolName(session) 与入口门禁 isProxyToolFor 用同一命名空间(含 session-stamped ccr.toolName 覆盖),比较一致。其余工具(compress/decompress/search_context/acp_status/acp_cache/absorb/rules)全部照旧 flip,#760b 证据绑定完整保留。
  • 快照正确性:kernel applyRetrieve 的 export.text 即精确原文字节(kernel/src/ccr.ts,export: { path, text: found.text },未改 kernel);捕获发生在 withSessionLock 内(executeProxyToolAsync 全程持锁),且独立于共享导出文件写入——写失败路径也挂 failed.retrievalExport。
  • 模型 wire 无泄漏:wire-mode 模型侧调用 retrieve 的路径(src/stream.ts:72)同样走 executeRetrieve,但消费方只序列化 .text 进 tool_result 块,retrievalExport 只出现在 /__bili/plugin/tool 管理端点响应里(additive,沿用 Plugin tool endpoint reports ok:true when the kernel refuses a fold range #1875 模式)。两种压缩模式均安全。
  • 测试有效性:真 server rig(listen(0) 定端口)、真端点、断言有牙——①retrieve 后 pluginAgent ≠ "mcp" 且第二轮 wire 仍注入 compress;②对照组 acp_status 仍 flip;③两会话同 ref 号并发 retrieve,assert.equal(expA.text, BIG_A) 字节级相等 + 指针文本完整(acp-retrieved #ref)且不内联原文。我实测了「无修复必挂」:在 base 70d651cc3 上跑新测试,1、3 挂 / 2 过;PR head 上全过。回归测试有真实牙齿。
  • 本地定向验证:typecheck 干净;issue2780-retrieval-ownership + ccr-plugin + issue760-percall-conversation 三套 23/23 通过(全量交给 CI)。
  • CI:head 5543b7e 上 15/15 全绿(ubuntu/windows × node22/24 测试矩阵 + kernel-guard + config-surface-guard + docs-sync + lane-guard + build-artifact 等)。
  • master 漂移核查:PR base 之后 master 前进两个 merge(fix(#2592): sniff the unattributed raw-URL branch for the dsh compaction envelope #2763 raw-url-compaction-sniff → native-intercept.ts/dsh-compaction-guard.ts;fix(storage): close the SQLite handle when UnifiedStore.open fails on a corrupt index (#2771 follow-up) #2788 corrupt-open-handle → src/storage/store.ts,注意不是本 PR 的 src/store.ts)+ 存储测试——与本 PR 四文件零重叠,GitHub mergeable=True,无需 rebase。
  • 高危域逐项:自动更新/自更新路径未触碰;dsh 相关未触碰;lockfile 未动(kernel-guard/pi-subagents-guard/version-guard 全绿);kernel/ 未改(只消费既有 API);无 config surface(config-surface-guard 绿,PR 正文亦声明 none)。

结构化八问

  1. 是什么问题:远程代理模式下 acp_retrieve 的两个缺陷——retrieval-only 原生调用被误判为「宿主拥有全部 bili 压缩工具」而翻转到 plugin mode,压制代理自身的压缩工具注入;大原文导出只能靠全局本地文件指针送达,跨会话同 ref 号碰撞(后写者胜)且远程调用方根本读不到该路径。
  2. 什么原因导致的:(a) #760b 的证据式 flip 把「任意 MCP 工具成功执行」当作宿主拥有全套压缩工具的证明,但只注册/只调用 retrieve 不构成该证据;(b) CCR 大导出的投递依赖 ref 寻址的全局文件 <stateDir>/retrieve/<ref>.txt,而 ref 号是每 store 的顺序号,不同会话的同序号映射到同一物理文件。两条都是机制层根因,修复打在判定点和数据源,不是症状层过滤。
  3. 影响范围与严重程度:使用原生 retrieval-only 适配器对接远程(非 loopback)代理的用户面。旧行为下:这类会话被静默剥夺代理压缩工具(能力降级,会话仍可用);跨会话 ref 碰撞时调用方 A 可能读到会话 B 折叠内容(特定条件下的数据完整性风险:需两会话在同序号位都存了超阈值大结果且都走大导出 retrieve)。非全面故障,属特定条件功能缺陷 + 潜在跨会话内容串读。
  4. 怎么修复的:Part 1 在唯一 flip 判定处把 retrieve 工具排除出所有权证据(单条件改动,其余工具照旧);Part 2 在会话锁内快照 kernel 给出的精确原文,作为 additive retrievalExport:{path,text} 字段回传管理端点响应——与共享文件写入解耦,写失败和跨会话碰撞两种情形下调用方都拿到自己会话的精确原文。framed 指针文本、工具参数、模型 wire 全部不变。
  5. 是否回归问题:未发现。逐项清点既有行为:#760b 其余工具 flip(对照测试钉住 + issue760 套件绿)、header-bound 会话(首半句守卫未动)、小结果 retrieve(export undefined → 无新字段,行为同旧)、miss/幻觉 ref(提前返回,未触碰)、禁用工具 note 路径(执行前返回,未触碰)、导出文件写入语义(同一 writeRetrievalExport,0600/幂等重写不变)、模型出站字节(管理端点 additive 字段,不进模型 wire)。一个有意为之的语义窗口需知晓:若全插件宿主的首次调用恰好是 retrieve,会话将保持 unbound 直到下一次非 retrieve 调用——期间 ephemeral 工具仍注入(与首次调用前的状态完全相同,属冗余而非错误,PR 行为表已披露)。
  6. 是否破坏缓存:否。前缀缓存/重试/去重策略均未触碰;模型出站字节不变,additive 字段只在管理端点 JSON 响应中。
  7. 是否改了设计方向:否。严格按 issue 范围只做后端修复,明确不引入本地 native-tool 注册桥、Windows SSH helper、传输/认证契约(留作 maintainer 单独决策)。
  8. 是否引入新配置:否。retrievalExport 是响应 payload 字段,非配置项;无新 env/flag/config key。

遗留观察(不拦合并,同机制族):全局导出文件的跨会话碰撞本身仍在——远程投递已被内联快照覆盖,但本地 wire-mode 模型顺着 framed 指针读文件时,理论上仍可能读到碰撞后另一会话的字节。彻底修需要改指针路径/格式(模型可见契约变化),超出 #2780 既定范围;建议作为 #2780 的检查表项跟踪,由 owner 决定是否立项后续,不单开 issue(同一失败域)。

判定:可合并。 代码、测试牙齿(fail-on-base/pass-on-head 实测)、CI 15/15、diff 整洁性、master 漂移零重叠均已核实。因触及 session-binding 逻辑,按本仓规则需 owner 手动合并:#2793

@ranxianglei

Copy link
Copy Markdown
Owner Author

(ai: zhipuai-lb/glm-5.3)

陈旧票清理(第三批动作①):目标 issue #2780 已关。为避免重复劳动关闭本 PR;如判断有误请直接 reopen 并留言。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

清理判定核实为正确,不 reopen。 本 PR 与原始报告者自己的 PR #2801 同症状、同机制、同根因,#2801 先合入,本 PR 判重关闭成立。证据链如下(均已对当前 master ba5ab0bce 逐项验证):

1. #2780 的关闭不是陈旧清理,是修复合入的正常关闭。 API 事件:state_reason=completed,closed_at=2026-10-12T15:57:12Z——比报告者 mariopasquali 的 PR #2801 合入时刻(merged_at=2026-10-12T15:57:10Z)仅晚 2 秒,即「Closes #2780」触发的自动关闭。#2780 floor 4 也明确写了「Proposed fix … in draft PR #2801」。

2. #2801(commit cf54214c4 "Preserve proxy ownership and atomic native retrieval exports")已覆盖本 PR 的两个缺陷:

  • 缺陷 1(retrieval-only 误判所有权):master src/plugin.ts flip 点已带 tool !== retrieveToolName(session) 守卫——与本 PR 的条件逐字相同,#760b 其余工具照旧 flip 的语义保留;
  • 缺陷 2(跨会话 ref 碰撞 + 远程不可达):handlePluginTool 在会话锁内对本会话自己的 content store 重跑 applyRetrieve,把精确原文作为 additive body.retrievalExport 回传(gate:nativeCaller===true + receipt 文本精确匹配)。每个调用方拿到的都是自己会话的原文,与共享全局导出文件 <stateDir>/retrieve/<ref>.txt 是否被同 ref 覆写无关——效果与本 PR 的内联快照等价,机制不同(锁内重跑 vs executeRetrieve 内附带);
  • 回归钉:master tests/ccr-plugin.test.ts 新增两个测试——"native retrieval bridge preserves proxy compression ownership"(对应缺陷 1)与 "native retrieval exports preserve each session's original when refs collide"(对应缺陷 2 的并发同 ref 碰撞场景)。

标签:duplicate(与 #2801 同一失败域:CCR retrieve 的所有权证据判定 + 大原文投递路径;先来后到,#2801 已合入保留,本 PR 关闭正确)。

一个残留观察(信息性,不构成 reopen 理由):master 实现只在 nativeCaller===true 且 receipt 文本完全匹配时挂 retrievalExport;因此导出文件写入失败的降级路径(executeRetrieve 返回 FAILED+head preview)不会附带内联快照——本 PR 的实现当时连写失败也附带。触发条件极窄(stateDir 写失败 ∧ 远程 native 调用方 ∧ 超阈值大结果),且模型侧仍拿到 head preview,定级 p3 边缘。此设计已经合并并被 owner 验收(#2780 completed),此处留档供知悉,不单独立项。

收工判定:无需任何动作,维持关闭。 感谢清理批次;若后续发现 master 上两处行为有回归,再按常规流程走。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Retrieval-only native tool calls claim full plugin ownership and need session-bound original export snapshots

1 participant