Skip to content

Conversation

@daniel-lxs
Copy link
Member

@daniel-lxs daniel-lxs commented Jan 12, 2026

Problem

When storing conversation history with MCP tool calls, the tool_use.id may contain characters not allowed by the API validation pattern ^[a-zA-Z0-9_-]+$. This causes errors like:

messages.1.content.1.tool_use.id: String should match pattern '^[a-zA-Z0-9_-]+$'

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

  1. New: src/utils/tool-id.ts - Utility function for ID sanitization
  2. Modified: src/core/task/Task.ts - Applied sanitization at lines 3439 and 3460
  3. New: src/utils/__tests__/tool-id.spec.ts - 15 comprehensive test cases

Performance

  • Single regex call per tool_use at storage time only
  • No-op for valid IDs (most common case)
  • All existing tests pass

Closes ROO-514


Important

Adds sanitizeToolUseId() to ensure tool_use.id conforms to API validation, with updates in Task.ts and comprehensive tests.

  • Behavior:
    • Adds sanitizeToolUseId() in tool-id.ts to replace invalid characters in tool_use.id with underscores.
    • Applies sanitizeToolUseId() in Task.ts at lines 3439 and 3460 to sanitize tool_use.id before storing conversation history.
  • Utilities:
    • New utility function sanitizeToolUseId() in tool-id.ts.
    • Updates mcp-name.ts with normalizeMcpToolName() to handle underscore to hyphen conversion.
  • Tests:
    • Adds tool-id.spec.ts with 15 test cases for sanitizeToolUseId().
    • Updates mcp-name.spec.ts to test normalizeMcpToolName() and other MCP name utilities.

This description was created by Ellipsis for b5fadc8. You can customize this summary. It will automatically update as commits are pushed.

@daniel-lxs daniel-lxs requested review from cte, jr and mrubens as code owners January 12, 2026 22:14
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Jan 12, 2026
@roomote
Copy link
Contributor

roomote bot commented Jan 12, 2026

Rooviewer Clock   See task on Roo Cloud

Review complete. No issues found.

The PR correctly addresses the API validation issue by:

  • Adding sanitizeToolUseId() that replaces invalid characters with underscores to match pattern ^[a-zA-Z0-9_-]+$
  • Applying sanitization at the storage boundary in Task.ts (lines 3439 and 3460)
  • ID consistency between tool_use.id and tool_result.tool_use_id is handled by validateAndFixToolResultIds
  • Adding comprehensive test coverage (15 tests for tool-id)

All tests pass.

Previous reviews

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

When storing conversation history with MCP tool calls, the tool_use.id may
contain characters not allowed by the API validation pattern ^[a-zA-Z0-9_-]+$.

This adds sanitizeToolUseId() function that replaces invalid characters with
underscores, applied at the storage boundary in Task.ts.

Closes ROO-514
@daniel-lxs daniel-lxs force-pushed the feature/roo-514-sanitize-tool_use-ids-to-match-api-validation-pattern branch from b5fadc8 to 293bc2d Compare January 12, 2026 22:27
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jan 12, 2026
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Review] in Roo Code Roadmap Jan 12, 2026
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jan 12, 2026
@daniel-lxs daniel-lxs merged commit 621d950 into main Jan 12, 2026
27 of 30 checks passed
@daniel-lxs daniel-lxs deleted the feature/roo-514-sanitize-tool_use-ids-to-match-api-validation-pattern branch January 12, 2026 23:05
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Jan 12, 2026
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jan 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants