Skip to content

Conversation

@roomote
Copy link

@roomote roomote bot commented Nov 5, 2025

Description

This PR addresses Issue #9041 where the thinking block for Grok Code Fast 1 was displaying tool-related XML tags like <appy_diff> and <switch_mode> instead of just the model's reasoning content.

Problem

When using Grok Code Fast 1, the reasoning/thinking collapsible blocks sometimes showed tool command tags mixed with actual thinking content, making it difficult to read the model's actual reasoning process.

Solution

  • Added a sanitizeReasoningContent() function in the XAI provider that removes known tool-related XML/HTML tags while preserving the text content between them
  • The function uses a targeted regex pattern to match and remove specific tool tags (apply_diff, switch_mode, write_to_file, etc.)
  • Integrated sanitization into the streaming pipeline before yielding reasoning content to the UI
  • Added logic to skip empty reasoning chunks after sanitization

Testing

  • Added comprehensive unit tests covering:
    • Simple tag removal with preservation of inner text
    • Complex nested/multiline tool tag blocks
    • Empty-after-sanitization scenarios
    • Preservation of clean reasoning content
  • All existing tests continue to pass

Result

The thinking blocks now accurately display only the model's reasoning without extraneous tool command tags, as requested in the issue.

Fixes #9041


Important

Adds sanitizeReasoningContent() to remove tool-related tags from reasoning content in XAIHandler, with tests for various scenarios.

  • Behavior:
    • Adds sanitizeReasoningContent() in xai.ts to remove tool-related XML/HTML tags from reasoning content.
    • Integrates sanitization in createMessage() in XAIHandler to clean reasoning content before yielding.
    • Skips yielding reasoning if content is empty after sanitization.
  • Testing:
    • Adds unit tests in xai.spec.ts for tag removal, nested tags, empty content, and clean content preservation.
    • Ensures all existing tests pass.

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

- Added sanitizeReasoningContent function to remove tool-related XML tags
- Prevents display of <appy_diff>, <switch_mode>, and other tool tags in thinking blocks
- Added comprehensive tests for sanitization logic
- Fixes #9041
@roomote roomote bot requested review from cte, jr and mrubens as code owners November 5, 2025 01:17
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Nov 5, 2025
@roomote
Copy link
Author

roomote bot commented Nov 5, 2025

See this task on Roo Code Cloud

Review complete. No issues found.

Mention @roomote in a comment to trigger your PR Fixer agent and make changes to this pull request.

})

it("createMessage should not yield reasoning if content is empty after sanitization", async () => {
const onlyTags = "<appy_diff></appy_diff><switch_mode></switch_mode>"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typographical error: It appears that appy_diff is used instead of apply_diff. Please correct this to maintain consistency with other tests.

Suggested change
const onlyTags = "<appy_diff></appy_diff><switch_mode></switch_mode>"
const onlyTags = "<apply_diff></apply_diff><switch_mode></switch_mode>"

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Nov 5, 2025
@daniel-lxs
Copy link
Member

#9041 (comment)

@daniel-lxs daniel-lxs closed this Nov 5, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Nov 5, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[BUG] Thinking block renders tool calling and other tags

4 participants