fix: sanitize tool_use IDs to match API validation pattern #10649
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
When storing conversation history with MCP tool calls, the
tool_use.idmay contain characters not allowed by the API validation pattern^[a-zA-Z0-9_-]+$. This causes errors like:This can occur when MCP server names contain special characters (periods, colons, slashes) that leak into tool IDs.
Solution
Created a
sanitizeToolUseId()function that replaces any invalid character with underscore, applied at the storage boundary in Task.ts when building assistant content for API conversation history.Changes
src/utils/tool-id.ts- Utility function for ID sanitizationsrc/core/task/Task.ts- Applied sanitization at lines 3439 and 3460src/utils/__tests__/tool-id.spec.ts- 15 comprehensive test casesPerformance
Closes ROO-514
Important
Adds
sanitizeToolUseId()to ensuretool_use.idconforms to API validation, with updates inTask.tsand comprehensive tests.sanitizeToolUseId()intool-id.tsto replace invalid characters intool_use.idwith underscores.sanitizeToolUseId()inTask.tsat lines 3439 and 3460 to sanitizetool_use.idbefore storing conversation history.sanitizeToolUseId()intool-id.ts.mcp-name.tswithnormalizeMcpToolName()to handle underscore to hyphen conversion.tool-id.spec.tswith 15 test cases forsanitizeToolUseId().mcp-name.spec.tsto testnormalizeMcpToolName()and other MCP name utilities.This description was created by
for b5fadc8. You can customize this summary. It will automatically update as commits are pushed.