Skip to content

feat(pi): capability-aware proxy-style ACP channel for pi-subagents children (#2268) - #2276

Merged
ranxianglei merged 2 commits into
masterfrom
wt-2268-ework-daemon
Oct 7, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
wt-2268-ework-daemon

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Oct 6, 2026 •

Copy link
Copy Markdown
Owner

Closes #2268

Problem

pi-subagents' 7 builtin roles all ship strict frontmatter tools: allowlists that grant none of the ACP context tool names. Since #2185's required-extension self-registration, those children get named plugin sessions but run in pure plugin mode with no local ACP tools and no wire injection — interactive compression silently regressed for default roles versus pre-#2185 (when FG children were anonymous pfa-* proxy-mode sessions whose ACP tools came from proxy wire injection).

Fix

Per-request capability gate (src/server/pi-subagent-channel.ts) wired at the single pluginMode decision point in src/server.ts: a plugin-stamped pi request that carries pi-subagents' <active_agent name="…"> child marker AND exposes none of the bili-injectable tool names in its parsed tools[] is served through the existing proxy-style channel (wire-injected tools + nudge, server-side execution, acp_summary carrier; CCR/image/demote gates follow the effective mode). Session identity stays plugin-bound (named session, pluginAgent=pi, stamping untouched). Stateless per request: mid-session whitelist changes self-heal on the next request.

  • Marker choice: pi-subagents stamps every child session's system prompt at launch (buildInProcessChildLaunch) for BOTH foreground and background hosts; the raw-body sniff is exact across all four wire shapes (marker bytes are never JSON-escaped). The alternative signal PI_SUBAGENT_CHILD=1 exists only in the detached BG runner process — FG children don't have it.
  • Scope is owner-directed: nicobailon/pi-subagents children only (the marker is theirs); other plugin hosts and untagged requests are unaffected. Roles exposing any injectable name stay pure plugin mode — duplicate tool declarations would be rejected by providers, so partial grants are unsupported by design. If upstream drops the tag, behavior degrades gracefully to today's (named session, no local ACP tools).
  • No bypass of pi-subagents' security model: bili never asks the host to execute undeclared tools; it serves the compression channel server-side exactly as for any plain client. The role's original allowlist rides the wire unchanged alongside the injected names.

Behavior changes (old → new)

Case Old (v0.1.186+) New
pi-subagents child, role grants no ACP names (all 7 builtins) Named session, pure plugin mode, no local ACP tools, no wire injection Proxy-style channel: ACP tools injected + nudge + server-side execution; named session identity kept
Role grants ≥1 ACP name, or unrestricted role Pure plugin mode, locally registered tools Unchanged
Non-pi plugin hosts / untagged pi requests Pure plugin mode Unchanged (gate requires marker AND zero exposure)

Reason for the change: restore pre-#2185 compression capability on top of #2185's identity, per owner direction ("最好默认注入,而不是改配置文件").

Accepted residual edges: config-renamed absorb.toolName/ccr.toolName colliding with a role-whitelisted name (would keep such children on the plugin lane); partial grants remain unsupported.

Config surface

None — no new config field, env var, or CLI flag. Existing kill switches (BILLION_CONTEXT_PLUGIN=0, BILI_NATIVE_PI=0) suppress the whole native lane upstream of this gate.

Tests

  • tests/pi-subagent-channel.test.ts (new): 11 tests — marker sniff (absent / JSON-escaped / truncated-at-buffer-end / history-echo leniency), tools walker across all four wire shapes (8 injectable names, near-miss names, malformed entries never throw), composition (delegate/oracle fall back; granted-compress stays plugin; untagged and non-pi never fall back) plus 4 real-HTTP rig cases against a live proxy instance.
  • tests/e2e/e2e-native-pi.test.ts: two scenarios drive unmodified builtin delegate children through real pi-subagents@0.76.1 (hermetic install into the workspace scratch dir, version pinned, skips cleanly when the registry is unreachable):
    • fresh: asserts every child request carries the injected ACP core four plus delegate's original whitelist, one real acp_status round trip executed server-side, the once-per-session fallback log with the extracted role name, parent-session plugin surface intact, and both sessions persisted with pluginAgent=pi.
    • fork (real compression proof): run one loads bulky filler into the parent session; run two spawns the delegate with context:"fork" so the child inherits the transcript (the filler leaves the kernel's protected zone inside the child). Asserts a real model-invoked compress folded it server-side — receipt matches [Compressed m…–m… → N block(s), ~T tokens saved] — plus a post-fold acp_status showing the active block, and the compressed block persisted in the CHILD's named session.
  • Local (on rebased head, current master): typecheck clean, build clean, unit 11/11, full e2e-native-pi lane 6/6 (existing tests prove the gate is a byte-no-op for untagged traffic). Global suite + CI lanes via remote CI.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到,开始按 PR Review 规范审 #2276(① 原 issue 方向 → ② 回归清点 → ③ 代码 → ④ 测试有效性 → ⑤ diff 整洁度)。先核对 gate 的可注入名集合与代理端实际注入列表是否一一对应(缺一个名字 = 角色白名单含该名时双注入被 provider 拒绝),再走 CI 与定向验证。结论按结构化七问给出。

…hildren (#2268)

pi-subagents builtin roles ship strict frontmatter tools: allowlists that
grant none of the ACP context tool names; since #2185's required-extension
self-registration those children get named plugin sessions but lose the
wire-injected ACP tools they had pre-#2185 (anonymous pfa-* proxy mode), so
interactive compression silently regressed for default roles.

Per-request gate (src/server/pi-subagent-channel.ts): a plugin-stamped pi
request carrying pi-subagents' <active_agent name=> child marker whose tools
array exposes none of the bili-injectable names is served through the
proxy-style channel (wire-injected tools + nudge, server-side execution,
acp_summary carrier). Session identity stays plugin-bound; stateless per
request, self-healing on whitelist changes; scoped to nicobailon/pi-subagents
children only (owner-directed); roles exposing any injectable name stay pure
plugin mode (partial grants unsupported).

Tests: 11 unit (marker sniff, 4-shape tools walker, composition) + 4 real-HTTP
rig cases; e2e-native-pi gains a real pi-subagents@0.76.1 unmodified-delegate
child scenario (injected ACP surface + preserved whitelist + acp_status
round trip + named-session persistence + parent purity). CLIENTS en/zh caveat
rewritten from manual-grant recipe to auto-injection behavior.
@ranxianglei
ranxianglei force-pushed the wt-2268-ework-daemon branch from 2eb2132 to ef12054 Compare October 6, 2026 16:18
@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: wt-2268-ework-daemon (50a0d24)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2427-pr.2276.bdefc0e

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-pr2276.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] 🏷 Review 完成 — 判定:可合并。 已按 PR Review 规范走完 ①原issue → ②回归清点 → ③代码 → ④测试有效性 → ⑤diff整洁度。先报告审查中发现并已修复的唯一拦路项,再按结构化七问作答。

⚠️ Stale base / merge conflict(已在 PR 分支上直接修复)
PR base 停在 850067292,而 master 已推进到 9f82bbed8(99 files,含 #2155/#2246 self-heal degrade、#2241/#2250 persona continuity、#2267 acp-tag unified 等多个 src/server.ts 变更)。GitHub mergeable=False,内容冲突恰好落在 src/server.ts 的 pluginMode 决策点;且该分支此前从未跑过任何 CI。按「小问题直接修」在 PR 分支上 rebase 解决冲突:master 的 #2155 pluginLaneDegraded 降级与本 PR 的 capability gate 都是 plugin→proxy 降级,语义上合取组合(src/server.ts:2820):

const pluginMode = pluginAgent !== undefined && !pluginLaneDegraded(session) && !subagentFallback.present;

本地定向验证:typecheck clean、新增单测 11/11、tests/issue2155-self-heal.test.ts 12/12(钉住组合后的表达式)。已 push:ef120549d。

① 是什么问题:pi-subagents 的 7 个 builtin role frontmatter 都是不带 ACP 工具名的严格 allowlist;#2185 把它们 named-plugin 化后,children 失去了 #2185 之前(匿名 pfa-* proxy session)从 wire 注入得到的 ACP 工具,交互式压缩静默退化为只剩 preflight 硬兜底。

② 什么原因导致的:两层因果。① pi 的最小权限工具规划根本不会把扩展注册名放进 effectiveToolAllowlist(上游安全模型,bili 不能也不该绕过);② #2185 把 children 从匿名 proxy lane 切到纯 plugin lane,关闭了 wire 注入通道——能力与通道被绑死在同一开关上。

③ 怎么修复的:在 src/server.ts 唯一的 pluginMode 决策点加 per-request 能力门(新模块 src/server/pi-subagent-channel.ts,stateless):pi plugin-stamped 请求 + <active_agent name="…"> child marker + tools[] 暴露的 bili-injectable 名字为零 → 走既有 proxy-style lane(wire 注入 + nudge + server-side 执行 + acp_summary carrier);身份保持 plugin-bound。marker 而非 PI_SUBAGENT_CHILD env,因 env 只存在于 detached BG runner 进程。本审查额外修掉了 stale-base 冲突(#2155 降级合取,见上)。

④ 是否有回归问题:审过触碰路径的既有行为——untagged / 非 pi / granted 请求与之前逐字节一致(gate 需三条件同时成立,既有 e2e-native-pi 的 untagged traffic 即 no-op 证明);#2155 degrade/restore 语义保留(其 12 项套件 green);preflight mode-independent 未动;CCR stamping / image arming / demoteGate / stableSystemAnchor 均按既有设计跟随 effective mode(KDD#7 双模式 carrier 语义不变)。未发现无意回归;有意行为变更(PR body 的 old→new 表)披露完整。一处文档措辞("duplicate tool declarations are rejected by providers")严格说不准确(injectTool/injectOpenaiTool/injectGoogleTool/injectResponsesTool 均对 bili-owned 名去重,重复声明到不了 provider),但细看可作「为何不支持 partial grant」的设计理由解读,且更替措辞会过claim,故不改——留档备查。

⑤ 是否破坏缓存:不涉及——无 dedup key / 重试 / 增量游标变化;fallback child session 每请求 tools 数组稳定(role whitelist + 注入后缀),prefix cache 行为与其他 proxy-mode session 相同。

⑥ 是否改了设计方向:不涉及——复用两条既有 lane,只加一个决策点;不绕过 pi-subagents 安全模型(bili 不要求 host 执行未声明工具);范围按 owner 决定限 nicobailon/pi-subagents。

⑦ 是否引入新配置:不涉及——diff 不触碰 config surface;上游 kill switches(BILLION_CONTEXT_PLUGIN=0 / BILI_NATIVE_PI=0)仍有效。

结论:可合并。 rebased head ef120549d 上 CI 13/13 lanes 全绿(含 e2e-native-pi:真实 pi-stable + hermetic pin 装 pi-subagents@0.76.1,驱动未改动的默认 delegate,断言每请求工具面、server-side acp_status 真实往返、once-per-session log、父会话表面完整、双会话持久化 pluginAgent=pi);GitHub mergeable=True。按 §7.4 这是 feat(wire 行为变更),human merge:#2276

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到「上游 PR 冲突」唤醒——经查证是过期通知,本轮未做任何改动(按规则不重复 rebase)。

查证证据(刚执行):

  • origin/master 仍为 9f82bbed8 —— 与我上一轮 rebase 所用的 base 完全相同,master 自那次 push 后没有再前进;
  • PR head ef120549d 已直接落在该 base 上(base 字段即 9f82bbed8);
  • git merge-tree --write-tree origin/master origin/wt-2268-ework-daemon → exit 0,零冲突(merged tree 99b076b…);
  • GitHub API:mergeable=True;
  • 该 head 上 CI 13/13 lanes 全绿(上一轮已报告)。

结论:dirty 状态产生于我 rebase 之前(旧 head 2eb2132c5 确实与 master 冲突),平台轮询到的是旧快照;force-push 落地后状态已自动转干净。无需再动。

七问速览(完整论证见上一条 review 回复):

  1. 是什么问题:pi-subagents builtin roles 的严格 allowlist 不含 ACP 工具名,[pi] native 模式第三方 pi-subagents 深度测试与修复:extension registry 自注册(方案 A)落地 #2185 named-plugin 化后 children 失去 wire 注入的 ACP 工具,交互式压缩静默退化。
  2. 什么原因导致的:pi 最小权限规划不放扩展名进 allowlist(上游安全模型)+ [pi] native 模式第三方 pi-subagents 深度测试与修复:extension registry 自注册(方案 A)落地 #2185 把通道从 proxy 切到纯 plugin,能力与通道绑死同一开关。
  3. 怎么修复的:唯一 pluginMode 决策点加 per-request 能力门(pi-stamped + <active_agent> marker + 零 injectable 暴露 → 走既有 proxy-style lane);身份保持 plugin-bound。本审查另修了 stale-base 冲突(会话卡死自愈机制:卡死模式检测与代理侧主动补救 #2155 degrade 合取组合,src/server.ts:2820)。
  4. 是否有回归问题:无——untagged/非 pi/granted 请求逐字节不变,会话卡死自愈机制:卡死模式检测与代理侧主动补救 #2155 degrade/restore 保留(其套件 12/12 green),preflight 未动,双模式 carrier 语义(KDD#7)不变;有意变更已在 PR body 披露。
  5. 是否破坏缓存:不涉及——dedup/retry/游标均未变,fallback session tools 数组稳定,prefix cache 同其他 proxy-mode session。
  6. 是否改了设计方向:不涉及——复用两条既有 lane + 一个决策点,不绕过 pi-subagents 安全模型,范围限 nicobailon/pi-subagents。
  7. 是否引入新配置:不涉及——config surface 零触碰,上游 kill switches 仍有效。

判定维持:可合并。 #2276

@ranxianglei
ranxianglei merged commit c4e5954 into master Oct 7, 2026
26 checks passed
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.99-master.c4e5954 (rolling master tag).

npm install -g billion-context@0.0.99-master.c4e5954  # 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.

[Pi / pi-subagents] 默认内置角色的 tools 白名单阻挡 ACP:bili 自动加载成功,但上下文工具仍不可调用

1 participant