Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Sep 23, 2025

Description

This PR fixes issue #8242 where the ask_followup_question tool (and other tools) were incorrectly triggered when displaying code snippets containing tool XML tags.

Problem

When an assistant in Ask mode was asked to describe tool usage and displayed example XML tags in code blocks, the parsing logic incorrectly interpreted these as actual tool invocations rather than code examples.

Solution

Added code block detection to all three message parsing implementations:

  • parseAssistantMessage.ts
  • parseAssistantMessageV2.ts
  • AssistantMessageParser.ts

The parsers now:

  1. Track backtick counts to detect code blocks (```) and inline code (`)
  2. Maintain state variables (inCodeBlock, inInlineCode) during parsing
  3. Skip tool tag processing when inside code blocks
  4. Continue accumulating text content normally within code blocks

Testing

  • Added 6 comprehensive test cases covering various code block scenarios
  • All existing tests continue to pass (73 total tests passing)
  • Tests specifically verify the exact issue scenario reported

Changes

  • Added code block detection logic to message parsers
  • Added comprehensive test coverage for code block handling
  • No breaking changes to existing functionality

Fixes #8242


Important

Fixes issue #8242 by updating message parsers to prevent tool parsing within code blocks and inline code, with comprehensive tests added.

  • Behavior:
  • Testing:
    • Adds 6 test cases in parseAssistantMessage.spec.ts to cover various code block scenarios.
    • Ensures all 73 existing tests pass, verifying the exact issue scenario reported.
  • Changes:
    • Adds code block detection logic to message parsers.
    • No breaking changes to existing functionality.

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

- Added code block detection to parseAssistantMessage.ts
- Added code block detection to parseAssistantMessageV2.ts
- Added code block detection to AssistantMessageParser.ts
- Added comprehensive tests for code block scenarios
- Fixes issue where tool XML tags in code examples were incorrectly parsed as actual tool invocations

Fixes #8242
@roomote roomote bot requested review from cte, jr and mrubens as code owners September 23, 2025 01:37
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Sep 23, 2025
} else {
// If we had one backtick and now a different char, toggle inline code
if (this.codeBlockDelimiterCount === 1 && !this.inCodeBlock) {
this.inInlineCode = !this.inInlineCode
Copy link
Contributor

Choose a reason for hiding this comment

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

The inline/code block tracking logic is duplicated here. The heuristic toggles inline code on the first non-backtick after a single backtick, which works in the tests but may be fragile in edge cases. Consider explicitly matching a closing backtick and extracting this logic to a shared utility to reduce duplication across parsers.

This comment was generated because it violated a code review rule: irule_tTqpIuNs8DV0QFGj.

let inCodeBlock = false
let inInlineCode = false
let codeBlockDelimiterCount = 0
let lastTwoChars = ""
Copy link
Contributor

Choose a reason for hiding this comment

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

The variable 'lastTwoChars' is computed but never used. Please remove it to keep the code clean.

Copy link
Contributor Author

@roomote roomote bot left a comment

Choose a reason for hiding this comment

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

Reviewing my own code is like proofreading my own typos - I'll probably miss something obvious.

let inCodeBlock = false
let inInlineCode = false
let codeBlockDelimiterCount = 0
let lastTwoChars = ""
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The lastTwoChars variable is declared on line 19 but never used in the implementation. This appears to be leftover from a different approach and should be removed to avoid confusion.

} else {
// Check for inline code (single backtick)
if (codeBlockDelimiterCount === 1 && !inCodeBlock) {
inInlineCode = !inInlineCode
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consider not toggling inInlineCode when already inside a code block. While the current logic works because inCodeBlock takes precedence, the inInlineCode state could become incorrect:

Suggested change
inInlineCode = !inInlineCode
// Check for inline code (single backtick)
if (codeBlockDelimiterCount === 1 && !inCodeBlock) {
inInlineCode = !inInlineCode
}

} else {
// If we had one backtick and now a different char, toggle inline code
if (this.codeBlockDelimiterCount === 1 && !this.inCodeBlock) {
this.inInlineCode = !this.inInlineCode
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same issue here - consider not toggling inInlineCode when already in a code block:

Suggested change
this.inInlineCode = !this.inInlineCode
// If we had one backtick and now a different char, toggle inline code
if (this.codeBlockDelimiterCount === 1 && !this.inCodeBlock) {
this.inInlineCode = !this.inInlineCode
}

} else {
// If we had one backtick and now a different char, toggle inline code
if (backtickCount === 1 && !inCodeBlock) {
inInlineCode = !inInlineCode
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same pattern here - only toggle inline code when not in a code block:

Suggested change
inInlineCode = !inInlineCode
// If we had one backtick and now a different char, toggle inline code
if (backtickCount === 1 && !inCodeBlock) {
inInlineCode = !inInlineCode
}

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Sep 23, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Sep 23, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Sep 23, 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

Archived in project

Development

Successfully merging this pull request may close these issues.

[BUG] Roo presents the ask_followup_question choice boxes if you ask it to describe how the function works

3 participants