Skip to content

Conversation

@daniel-lxs
Copy link
Member

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

Description

Fixes a bug where XML tool parsing would occur even when Native Tool Calling (NTC) was enabled, causing confusion for the model.

The Problem

The issue occurred because the code only checked for the existence of this.assistantMessageParser to decide whether to parse XML content. However, the parser might exist due to:

  1. Race conditions
  2. Incomplete cleanup from previous tasks
  3. Configuration switches mid-session

When a model (confused or otherwise) output XML-like text while in native mode, the presence of the parser would trigger XML parsing, even though the protocol was strictly native. This would cause the model to see parsed XML tools and continue using XML format instead of native tool calls.

The Fix

This PR introduces a robust check that verifies the current protocol before attempting any XML parsing:

  1. Calculates shouldUseXmlParser once at the start of the API request loop (efficient)
  2. Uses this flag in the streaming loop to guard XML parsing
  3. Uses this flag in the finalization step

This ensures that even if the parser object exists in memory, it will NEVER be used if the current protocol is native.

Testing

  • Verified with existing tests
  • Added specific test case to cover the edge case where parser exists but protocol is native (verified locally then removed)
  • All tests passed

Important

Fixes bug in Task.ts to prevent XML parsing when protocol is native by checking protocol before parsing.

  • Behavior:
    • Fixes bug in Task.ts where XML parsing occurred even when protocol was native.
    • Introduces shouldUseXmlParser flag to check protocol before parsing XML.
    • Ensures XML parsing only when protocol is XML, preventing incorrect parsing in native mode.
  • Implementation:
    • Calculates shouldUseXmlParser at start of API request loop.
    • Uses shouldUseXmlParser in streaming loop and finalization step to guard XML parsing.
  • Testing:
    • Verified with existing tests.
    • Added and removed specific test case for edge case where parser exists but protocol is native.

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

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Nov 18, 2025
@roomote
Copy link
Contributor

roomote bot commented Nov 18, 2025

Rooviewer Clock   See task on Roo Cloud

All previously flagged issues have been resolved. The redundant non-null assertions have been successfully removed.

  • Remove redundant non-null assertion in streaming loop (line 2231)
  • Remove redundant non-null assertions in finalization block (lines 2556-2557)
Previous reviews

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

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Nov 18, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Nov 18, 2025
@mrubens mrubens merged commit 0d72471 into main Nov 18, 2025
13 checks passed
@mrubens mrubens deleted the fix/native-protocol-parser-bug branch November 18, 2025 23:30
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Nov 18, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Nov 18, 2025
mini2s added a commit to zgsm-ai/costrict that referenced this pull request Nov 19, 2025