Repository navigation
Description
Environment
- pi
0.99.2 @tt-a1i/openpi0.9.0(installed from npm;extensions/shared/child-session.tsis byte-identical tomain)
Symptom
Every subagent_spawn fails immediately, for every built-in agent type (explorer, implementer, reviewer, advisor):
Child tool preflight failed: requested tools "tool_search", "codemode", "web_search",
"source_check", "fetch_content", "get_search_content", "agent_browser_action",
"agent_browser_qa", and 3 more are unavailable after child extensions initialized.
Check the Agent Type tools list and child extension loading.
The built-in types declare no tools: key, so this is pure inheritance from the parent — not a narrowing allowlist anyone wrote by hand.
Root cause
inheritedChildToolAllowlist() projects the parent's live pi.getActiveTools() into the child's requested allowlist (minus CHILD_EXCLUDED_TOOL_NAMES). bindChildSessionExtensions() then verifies that list against the fresh child registry, but it only activates the hardcoded names in CHILD_SAFE_PACKAGE_TOOL_NAMES (fd, rg, git_show, git_diff, git_log). Every other requested name must already be active in the child.
That assumption does not hold on current pi, where the parent's tool surface is mutable at runtime:
pi-web-accesswithtoolActivation: "auto"(the default) starts a session with onlyweb_enableand activatesweb_search/source_check/fetch_content/get_search_contentafter the model calls it.pi-agent-browser-nativeaddsagent_browser_action/_qa/_electron/_source/_network_sourceonly afteragent_browser_toolsenables them.- MCP servers with
deferredexposure bring intool_search;codemodeexposure brings incodemode.
So the parent legitimately holds tools that a brand-new child session has never activated, and the preflight turns that into a hard spawn failure. With a few of these packages installed, subagents become completely unusable.
Why extending the name list is not a fix
CHILD_SAFE_PACKAGE_TOOL_NAMES is a hand-maintained list of five names. Every package that activates tools on demand would need another entry, and the set is open-ended — the list cannot be kept in sync with what users install.
Suggested fix
1. Activate from requested, not from a hardcoded list. requested is already the narrowing allowlist (parent surface minus CHILD_EXCLUDED_TOOL_NAMES), so activating every requested name the child has registered cannot widen the boundary:
const toActivate = requestedSet ?? new Set<string>([...CHILD_SAFE_PACKAGE_TOOL_NAMES]);
for (const name of toActivate) {
if (available.has(name) && !active.has(name)) {
activeNames.push(name);
active.add(name);
}
}This covers any package, any pi release, and any MCP server without touching the code again.
2. Do not fail the whole spawn over an inherited tool. requested is derived from the parent's surface, so a missing name is not automatically a configuration error — it may be a runtime-registered tool the child never receives at all. Drop it and report instead; a hard failure is appropriate for an explicitly declared allowlist (an agent type's tools:), where silently dropping a name would hide the user's intent.
const missing = [...new Set(requested)].filter((name) => !active.has(name));
if (missing.length === 0) return;
console.warn(
`[openpi] child tool surface narrowed: ${missing.length} of ${requested.length} requested tool(s) unavailable ...`,
);Reproduction
- pi 0.99.2 with
pi-web-accessinstalled (defaulttoolActivation: "auto"). - In a parent session, get
web_searchinto the active set (callweb_enableonce, or letautochoose eager). - Call
subagent_spawnwithagent_type: "explorer". - It fails with the error above before the child's first prompt.
Patch against 0.9.0
Both changes are in one hunk set below; the patch applies cleanly to 0.9.0 (patch -p1).
--- a/extensions/shared/child-session.ts
+++ b/extensions/shared/child-session.ts
@@ -732,21 +732,25 @@
await session.bindExtensions({ mode: "print" });
const requested = effectiveChildToolAllowlist(requestedTools);
let active: Set<string> | undefined;
+ let available: Set<string> | undefined;
if (
session.getActiveToolNames &&
session.getAllTools &&
session.setActiveToolsByName
) {
const requestedSet = requested ? new Set(requested) : undefined;
- const available = new Set(session.getAllTools().map(({ name }) => name));
+ available = new Set(session.getAllTools().map(({ name }) => name));
const activeNames = session.getActiveToolNames();
active = new Set(activeNames);
- for (const name of CHILD_SAFE_PACKAGE_TOOL_NAMES) {
- if (
- available.has(name) &&
- !active.has(name) &&
- (requestedSet === undefined || requestedSet.has(name))
- ) {
+ // 父级继承来的工具在子会话里往往只是"已注册但未激活":内置扩展注册的
+ // tool_search / codemode,以及包提供的 web_search、agent_browser* 等,
+ // 都需要一次显式激活才会进入子会话的活动面。requested 是父级活动面去掉
+ // parent-only 工具后的白名单,按它激活不放宽任何边界;requested 缺失时
+ // 退回 CHILD_SAFE_PACKAGE_TOOL_NAMES。
+ const toActivate =
+ requestedSet ?? new Set<string>([...CHILD_SAFE_PACKAGE_TOOL_NAMES]);
+ for (const name of toActivate) {
+ if (available.has(name) && !active.has(name)) {
activeNames.push(name);
active.add(name);
}
@@ -769,8 +773,21 @@
const missing = [...new Set(requested)].filter((name) => !active.has(name));
if (missing.length === 0) return;
- throw new Error(
- `Child tool preflight failed: requested tool${missing.length === 1 ? "" : "s"} ${boundedToolNames(missing)} ${missing.length === 1 ? "is" : "are"} unavailable after child extensions initialized. Check the Agent Type tools list and child extension loading.`,
+ // `requested` is inherited from the parent's live tool surface, so a name the
+ // child cannot expose is not automatically an error. A parent can hold tools
+ // the child legitimately never gets: runtime-registered ones (an MCP server's
+ // tools, a package that activates tools on demand) or names no child
+ // extension registered at all. Failing the whole spawn over one of those is
+ // worse than running without it, so drop them and report once instead. The
+ // counts keep a genuine loading failure visible instead of silent.
+ const registeredCount = available?.size ?? 0;
+ const unregisteredCount = available
+ ? missing.filter((name) => !available.has(name)).length
+ : 0;
+ console.warn(
+ `[openpi] child tool surface narrowed: ${missing.length} of ${requested.length} requested tool(s) unavailable ` +
+ `(${unregisteredCount} never registered, ${missing.length - unregisteredCount} registered but inactive; ` +
+ `${active.size} active of ${registeredCount} registered). Dropped: ${boundedToolNames(missing)}`,
);
}
Activity
fix(subagents): activate inherited child tools instead of a fixed list
cuipengcx90 commentedon Oct 2, 2026
Second, independent root cause for the same symptom (2026-10-02).
tool_searchandcodemodein the failure above are not runtime-activated toolsthat a fresh child merely has not activated yet. They are never registered in
a child:
Pi's built-in extensions (
codemode,tool-search,mcp,llama.cpp) arebuiltin: trueinline extensions. Their code reaches aDefaultResourceLoaderonly through
extensionFactories: the CLI'smain()passes them, and an SDKcaller must pass them itself (
dist/core/resource-loader.js:245builds thebuilt-in registry from those factories,
dist/core/package-manager.js:740thenenables
builtin:<name>by default).createChildResources()passes none, so thechild has no built-in registry at all.
That is why extending
CHILD_SAFE_PACKAGE_TOOL_NAMEScannot cover these twonames: activating only works on a name the child has registered.
#638 now also injects
tool-searchandcodemodeinto the child loader, whichremoves both "never registered" entries (verified: a child reports all 28 tools
and the warning is gone). The same revision keeps the preflight hard for an
explicit allowlist, and fixes a latent replay-fingerprint failure that injecting
a built-in extension exposes.
azcine94 commentedon Oct 2, 2026
补充复现:仅激活内置 codemode 即可导致默认子代理启动失败
在 Pi 0.99.1 + OpenPI 0.9.0 上独立复现了本 Issue 中 codemode 未在子会话注册的情况。该复现不需要安装 pi-web-access、浏览器工具等额外包,也不依赖 MCP 自动激活:父会话显式激活内置 codemode 后,默认子代理就会启动失败。
环境
0.9.00.99.1v24.18.0(复现测试使用)pi,通过 SDK 创建独立子会话问题描述
当父会话激活内置
codemode工具后,OpenPI 默认继承父会话工具的子代理无法启动。该问题同时出现在
codemode.mode: "on"和"only"下。即使不通过 codemode 脚本,而是直接调用
subagent_spawn,也会失败。 触发条件是父会话已经激活 codemode,而不是派发调用是否经过 codemode。仅加载 codemode 扩展、但未激活该工具时,子代理可以正常启动。
复现步骤
在已加载 OpenPI 的 Pi 会话中,确认内置 codemode 没有被
-builtin:codemode排除。在现有设置中加入以下配置,保留其他设置:
{ "defaultTools": ["+codemode"], "codemode": { "mode": "on" } }重启会话或执行
/reload,确认codemode已处于活动工具列表中。加载子代理工具组:
在后续工具调用中派发一个未指定自定义工具限制的子代理:
子代理在启动阶段报错:
在
delegate已加载后,通过 codemode 调用同一派发工具,也会得到相同的错误:预期行为
激活父会话的 codemode 不应导致原本可用的默认子代理派发失败。无论直接调用
subagent_spawn,还是通过 codemode 调用,子代理都应能够完成初始化并执行任务。实际行为
子代理首次模型请求之前的工具预检查失败,任务无法开始。
通过 codemode 调用时,外层脚本返回:
对照测试结果
on模式on模式only模式相关调用链
以下行号对应本地安装的 OpenPI 0.9.0:
extensions/subagents/index.ts:1028:从pi.getActiveTools()生成子代理工具清单,父会话激活 codemode 后,该清单包含codemode。extensions/shared/child-session.ts:653:createChildResources()创建DefaultResourceLoader,但没有提供 codemode 扩展工厂。extensions/subagents/src/backends/pi.ts:233–265:使用上述资源加载器创建 SDK 子会话,并执行bindChildSessionExtensions()。extensions/shared/child-session.ts:769–773:检查要求的工具是否出现在子会话活动工具列表中,发现缺少codemode后抛出错误。Pi 0.99.1 的
docs/sdk.md明确区分 CLI 与 SDK 的内置扩展加载行为。这里观察到的是:子代理继承的工具清单包含 codemode,但其 SDK 子会话未注册该工具。验证方式与范围
subagent_wait结果回传。本评论仅补充复现与诊断证据,不提出解决方案。
tt-a1i commentedon Oct 4, 2026
The source and regression investigation is preserved in Child tool inheritance and replay identity, linked from PR #638.
The follow-up fixes keep explicit role tool requirements strict at both public entries, verify Pi's actual active surface after activation, and retain native/inline extension identity boundaries for replay. Local full checks and tests passed, and independent subagent review found no remaining defects at
e8c43cb1. Current-head CI is being completed before merge; the record states the SDK and external-package validation limits.fix: restore Pi child tools and preserve explicit requirements (openp…