fix(cache): sort MCP tools deterministically to stabilize prompt cache#2
Open
fix(cache): sort MCP tools deterministically to stabilize prompt cache#2
Conversation
…#60452) * refactor: move bundled replay policy ownership into plugins * test: preserve replay fallback until providers adopt hooks * test: cover response replay branches for ollama and zai --------- Co-authored-by: Shakker <shakkerdroid@gmail.com>
Merged via squash. Prepared head SHA: 28ae50b Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com> Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com> Reviewed-by: @gumadeiras
…or [AI] (openclaw#59822) * fix: address issue * fix: address PR review feedback * docs: add changelog entry for PR merge * docs: normalize changelog entry placement --------- Co-authored-by: Devin Robison <drobison@nvidia.com>
…a exceeds size limit (openclaw#60289) Merged via squash. Prepared head SHA: f33dd49 Co-authored-by: efe-arv <259833796+efe-arv@users.noreply.github.com> Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com> Reviewed-by: @gumadeiras
* fix(sandbox): block home credential binds * fix(sandbox): harden blocked credential bind checks
e134420 to
2ca9eed
Compare
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.
Problem
createBundleMcpToolRuntime(src/agents/pi-bundle-mcp-tools.ts:122) is called on every turn fromattempt.ts:1842. It collects tools viaclient.listTools()without sorting, then returns them in collection order.The MCP spec doesn't guarantee
listTools()order. If tool order differs between turns — from paginated responses, third-party server implementations, or future SDK changes — the tools array in the API request changes, busting the prompt cache at the tools block.Fix
Sort the collected tools alphabetically by name before returning:
This makes the tools block deterministic regardless of
listTools()iteration order or server-config iteration order.Semantics unchanged: collision resolution (first-server-wins via
reservedNamesset) happens during collection, before the sort.Verification
zeta, alpha, mu— asserts runtime returns[alpha, mu, zeta]attempt.tsare name-based (allowlist, prefix-stripping at :620), not position-basedFollow-up (not in this PR)
Hoist runtime to session scope.
createBundleMcpToolRuntimecurrently spawns stdio transports +listTools()on every turn and disposes in thefinallyatattempt.ts:3227. Bigger win: cache the runtime keyed on a hash ofloaded.mcpServersconfig, dispose on session end. Stops re-spawning MCP servers per turn. More invasive — needs session-lifecycle wiring.🤖 Generated with Claude Code