Skip to content

Conversation

@daniel-lxs
Copy link
Member

@daniel-lxs daniel-lxs commented Nov 15, 2025

This PR fixes the assistant message parser initialization to only use XML parsing when the tool protocol is set to 'xml'.

Problem

When using native tool protocol, models like Claude Sonnet were sometimes getting confused and attempting to use XML-formatted tool calls instead of the native tool format. The XML parser would then parse these incorrect tool calls, which further confused the model and created a feedback loop of incorrect tool usage.

Changes

  • Modified Task.ts to conditionally initialize AssistantMessageParser based on toolProtocol setting
  • When toolProtocol is 'native', the parser is set to undefined since tool calls come as tool_call chunks, not XML
  • When toolProtocol is 'xml', the parser is initialized as before to parse XML-formatted tool calls
  • Added conditional checks and optional chaining for all parser method calls
  • Added native protocol text handling to process plain text chunks without XML parsing

Why

With native tool protocol, the model returns tool calls as structured tool_call chunks that don't require XML parsing. By disabling the XML parser for native protocol, we prevent the parser from inadvertently processing and validating malformed XML tool calls that the model might generate, eliminating the confusion feedback loop.


Important

Conditionally initialize AssistantMessageParser in Task.ts based on toolProtocol to support both XML and native protocols.

  • Behavior:
    • In Task.ts, AssistantMessageParser is conditionally initialized based on toolProtocol setting.
    • For toolProtocol set to 'native', assistantMessageParser is set to undefined.
    • For toolProtocol set to 'xml', assistantMessageParser is initialized as before.
  • Code Adjustments:
    • Use optional chaining (?.) for assistantMessageParser in reset() and finalizeContentBlocks() calls.
    • Adjust logic in recursivelyMakeClineRequests() to handle both XML and native protocols.
    • Modify presentAssistantMessage() logic to differentiate between XML and native text handling.

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

@daniel-lxs daniel-lxs requested a review from jr as a code owner November 15, 2025 00:29
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Nov 15, 2025
@roomote
Copy link
Contributor

roomote bot commented Nov 15, 2025

Rooviewer Clock   See task on Roo Cloud

Review completed. No new issues found.

The PR correctly implements conditional parser initialization and abort controller support for request cancellation. All changes follow good practices and maintain proper null-safe access patterns.

Previous reviews

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

@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Review] in Roo Code Roadmap Nov 15, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Nov 15, 2025
@daniel-lxs daniel-lxs force-pushed the disable-xml-parser-for-native-tools branch from 17b2a3b to 73d2c5c Compare November 15, 2025 00:35
Comment on lines +410 to +412
const toolProtocol = vscode.workspace.getConfiguration(Package.name).get<ToolProtocol>("toolProtocol", "xml")
this.assistantMessageParser = toolProtocol === "xml" ? new AssistantMessageParser() : undefined
Copy link
Collaborator

@mrubens mrubens Nov 15, 2025

Choose a reason for hiding this comment

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

As a follow-up I think we should probably centralize these toolProtocol checks into a single shared method that we import

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Nov 15, 2025
@hannesrudolph hannesrudolph added PR - Needs Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Nov 15, 2025
- Make assistantMessageParser optional (undefined for native protocol)
- Only initialize parser when toolProtocol is 'xml'
- Add conditional checks before calling parser methods
- Handle native protocol text chunks separately from XML parsing

This prevents unnecessary XML parsing when using native tool calls,
which come as structured tool_call chunks instead of XML text.
@daniel-lxs daniel-lxs force-pushed the disable-xml-parser-for-native-tools branch from 73d2c5c to c6d315d Compare November 15, 2025 00:52
@mrubens mrubens merged commit b2f204f into main Nov 15, 2025
9 checks passed
@mrubens mrubens deleted the disable-xml-parser-for-native-tools branch November 15, 2025 00:53
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Nov 15, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Nov 15, 2025
mini2s added a commit to zgsm-ai/costrict that referenced this pull request Nov 17, 2025