Skip to content

Bug: apply_diff errors out on large or complex XML filesΒ #4852

@hannesrudolph

Description

@hannesrudolph

App Version

3.21.3

API Provider

OpenRouter

Model Used

Anthropic Sonnet 4

πŸ” Steps to Reproduce

  1. Ensure concurrent edits are enabled in Roo Code settings
  2. Create two XML files in your workspace:
    • Create testa.xml with the following content:
      <?xml version="1.0" encoding="UTF-8"?>
      <root>
          <level1>
              <level2>
                  <level3>
                      <level4>
                          <level5>
                              <level6>
                                  <level7>
                                      <level8>
                                          <level9>
                                              <level10>
                                                  <data>
                                                      <item>Value 1</item>
                                                      <item>Value 2</item>
                                                      <item>Value 3</item>
                                                      <nested>
                                                          <subnested>
                                                              <subsubnested>
                                                                  <deep>This is deeply nested content</deep>
                                                                  <deep>More content here</deep>
                                                                  <deep>Even more content</deep>
                                                              </subsubnested>
                                                              <subsubnested>
                                                                  <deep>Another deep element</deep>
                                                                  <deep>And another one</deep>
                                                              </subsubnested>
                                                          </subnested>
                                                          <subnested>
                                                              <subsubnested>
                                                                  <deep>More deeply nested</deep>
                                                                  <deep>Content continues</deep>
                                                              </subsubnested>
                                                          </subnested>
                                                      </nested>
                                                      <item>Value 4</item>
                                                      <item>Value 5</item>
                                                      <complexPattern>
                                                          <!-- This pattern is designed to cause backtracking -->
                                                          <a><b><c><d><e><f><g><h><i><j>
                                                              <content>Complex nested structure</content>
                                                          </j></i></h></g></f></e></d></c></b></a>
                                                          <a><b><c><d><e><f><g><h><i><j>
                                                              <content>Another complex structure</content>
                                                          </j></i></h></g></f></e></d></c></b></a>
                                                      </complexPattern>
                                                  </data>
                                                  <moreData>
                                                      <repeatingPattern>Pattern A</repeatingPattern>
                                                      <repeatingPattern>Pattern A</repeatingPattern>
                                                      <repeatingPattern>Pattern A</repeatingPattern>
                                                      <repeatingPattern>Pattern B</repeatingPattern>
                                                      <repeatingPattern>Pattern B</repeatingPattern>
                                                      <repeatingPattern>Pattern B</repeatingPattern>
                                                      <ambiguousContent>
                                                          This content has multiple possible matches
                                                          and can cause the regex to try many combinations
                                                          especially when looking for specific patterns
                                                          =======
                                                          This looks like a separator but it's not
                                                          >>>>>>>
                                                          These patterns can confuse the regex
                                                          <<<<<<<
                                                          Causing it to backtrack extensively
                                                      </ambiguousContent>
                                                  </moreData>
                                              </level10>
                                          </level9>
                                      </level8>
                                  </level7>
                              </level6>
                          </level5>
                      </level4>
                  </level3>
              </level2>
          </level1>
      </root>
    • Create testb.xml with identical content to testa.xml
  3. Open Roo Code and start a new task
  4. Use the following prompt exactly:
    Please update the XML file at 'testa.xml' (see below for file content) and 'testb.xml' (see below for file content) to change all instances of "Pattern A" to "Pattern X" and all instances of "Pattern B" to "Pattern Y". Also change "Complex nested structure" to "Updated nested structure". Make all the file edits at once to multiple files at once.
    
  5. Roo will attempt to apply changes to both files simultaneously using apply_diff

πŸ’₯ Outcome Summary

Expected: The apply_diff operation completes successfully, and the changes are applied to both XML files simultaneously.
Actual: The UI displays the "Edit Unsuccessful" with the error Failed to parse apply_diff XML: Failed to parse XML: Cannot read properties of undefined (reading 'addChild') with the log file saying

<args>
<file>
  <path>testa.xml</path>
  <diff>
    <content>
<<<<<<< SEARCH
                                                    <a><b><c><d><e><f><g><h><i><j>
                                                        <content>Complex nested structure</content>
                                                    </j></i></h></g></f></e></d></c></b></a>
=======
                                                    <a><b><c><d><e><f><g><h><i><j>
                                                        <content>Updated nested structure</content>
                                                    </j></i></h></g></f></e></d></c></b></a>
>>>>>>> REPLACE
    </content>
    <start_line>40</start_line>
  </diff>
  <diff>
    <content>
<<<<<<< SEARCH
                                                <repeatingPattern>Pattern A</repeatingPattern>
                                                <repeatingPattern>Pattern A</repeatingPattern>
                                                <repeatingPattern>Pattern A</repeatingPattern>
                                                <repeatingPattern>Pattern B</repeatingPattern>
                                                <repeatingPattern>Pattern B</repeatingPattern>
                                                <repeatingPattern>Pattern B</repeatingPattern>
=======
                                                <repeatingPattern>Pattern X</repeatingPattern>
                                                <repeatingPattern>Pattern X</repeatingPattern>
                                                <repeatingPattern>Pattern X</repeatingPattern>
                                                <repeatingPattern>Pattern Y</repeatingPattern>
                                                <repeatingPattern>Pattern Y</repeatingPattern>
                                                <repeatingPattern>Pattern Y</repeatingPattern>
>>>>>>> REPLACE
    </content>
    <start_line>49</start_line>
  </diff>
</file>
<file>
  <path>testb.xml</path>
  <diff>
    <content>
<<<<<<< SEARCH
                                                    <a><b><c><d><e><f><g><h><i><j>
                                                        <content>Complex nested structure</content>
                                                    </j></i></h></g></f></e></d></c></b></a>
=======
                                                    <a><b><c><d><e><f><g><h><i><j>
                                                        <content>Updated nested structure</content>
                                                    </j></i></h></g></f></e></d></c></b></a>
>>>>>>> REPLACE
    </content>
    <start_line>40</start_line>
  </diff>
  <diff>
    <content>
<<<<<<< SEARCH
                                                <repeatingPattern>Pattern A</repeatingPattern>
                                                <repeatingPattern>Pattern A</repeatingPattern>
                                                <repeatingPattern>Pattern A</repeatingPattern>
                                                <repeatingPattern>Pattern B</repeatingPattern>
                                                <repeatingPattern>Pattern B</repeatingPattern>
                                                <repeatingPattern>Pattern B</repeatingPattern>
=======
                                                <repeatingPattern>Pattern X</repeatingPattern>
                                                <repeatingPattern>Pattern X</repeatingPattern>
                                                <repeatingPattern>Pattern X</repeatingPattern>
                                                <repeatingPattern>Pattern Y</repeatingPattern>
                                                <repeatingPattern>Pattern Y</repeatingPattern>
                                                <repeatingPattern>Pattern Y</repeatingPattern>
>>>>>>> REPLACE
    </content>
    <start_line>49</start_line>
  </diff>
</file>
</args>
</apply_diff>

[Response interrupted by a tool use result. Only one tool may be used at a time and should be placed at the end of the message.]

πŸ“„ Relevant Logs or Errors

No explicit error messages or logs are generated. The operation simply hangs.

Related Discussions

Related to #4851

Metadata

Metadata

Assignees

Labels

Issue - In ProgressSomeone is actively working on this. Should link to a PR soon.bugSomething isn't working

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions