Skip to content

fix(agent-runtime): keep on-demand tools active for the whole session - #1279

Merged
vastsa merged 4 commits into
vastsa:mainfrom
yexisu:fix/deferred-tool-sticky-activation
Oct 2, 2026
Merged

vastsa merged 4 commits into
vastsa:mainfrom
yexisu:fix/deferred-tool-sticky-activation

Conversation

@yexisu

@yexisu yexisu commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Fixes #1225

Problem

On Windows, Bash / Read / Glob / Grep intermittently fail with Tool <name> not found in 0 ms. The failure happens at name resolution: the model emits a tool call whose name is not in the schema the current request shipped, so pi-agent-core rejects it immediately.

Root cause

Deferred tool activation was reset at every prompt (resetDeferredToolsForPrompt cleared activeDeferredToolNames) and re-derived only from the visible context. When the ToolSearch announcement and the tool's own results fell out of the context window (compaction, long turns), the restore found nothing to reactivate, the next request shipped a schema without the tool, and a direct call was rejected. That is exactly the intermittent "same session, same tool, alternates between working and failing" pattern in the report.

Change and trade-offs

Activation is now sticky per session: the prompt-time context restore still runs as a backfill (#225 behavior preserved), but nothing clears the set mid-session. rebuildToolCatalog remains the owner of the catalog and prunes both sets on mode switches and extension reloads, so the sticky set cannot outlive the tools it names.

Design note: this relaxes the "every new prompt starts with a minimal toolset" intent recorded at the old call sites, keeping more tool declarations per request than the strict per-prompt reset. The alternative — keeping only context-derived activation — is what reproduces the bug, and a full ADR-level redesign of the on-demand catalog is out of scope for this fix. If schema size per request becomes a concern, a follow-up can cap the sticky set by recency.

Validation

  • npx vitest run packages/agent-runtime/src/runtime.test.ts: 261/261 pass, including new tests pinning sticky activation and catalog pruning
  • npx tsc --noEmit -p packages/agent-runtime: clean
  • Full agent-runtime suite: 1130/1131; the 1 failing test (native-pi-session Windows path assertion) and the hosted-search-compaction dist-resolution failure reproduce identically on unmodified origin/main — pre-existing environment issues, unrelated to this change
  • git merge-base --is-ancestor origin/main HEAD verified before push

Deferred tool activation was reset at every prompt and re-derived only
from the visible context. When the ToolSearch announcement and the
tool's own results fell out of the window (compaction, long turns),
the next prompt shipped a schema without the tool and the model's
direct call was rejected at name resolution — the intermittent
"Tool <name> not found" 0 ms failure users hit on Windows (vastsa#1225).

Activation is now sticky per session: the prompt-time context restore
still runs as a backfill, but nothing clears the set mid-session.
rebuildToolCatalog remains the owner of the catalog and prunes both
sets on mode switches and extension reloads, so the sticky set cannot
outlive the tools it names. Tests updated to pin the new behavior.
@vastsa

vastsa commented Oct 1, 2026

Copy link
Copy Markdown
Owner

审核结论:问题真实,sticky activation 的修复触及根因,且当前 head 的 agent-runtime 定向测试通过(261/261)。rebuildToolCatalog() 会清理不再存在的工具,模式切换也会清空激活集合,当前未发现权限或工具越权回归。

我在独立 worktree 复跑了:

  • vitest run packages/agent-runtime/src/runtime.test.ts:261/261 通过
  • git merge-base --is-ancestor origin/main HEAD:通过

暂不直接合入:该 PR 的 GitHub Head contains latest base 检查仍失败,需刷新 PR integration candidate / 重新触发该门禁。完整 typecheck 在共享 pnpm 依赖链接环境中被既有 subagent-model-binding.ts 的可移植推断错误阻断,不能替代 CI 通过。

@vastsa
vastsa merged commit 2fa8fc1 into vastsa:main Oct 2, 2026
4 checks passed

This branch was previously deployed

1 inactive deployment
Preview — 9fb0fd8e Deployed Oct 2, 2026 by vercel[bot]
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.

[Bug] Bash / Read / Glob / Grep intermittently fail with Tool <name> not found (0 ms) on Windows — present in 0.15.9 and 0.15.10

2 participants