Skip to content

Conversation

@daniel-lxs
Copy link
Member

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

Problem

When resuming tasks with native protocol, tool_use and tool_result blocks were being converted to text format:

Called read_file with files: [{"path":"config.json"}]

This confused the model, making it think that's how to call tools instead of using the proper OpenAI tool calling format.

Root Cause

The tool-to-text conversion logic added in v2.0 (commit 1d912bd) for XML protocol was running for all protocols. It should only run for XML protocol where tools are text-based, not for native protocol where tools use structured API calls.

Solution

Gate the conversion logic to only run for XML protocol (lines 1433-1465 in Task.ts). Native protocol now preserves tool_use/tool_result blocks, which convertToOpenAiMessages properly transforms to:

{
  "role": "assistant",
  "tool_calls": [{"id": "call_123", "type": "function", ...}]
},
{
  "role": "tool",
  "tool_call_id": "call_123",
  "content": "..."
}

This matches the OpenAI API format documented in tool_calling.md.

Testing

  • Added 8 new tests verifying both protocols work correctly
  • All 4,173 tests pass (319 test files)
  • XML protocol behavior confirmed unchanged via regression tests

Backward Compatibility

Protocol is determined at resume time based on current settings. Old tasks with tool blocks are handled correctly:

  • Resume with XML: blocks converted to text (unchanged behavior)
  • Resume with native: blocks preserved and properly converted to OpenAI format

Important

Fixes tool block conversion logic to preserve tool blocks for native protocol, ensuring correct transformation and backward compatibility.

  • Behavior:
    • Fixes tool block conversion logic in Task.ts to only apply to XML protocol, preserving tool blocks for native protocol.
    • Ensures convertToOpenAiMessages correctly transforms tool blocks for native protocol.
  • Testing:
    • Adds task-tool-history.spec.ts with 8 new tests for both XML and native protocols.
    • Confirms unchanged XML protocol behavior with task-xml-protocol-regression.spec.ts.
    • All 4,173 tests pass across 319 test files.
  • Backward Compatibility:
    • Protocol determined at resume time; old tasks handled correctly for both protocols.

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

Problem: When resuming tasks with native protocol, tool_use and tool_result
blocks were being converted to text format (e.g., 'Called read_file with...'),
which confused the model and prevented proper OpenAI tool calling format.

Root Cause: The tool-to-text conversion logic added in v2.0 for XML protocol
was running for all protocols, including native protocol where it shouldn't apply.

Solution: Gate the conversion logic to only run for XML protocol. Native protocol
now preserves tool_use/tool_result blocks, which are properly converted to OpenAI
format (tool_calls/tool role) by convertToOpenAiMessages.

Testing: Added 8 new tests verifying both protocols work correctly. All 58 existing
tests pass, confirming XML protocol behavior is unchanged.
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Nov 17, 2025
@roomote
Copy link
Contributor

roomote bot commented Nov 17, 2025

Rooviewer Clock   See task on Roo Cloud

Review completed. No issues found.

The implementation correctly gates tool block conversion to only run for XML protocol, preserving tool_use and tool_result blocks for native protocol as intended. The fix is well-tested with comprehensive test coverage for both protocols.

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 17, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Review] in Roo Code Roadmap Nov 17, 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 17, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Nov 17, 2025
@mrubens mrubens merged commit fc19e76 into main Nov 17, 2025
24 checks passed
@mrubens mrubens deleted the fix/native-protocol-tool-history branch November 17, 2025 19:07
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Nov 17, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Nov 17, 2025
mini2s added a commit to zgsm-ai/costrict that referenced this pull request Nov 18, 2025