fix(opencode): match MCP tool calls case- and hyphen-insensitively at dispatch#31514
Open
sqeeswy wants to merge 1 commit into
Open
fix(opencode): match MCP tool calls case- and hyphen-insensitively at dispatch#31514sqeeswy wants to merge 1 commit into
sqeeswy wants to merge 1 commit into
Conversation
Contributor
|
The following comment was made by an LLM, it may be inaccurate: One potentially related PR found: PR #29156:
The other results are mostly unrelated tooling/schema fixes. The search for the specific issue numbers (#31506, #27396) that this PR fixes didn't return other open PRs. Recommendation: Check if PR #29156 is still open and whether it addresses the same underlying problem or if they can be coordinated. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
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.
Issue for this PR
Closes #31506
Closes #27396
Type of change
What does this PR do?
MCP tools are registered with case- and hyphen-preserving names (
mcp/index.ts:sanitize(client) + "_" + sanitize(tool)), e.g.Tool_get_proporserver_get-by-id. Models frequently emit a lowercased or all-underscore variant of the name. When that happens the AI SDK reports the call as unrecognized and hands it toexperimental_repairToolCallinsession/llm.ts. That repair only tried the lowercased form, so a capitalized-prefix tool (#31506) or a hyphenated tool called with underscores (#27396) never matched and every call routed to theinvalidsentinel tool in a loop.The fix adds
repairToolName, which matches the failed name back to the registered key by normalizing both sides case-insensitively and treating-and_as equivalent. If the normalization is ambiguous (more than one registered key collapses to the same form) it returns nothing, so the call still routes toinvalidrather than guessing the wrong tool. This is the single client-side dispatch chokepoint, so it covers both issues without touching registration.This is separate from #29156, which sanitizes genuinely malformed names (invalid characters) at the serialization boundary in
message-v2.ts. This PR only normalizes well-formed names at dispatch; the two do not overlap.How did you verify your code works?
From
packages/opencode:bun typecheck— cleanbun test test/session/llm.test.ts— 31 pass, 0 failAdded unit tests for
repairToolNamecovering both axes (case and hyphen/underscore), an exact match, an unknown name, and an ambiguous collision.Screenshots / recordings
Not a UI change.
Checklist