Repository navigation
fix(agent-runtime): keep on-demand tools active for the whole session - #1279
Merged
Merged
Conversation
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.
Owner
|
审核结论:问题真实,sticky activation 的修复触及根因,且当前 head 的 agent-runtime 定向测试通过(261/261)。 我在独立 worktree 复跑了:
暂不直接合入:该 PR 的 GitHub |
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1225
Problem
On Windows, Bash / Read / Glob / Grep intermittently fail with
Tool <name> not foundin 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 (
resetDeferredToolsForPromptclearedactiveDeferredToolNames) 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.
rebuildToolCatalogremains 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 pruningnpx tsc --noEmit -p packages/agent-runtime: cleannative-pi-sessionWindows path assertion) and thehosted-search-compactiondist-resolution failure reproduce identically on unmodified origin/main — pre-existing environment issues, unrelated to this changegit merge-base --is-ancestor origin/main HEADverified before push