Skip to content

[BUG] apply_diff fail to strip the line number at last line in SEARCH and REPLACE #8020

@liyi3c

Description

@liyi3c

Problem (one or two sentences)

When using Roo for complex requirement coding, occasionally the last line of the code editor appears with a line number.

Context (who is affected and when)

developers use roo to do coding task may has this issue.
the apply_diff example:

`<<<<<<< SEARCH
1473 | ContactRelaEnum.MS.name(), addressList, contactStatusMap, SensitiveType.ADDRESS, curSector);
1474 | }
1475 | }
1476 | List addressInfoList = new ArrayList<>(CollectionUtils.size(repairInfoList) > 10 ? 10
1477 | : CollectionUtils.size(repairInfoList) + CollectionUtils.size(homeAddressInfoList)
1478 | + CollectionUtils.size(idNoAddressInfoList) + CollectionUtils.size(workAddressInfoList)
1479 | + CollectionUtils.size(personIdentityInfoList));
=======
1473 | ContactRelaEnum.MS.name(), addressList, contactStatusMap, SensitiveType.ADDRESS, curSector);
1474 | }
1475 | }
1476 |
1477 | //
1478 | if (isAddressDisplayOptimizeEnabled()) {
1479 | homeAddressInfoList = filterAddressesByThreeYearRule(homeAddressInfoList);
1480 | personIdentityInfoList = filterAddressesByThreeYearRule(personIdentityInfoList);
1481 | idNoAddressInfoList = filterAddressesByThreeYearRule(idNoAddressInfoList);
1482 | workAddressInfoList = filterAddressesByThreeYearRule(workAddressInfoList);
1483 | }
1484 |
1485 | List addressInfoList = new ArrayList<>(CollectionUtils.size(repairInfoList) > 10 ? 10
1486 | : CollectionUtils.size(repairInfoList) + CollectionUtils.size(homeAddressInfoList)
1487 | + CollectionUtils.size(idNoAddressInfoList) + CollectionUtils.size(workAddressInfoList)
1488 | + CollectionUtils.size(personIdentityInfoList));

REPLACE`

and after stripLineNumbers, the result is
Image

we debug and found this regex in multi-search-replace.ts will remove the last \n in SEARCH and REPLACE
let matches = [ ...diffContent.matchAll( /(?:^|\n)(?<!\\)<<<<<<< SEARCH>?\s*\n((?:\:start_line:\s*(\d+)\s*\n))?((?:\:end_line:\s*(\d+)\s*\n))?((?<!\\)-------\s*\n)?([\s\S]*?)(?:\n)?(?:(?<=\n)(?<!\\)=======\s*\n)([\s\S]*?)(?:\n)?(?:(?<=\n)(?<!\\)>>>>>>> REPLACE)(?=\n|$)/g, ), ]

1488 | \t\t\t\t\t\t+ CollectionUtils.size(personIdentityInfoList));\r\n
becomes
1488 | \t\t\t\t\t\t+ CollectionUtils.size(personIdentityInfoList));\r

thus stripLineNumbers() cannot match the line number

Reproduction steps

  1. Windows, Roo 3.28.2, model is qwen3-coder-480b
  2. The input is a feature design document, but that doesn’t matter here
  3. After 20–30 LLM rounds, the accumulated multi-turn context exceeds 100K. This may cause the LLM to be unstable when using apply_diff. When Roo begins editing a Java file, there is a certain probability that the last line of the edit will appear with a line number.

Expected result

no line number

Actual result

it has line number at the last edited line

Variations tried (optional)

No response

App Version

3.28.2

API Provider (optional)

OpenAI Compatible

Model Used (optional)

qwen3-coder-480b

Roo Code Task Links (optional)

No response

Relevant logs or errors (optional)

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