Skip to content

[PR] pi-native: re-assert the active tool loadout after a /tree rewind (compress etc. no longer silently die) | pi-native: /tree rewind 后重断言活动工具 loadout(compress 等工具不再静默失效) - #3545

Merged
ranxianglei merged 1 commit into
masterfrom
2026-10-17_pi-tree-rewind-loadout-reassert
Oct 20, 2026

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #3542

问题

pi-native 模式下用 pi 内置 /tree 回退(典型流程:回退到首条用户消息 + 换模型 + 重发)后,bili 的 ACP 工具(compress/decompress/acp_status…)变成「已注册但未激活」:定义仍在 pi 的 registry 里,但离开了活动 loadout(pi 声明给模型、且 dispatcher 按名检查的那一套)。此后模型每次调用都被 pi 拒 Tool compress not found,整场会话无法恢复,两侧都无日志。

机制(pi-coding-agent 1.3.0 逐行核对,行号与 issue 一致):

修法

在 session_tree 事件上重断言 loadout——该事件恰在重置之后、下一次 _startRun 之前触发:

  • 只增不减(additive-only):宿主当前持有的名字一律不动,只补回缺失的 bili 工具;与 pi 自身 reload() 无条件重新激活全部 extension tools 的先例一致;
  • 成功时打一条 warn 进 bili.log(本 bug 的另一半是两侧静默),点名缺失的工具;
  • 宿主没有 getActiveTools/setActiveTools 面(老 pi / omp)或查询抛错(stale ctx)→ no-op,绝不盲目 set(与 reassertDroppedTools 同一纪律)。已核对 0.83.0 与 1.3.0 两个版本都具备该 API 面。

边界说明:根因在 pi core(_restoreToolsFromTranscript 把会话级仍为真的工具声明当历史状态丢弃),真实修复属于上游;本 PR 只做 in-scope 补偿,不向上游提 issue(owner 决定)。

行为变更披露

  • 新增:pi 宿主每次 /tree(及同类 tree 导航)后,若 bili 工具不在活动 loadout 中会被重新激活,并多一行 [native-client] … dropped from the active loadout … — re-asserting (#3542) warn 日志。未回退的会话、无该 API 面的宿主行为完全不变。
  • 无配置变更、无 wire/payload 变更(tool-call arguments 路径未触碰)。

验证

pi's navigateTree() resets the ACTIVE tool loadout to what the surviving
transcript system entries declare (_restoreToolsFromTranscript), discarding
the entry that declared the bili tools whenever it sits after the rewind
target (the normal case - the manifest handshake is async). The definitions
stay in the registry, so #2708's registry probe sees nothing missing, but pi
dispatches on the loadout: every later compress/decompress/acp_status call
fails with "Tool X not found" until restart, silently on both sides.

Re-assert the loadout on the session_tree event, which fires right after the
reset and before the next _startRun: additive-only (names the host currently
holds are never removed), logged, and a no-op on hosts without the
getActiveTools/setActiveTools surface (older pi / omp).

Root cause stays in pi core (_restoreToolsFromTranscript dropping a still-true
declaration); this is the in-scope bili-side compensation.

Fixes #3542
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-17_pi-tree-rewind-loadout-reassert (7550425)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.4191-pr.3545.91490cd

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-pr3545.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title pi-native: /tree rewind 后重断言活动工具 loadout(compress 等工具不再静默失效) pi-native: re-assert the active tool loadout after a /tree rewind (compress etc. no longer silently die) | pi-native: /tree rewind 后重断言活动工具 loadout(compress 等工具不再静默失效) Oct 17, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重: 不重复。 最近邻是已关闭的 #2708(Tool compress not found)——同症状家族但机制不同:#2708 是 registry 定义丢失(探测面 getAllTools()),本项是活动 loadout 丢失(定义仍在、只是不再声明给模型),#2708 的修复 fec8b15 对这一类结构性失明。open+closed 检索无其他 loadout/tree-rewind 签名匹配项。根因侧已由 owner 在上游 earendil-works/pi#11075 跟踪。#3545 是 #3542 的唯一 PR,满足 loop guard。

独立审核结论(以下机制均本人对 pi 源码/tarball 重新核对,未复用 issue 文本):

方向(①):修复层次正确——根因在 pi core _restoreToolsFromTranscript 把会话级仍为真的工具声明当历史状态丢弃,真实修复属上游(已报);bili 侧补偿点选在 session_tree 事件,该事件恰在重置之后、下一次 _startRun 之前触发。已对下载的 1.3.0 tarball 逐行验证:navigateTree() @dist/core/agent-session.js:3232 → _restoreToolsFromTranscript() @:3376 → 紧随其后 emit session_tree,事件在 navigateTree 内部、任何后续 run 之前发出。additive-only 与 pi 自身 reload() 无条件重新激活全部 extension tools 的先例一致。

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

  • 插件初始化路径:新增一个 session_tree handler,事件未触发前惰性;无 API 面的宿主 no-op(测试钉住)→ 保持;
  • ExtensionAPI 结构类型新增两个可选字段:超集,不影响其他调用点(CI typecheck 绿)→ 保持;
  • pi-native: tools register once per session id, so a pi tool-registry rebuild silently removes compress/decompress/... for the rest of the session #2708 registry 自愈路径:reassertDroppedTools 及其两个调用点(:709/:776)与日志行均未动 → 保持;
  • FakePi 测试夹具:改动限于本测试文件,套件绿 → 保持;
  • wire/payload/tool-call arguments:未触碰 → 保持;
  • config/persistence/kernel:未触碰 → 保持。
    唯一有意变更(PR 正文已披露):每次 tree 导航后若 bili 工具不在 loadout 则重新激活 + 一条点名缺失工具的 warn 日志。无回归。

代码(③):新函数 reassertLoadoutAfterTree 与 reassertDroppedTools 纪律逐条对齐——可选面守卫、查询 try/catch(stale ctx → no-op)、绝不盲目 set、.call(pi) 调用;additive-only [...active, ...missing];去重语义与 pi 自身 _setActiveTools([...new Set(...)] @dist:2923)一致;日志在 set 成功后打(只在真实补回时),点名数量+工具名+issue 编号,治住「两侧静默」的另一半;快速路径零副作用。API 面独立核验:devDep 钉死版 0.83.0(types.d.ts :866/:933/:937)与报告版 1.3.0(:1282/:1291/:1199)均具备 getActiveTools/setActiveTools/session_tree 三面。

测试有效性(④):5 个新测试都有牙——(1)恢复+日志内容断言(XDG_STATE_HOME 隔离 bili.log,断言 warn 点名 compress)(2)additive-only 保宿主名字序 bash,read,compress,acp_status快速路径零 setter/re-register 调用(4)无 API 宿主 no-op(5)查询抛错 no-op。Fake host 忠实建模 pi(loadout 与 registry 分离、Set 去重)。任一 facet 回归都会让至少一个测试失败。一个覆盖缺口已审:registeredTools 空守卫无专门测试——核代码确认该守卫是冗余防御(即使删掉,missing 亦为空而提前返回,行为零差异),判定不值得补测。

Diff 整洁度(⑤):2 文件 +167/-0,每行与目的相关,无无关变更;commit message 含机制+边界说明+Fixes #3542。

CI:独立核对 head 7550425 的全部 42 个 check run——全 success/skipped(skips 均为条件式 real-client e2e 门),零失败。

热文件备注:src/agent/pi.ts 同时被 open PR #3556/#3529/#3440 触碰;对当前 master merge-tree 干净(base 之后 master 侧对该文件的唯一变更是 #3516 P1-3 guardrail 接线,与本 PR 区域不相交)。BEHIND 状态不阻挡合并;若上述 PR 先行落地,合并前 rebase 一次即可。


结构化八问:

  1. 是什么问题:pi-native 模式下用 /tree 回退后,bili 的 ACP 工具(compress/decompress/acp_status…)仍在 registry 注册却离开活动 loadout,模型此后每次调用都被 pi 拒 Tool compress not found,整场会话无法恢复,两侧都无日志。
  2. 什么原因导致的:pi core navigateTree() 末尾调 _restoreToolsFromTranscript(),把 loadout 重置为存活 system entries 声明的并集;bili 的 manifest 握手是异步的,其工具声明 entry 落在回退目标之后被丢弃;此后无人再激活(_startRun 清 pending,registry 重建只在 reload 或名字全新时发生);pi-native: tools register once per session id, so a pi tool-registry rebuild silently removes compress/decompress/... for the rest of the session #2708 的自愈探测的是 registry,定义还在 → 结构性看不见这一类。
  3. 影响范围与严重程度:pi-native(pi plugin lane)用户中,凡 /tree 回退越过 bili 工具声明点的(典型:回退到首条用户消息+换模型+重发)完全无法使用压缩工具直至重启;其他 lane、未回退会话、无该 API 面的宿主持续不受影响。
  4. 怎么修复的:在 session_tree 事件上重断言 loadout(additive-only:只补回缺失的 bili 工具,宿主持有的名字一律不动);成功时打 warn 点名缺失工具;宿主无 API 面或查询抛错 → no-op,绝不盲目 set(与 pi-native: tools register once per session id, so a pi tool-registry rebuild silently removes compress/decompress/... for the rest of the session #2708 同一纪律)。根因留在上游(/tree deactivates registered tools that the rewound branch never declared; reload() re-activates them earendil-works/pi#11075),本 PR 只做 in-scope 补偿。
  5. 是否有回归问题:diff 触碰的既有行为(初始化路径、结构类型、pi-native: tools register once per session id, so a pi tool-registry rebuild silently removes compress/decompress/... for the rest of the session #2708 路径、测试夹具、wire、config、persistence)逐项审过全部保持;唯一有意变更即披露的「tree 导航后重新激活 + 一条 warn 日志」。无回归。
  6. 是否破坏缓存:不涉及——缓存/重试/增量游标/去重键策略均不受影响(仅工具注册面,未碰 payload)。
  7. 是否改了设计方向:不涉及——架构/边界/数据流不变,纯补偿逻辑挂在既有插件生命周期上。
  8. 是否引入了新的配置:无——无新 env/config/CLI;仅新增一条 warn 日志行。

判定:满足 §7.4 auto-merge gate 全部条件(单模块 fix:、有回归测试、CI 在 pushed head 上绿、clean diff、Fixes #3542、未触承重设施),可交人工合并。

另:按标题国际化惯例已将 PR 标题改为英文前缀形式 pi-native: re-assert the active tool loadout after a /tree rewind (compress etc. no longer silently die) | <原中文标题>(正文未动)。

@ranxianglei ranxianglei changed the title pi-native: re-assert the active tool loadout after a /tree rewind (compress etc. no longer silently die) | pi-native: /tree rewind 后重断言活动工具 loadout(compress 等工具不再静默失效) [PR] pi-native: re-assert the active tool loadout after a /tree rewind (compress etc. no longer silently die) | pi-native: /tree rewind 后重断言活动工具 loadout(compress 等工具不再静默失效) Oct 17, 2026
@ranxianglei
ranxianglei merged commit 391b802 into master Oct 20, 2026
42 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.648-master.391b802 (rolling master tag).

npm install -g billion-context@0.0.648-master.391b802  # 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

1 participant