Skip to content

[PR] fix: pi /tree recovery respects deliberately-off bili tools — pi-loadout selections survive navigation - #4996

Open
ranxianglei wants to merge 7 commits into
masterfrom
2026-10-27_pi-tree-recovery-respect-off-tools
Open

ranxianglei wants to merge 7 commits into
masterfrom
2026-10-27_pi-tree-recovery-respect-off-tools

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #4988

What

The #3542 session_tree re-assert treated every registered-but-inactive bili tool as rewind-dropped and re-activated it. An external loadout manager (pi-loadout) or a manual toggle may keep a registered tool deliberately off; when pi-loadout's own session_tree handler ran before bili's, the off selection was resurrected on every tree navigation — order-dependent, exactly the repro in the issue.

Fix

Recovery is now judged against the pre-navigation loadout:

Consequence: the deliberate off survives in both handler orders — if pi-loadout restores its selection first, bili sees it standing and makes no setter call; if bili runs first, it re-adds only previously-active tools and pi-loadout's later re-application still stands.

Behavior change (intended)

Tests (tests/plugin-agent.test.ts, +4, all green locally, full suite on CI)

  1. deliberately-off tool is NOT resurrected; the previously-active one is (negative gate);
  2. the off survives in both handler orders (pi-loadout-first → zero setter calls; bili-first → recovers only actives);
  3. previously-active tools lost on rewind are still fully recovered (sampled path);
  4. navigation before late manifest registration is a no-op; recovery works once registered.

All five pre-existing #3542 cases stay green (they fire session_tree without session_before_tree → legacy fallback path).

Boundary notes

  • Root cause of the loadout reset itself stays in pi core (upstream /tree deactivates registered tools that the rewound branch never declared; reload() re-activates them earendil-works/pi#11075); this PR only narrows the in-scope compensation so it stops fighting external loadout managers.
  • The issue's second hypothesis (startup race: pi-loadout stores pending entries for selected tools but not explicit off entries, so a late default-active registration bypasses an off selection) was investigated independently against pi-loadout 0.0.38 source and CONFIRMED structurally — but that gap lives in pi-loadout's selection model (an external project), not in this repo. Reported in the issue thread; no cross-repo submission without owner approval.

The #3542 session_tree re-assert treated every registered-but-inactive bili tool as rewind-dropped and re-activated it. An external loadout manager (pi-loadout) or a manual toggle may keep a registered tool deliberately off; when its session_tree handler ran before bili's, the off selection was resurrected on every navigation (order-dependent).

Recovery is now judged against the pre-navigation loadout observed on session_before_tree (pi fires it inside navigateTree before the leaf switch and the _restoreToolsFromTranscript reset), with per-request sampling as fallback for hosts without the event. Only tools that were active before the navigation and are gone after it are recovered; a never-sampled host keeps the original all-registered recovery. Additive-only setter semantics unchanged; no new config surface.
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-27_pi-tree-recovery-respect-off-tools (0cf59f6)

Latest build — install this exact version

npm install -g billion-context@0.0.7143-pr.4996.537bc46

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

Recent builds (commit → version)

commit version build
0cf59f6 billion-context@0.0.7143-pr.4996.537bc46 build
eb3e785 billion-context@0.0.6878-pr.4996.8fcc373 build
ad53201 billion-context@0.0.6683-pr.4996.139b125 build
aa4649d billion-context@0.0.6615-pr.4996.a098d0b build
361e2e8 billion-context@0.0.6557-pr.4996.e6aadca build
ffa3d6e billion-context@0.0.6529-pr.4996.1758665 build

Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix: pi /tree recovery respects deliberately-off bili tools — pi-loadout selections survive navigation [PR] fix: pi /tree recovery respects deliberately-off bili tools — pi-loadout selections survive navigation Oct 27, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重: 不重复。 全仓 open/closed 检索无其他同修条目。相关历史:#3542(本 PR 收窄的那个 tree 恢复机制,已关)、#3545(已关)、上游 earendil-works/pi#11075(loadout reset 根因,外部项目)。本 PR 是 #4988 唯一的仓内修复。

标签: bug / pi / scope/wiring / p2(pi 车道协议接线缺陷,有绕行、不毁体验——与原始 issue #4988 定级一致)。

开始独立 review(方向/回归/代码/测试有效性/diff 整洁度逐项过)。分支落后 master 140 commits,按 3 楼 merge-guard 通知由专职守卫处理 rebase,本审核不重复操作。结论稍后按八问体例给出。

@ranxianglei ranxianglei added bug Something isn't working p2 pi scope/wiring labels Oct 27, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

PR #4996 review 结论(独立复审,未沿用 #4988 作者侧结论):

① 方向关:方向正确。根因独立定位与 PR 描述一致——#3542 的恢复判据是「已注册 vs 当前活跃」对比,隐含假设「注册了的 bili 工具不活跃 = 被 rewind 重置丢了」;当外部 loadout manager(pi-loadout)或手动切换刻意保持 off 时该假设不成立。修法打在判据本身(补「导航前状态」证据),不是症状层拦截,属根治。重置机制本体在 pi core(上游 earendil-works/pi#11075),不在本仓范围,本 PR 只收窄自家补偿面——边界处理正确。

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

③ 代码关:diff 通读完毕(仅 2 文件:src/agent/pi.ts +~47/−3、tests/plugin-agent.test.ts +102)+ 周边上下文。sampleActiveBili 防御姿态正确:registeredTools 空 / getActiveTools 缺失 / 调用抛错 / 返回非数组——一律保持 unobserved(never guess),绝不把错误观测写进决策。单 commit,无无关改动,未动版本号。

④ 测试有效性:不是假测试。harness 的 on() 按注册顺序链式执行多 handler(与真 pi 广播到全部 handler 的语义一致),setActiveTools 镜像真 pi 的去重行为;4 个新测试断言有牙:负门(deliberately-off 不被复活)、双 handler 顺序(loadout-first → 零 setter 调用;bili-first → 只恢复 actives)、previously-active 完整恢复、late-registration no-op→注册后恢复。正反向覆盖齐。

独立验证记录(不信 PR 正文与作者侧评论,全部自行复核):

  • 对照 earendil-works/pi 现行源码:navigateTree() 确实先发 session_before_tree(leaf switch 与 _restoreToolsFromTranscript() 之前)、后发 session_tree(_restoreToolsFromTranscript() 之后)——采样点即导航前 loadout ✓
  • registerTool 同步触发 refreshTools() 立即激活 default-active 工具——per-request 采样观察不到「已注册未激活」中间态,此处无洞 ✓
  • 本地定向跑:tests/plugin-agent.test.ts 79/79 绿(含既有 5 个 pi-native: /tree rewind resets the active tool loadout from the transcript, so bili tools become registered-but-inactive ("Tool compress not found") and the #2708 self-heal cannot see it #3542 case);tsc --noEmit 干净。
  • 全量套件留给 CI:最近一次快照 0 failed / 15 pending(镜像缓存停在旧快照,直连 API 撞全 fleet 限流无法即时刷新);且分支落后 master 140 commits、merge-guard 已派工处理 rebase——最终红绿以 rebase 到最新 master 后的 CI 为准,当前这轮检查跑在旧基线上,参考价值有限。

结构化八问:

  1. 是什么问题:pi /tree 导航后的工具恢复会把用户(或 pi-loadout)刻意关掉的 bili 工具重新打开,且依赖 handler 执行顺序——每次树导航都可能把 off 选择覆盖掉。
  2. 什么原因导致的:pi-native: /tree rewind resets the active tool loadout from the transcript, so bili tools become registered-but-inactive ("Tool compress not found") and the #2708 self-heal cannot see it #3542 的恢复判据缺「导航前活跃」证据,把「注册但不活跃」一律当成 rewind 重置丢失;重置机制本体在 pi core(上游 #11075),不在本仓范围。
  3. 影响范围与严重程度:仅 pi 车道且使用外部 loadout manager / 手动关闭 bili 工具并做树导航的用户;后果是选择被覆盖(可恢复,再关一次即可),不影响压缩正确性与数据。p2。
  4. 怎么修复的:以导航前 loadout 为判定基准——session_before_tree 采样(旧 host 由 per-request 采样兜底),只恢复「之前活跃且之后消失」的工具;从未采样的 host 保持原行为。
  5. 是否有回归问题:无。见 ② 清单——pi-native: /tree rewind resets the active tool loadout from the transcript, so bili tools become registered-but-inactive ("Tool compress not found") and the #2708 self-heal cannot see it #3542 保证、快路径、setter 语义、老 host 降级逐项保持;两个新发现边缘均安全向。
  6. 是否破坏缓存:不涉及——未触碰前缀缓存接缝、重试、游标、去重键。
  7. 是否改了设计方向:无——原地收窄既有补偿。外部边界两条已在 PR 注明:重置根因属 pi core(已报上游);startup-race 假设属 pi-loadout 选择模型(外部项目,结构确认,issue 线程已报告,未经 owner 批准不做跨仓提交)。
  8. 是否引入新配置:无——无 env、config 字段、CLI flag。

判定:代码层面通过审查,无需修改。合并前置条件:等 merge-guard 完成 rebase 到最新 master、新 head 上全套 CI 绿(当前 0 failed 但 15 pending,且跑的是旧基线结果)。声明的行为变更(旧:任何注册但非活跃的都复活 → 新:只恢复导航前活跃的)已在 PR 正文披露,与我的独立判断一致。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)
Re-synced origin/master (36 more commits landed since the last sync) — merged cleanly, zero conflicts; neither of this PR's files (src/agent/pi.ts, tests/plugin-agent.test.ts) was touched by those commits, so the fix is preserved verbatim. Pushed 361e2e8e → aa4649dcf. State after push: no longer behind — mergeable=true, mergeable_state=blocked only because required checks are re-running on the new head. No design decisions needed.

@qingkongwujian-art

Copy link
Copy Markdown

感谢修复和审查。请继续推进 #4996 合并;这个修复针对 /tree 后错误重新启用已关闭工具的问题,方向符合预期。

我核查时,最新 head aa4649dcf3b3eaf6d0f81db6a316d27d18be8740 显示分支落后 master,且 11 个测试分片失败。抽查 Linux 和 Windows 日志,失败发生在测试运行前:tests/issue4982-draining-twin-ladder.test.ts 未登记到 scripts/run-ci-tests.mjs 的 LIVE_FILES。请在同步最新 master 后处理并确认必要 CI 通过,再合并。

另外,现有模拟测试未覆盖源分支与目标分支工具选择不同的情况:若源分支启用某工具、目标分支关闭它,bili 在 pi-loadout 之后执行时,可能依据导航前状态重新启用它。请评估这个场景是否符合预期或需要补测。启动时异步注册的竞态也是独立问题,不应视作已由本 PR 修复。

ci-check added 2 commits October 29, 2026 08:35
…er orders

When source and target branches carry different tool selections (active on
source, deliberately off on target), bili's local view cannot distinguish a
rewind drop from the manager's deliberate off — the outcome is order-dependent.
Add two pinned rows (bili-last resurrects / manager-last keeps the target
selection) and correct the reassertLoadoutAfterTree doc, which overstated
'survives in either handler order'.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

进度汇报(进程曾被强制重启,先交代状态):

CI 红的根因已定位并修复。不是测试失败——11 个分片在测试运行前就死了:分支最后一次同步的 master(b08fbf361)之后,#4982 的进程派生套件 tests/issue4982-draining-twin-ladder.test.ts 进了 master 但没登记进 scripts/live-files.mjs 的 LIVE_FILES(master 侧由 02ef0d1 补上);分支 head 正好落在这个窗口里,run-ci-tests.mjs 的注册校验直接 die。与你的抽查结论一致。

已推送 ad53201(PR 分支 2026-10-27_pi-tree-recovery-respect-off-tools),内容:

  1. merge 最新 master(5594c1315)→ 注册恢复;本地按 run-ci-tests 同款规则复扫:无未登记 spawner。
  2. 你提的场景评估:真实存在,是已知残留边界——源分支 ON、目标分支 OFF 时,bili 的恢复判据依据「导航前观测」,跑在 pi-loadout 之后会把它复活、跑在之前则目标选择存活。两种情况在 bili 本地视角形状完全相同(回退丢失 vs 有意 off),猜修必然误伤一边,所以本 PR 不猜;新增 2 个测试把两种顺序下的行为显式钉住(标为 pinned-not-blessed 的已知残留)。彻底关闭需要扩展间协调信号,超出本 PR 范围。
  3. 顺带修正了一处过度声明的注释(「either handler order 都存活」补上差异选择例外)。

本地定向验证:typecheck ✅ build ✅ plugin-agent 81/81 ✅。启动时异步注册竞态不由本 PR 修复——#4988 下已有独立调查结论(缺陷在 pi-loadout 的选择模型),跟踪在那条,不重复立项。

CI 正在新 head 上重跑(static-gates/build/gate/mysql-contract 已过,11 个测试分片运行中),全绿后我发八问收尾。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

CI 已全绿:新 head ad53201ec,30/30 检查通过(11 个测试分片 ubuntu/windows × node 22/24 全过 + static-gates/build/gate/mysql-contract;e2e 真客户端车道按设计跳过)。

结构化八问:

  1. 是什么问题:两件事——① PR 分支落进 master 的一个「测试文件未登记」窗口,11 个 CI 分片在跑任何测试之前就死掉;② 你指出的「源分支启用某工具、目标分支关闭它」场景在现有测试里没有覆盖。
  2. 什么原因导致的:① [PR] release v0.1.209 #4982 的进程派生套件 tests/issue4982-draining-twin-ladder.test.ts 先进了 master(b08fbf361),登记 LIVE_FILES 的修复(02ef0d170)晚于本分支最后一次同步 master 的点落地——分支 head 恰好夹在中间,run-ci-tests.mjs 的注册校验直接 die。是同步时点问题,不是代码缺陷。② 修复后的恢复判据依据「导航前观测」:源 ON / 目标 OFF 且 bili 跑在 pi-loadout 之后时,导航前观测到的是 ON → bili 会复活它;bili 先跑则 pi-loadout 最后写回、目标选择存活。两种情况在 bili 本地视角形状完全相同(回退丢失 vs 有意 off),无法本地区分。
  3. 影响范围与严重程度:① 仅本 PR 的 CI 门禁,无运行时影响。② 特定条件(两个分支携带不同 loadout 选择 + handler 顺序为 loadout→bili)下 off 选择被复活;体验瑕疵级,有绕行(调整扩展顺序或导航后重新 off)。不扩大也不缩小原修复面。
  4. 怎么修复的:① merge 最新 master(5594c1315)恢复登记,本地按 run-ci-tests 同款规则复扫确认无未登记 spawner。② 不猜修——新增 2 个测试把两种顺序下的行为显式钉住(bili-last 复活 / bili-first 保留目标选择),注释标明这是 pinned-not-blessed 的已知残留边界;彻底关闭需要扩展间协调信号(如 pi-loadout 在 session_tree 后广播最终选择),超出本 PR 范围。顺带修正了一处过度声明的注释。
  5. 是否有回归问题:逐项过——恢复语义不变(仍 additive-only、只补「导航前激活且导航后消失」);pi-native: /tree rewind resets the active tool loadout from the transcript, so bili tools become registered-but-inactive ("Tool compress not found") and the #2708 self-heal cannot see it #3542 五测与新 4+2 例全绿(81/81);wire/payload 路径未触碰;merge 带入的 master 变更与本 PR 触碰文件无语义冲突(唯一重叠文件 scripts/live-files.mjs 本 PR 侧零改动)。有意行为变更:无新增(原修复的 old→new 已在 PR 正文披露)。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:不涉及。差异选择残留作为已知边界记录在代码注释与测试里,留给后续协调机制。
  8. 是否引入了新的配置:无。

启动时异步注册竞态:确认不由本 PR 修复,保持独立跟踪——#4988 下已有独立调查结论(pi-loadout 0.0.38 的选择模型只记正向条目、无显式 off 的 pending,缺陷在其存储模型,属外部项目,未经批准不向其提交)。不重复立项。

收工判定:修复方向经你确认、CI 全量绿、场景评估闭环(钉住而非掩盖)、竞态归属明确——就绪,等人工合并:#4996

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

新 head eb3e785fc(merge-guard 车道合入 master@09a5b5b77)的 3 个红分片定性:继承性 flake,非本 PR 代码问题。

结构化八问:

  1. 是什么问题:ubu24/3、ubu22/3、win22/4 三个测试分片各挂同一个子测试——#5140 cold-restored non-retained parent serves its intact raw tail immediately。
  2. 什么原因导致的:该子测试间歇性返回 409(期望 200),tests/plugin-fork.test.ts:1473——与 CI Control Center: Centralized CI Failure Handling & Status Sync (Comment all CI issues here; do not open new issues) | CI 总控: CI 失败集中处理与状态同步(所有 CI 问题在此评论, 勿开新 issue) #4599 在档的 master 自身红家族(floor 486/487)逐字同签名;master 同一 sha 同时存在全绿 run 和红 run,是 [PR] fix: recover non-retained parent fork snapshot from intact unified raw tail after cold restart (#5140) #5144(cold raw-tail fork,10-29 合入)引入的负载时序 flake。本分支内容 diff 仍只有 src/agent/pi.ts + tests/plugin-agent.test.ts 两文件(+209/−3),与 plugin-fork/fork-snapshot 路径零交集;ci-fixes@cf99d93 已整体包含在分支内,merge 无增量可推。
  3. 影响范围与严重程度:仅本 PR 的 CI 验证面,运行时/生产零影响;严重度 = CI 噪音,阻塞合并验证但不阻塞结论。
  4. 怎么修复的:分支侧无需改码(改本 PR 文件对继承 flake 无效)。已触发 rerun-failed-jobs(HTTP 201),等 attempt 2 判定;若同签名复红,按政策升级(决策请求 + 归入 [PR] fix: recover non-retained parent fork snapshot from intact unified raw tail after cold restart (#5140) #5144 flake 家族由哨兵收敛到 ci-fixes)。已在 CI Control Center: Centralized CI Failure Handling & Status Sync (Comment all CI issues here; do not open new issues) | CI 总控: CI 失败集中处理与状态同步(所有 CI 问题在此评论, 勿开新 issue) #4599 登记一行。
  5. 是否有回归问题:本轮零改动,不涉及。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:不涉及。
  8. 是否引入了新的配置:无。

rerun 结果出来我补终报。

This branch has not been deployed

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

Labels

bug Something isn't working p2 pi scope/wiring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pi: tree recovery can override pi-loadout disabled tools

2 participants