Skip to content

fix: validate separator newline in apply_diff to catch malformed ------- markers#12212

Draft
roomote-v0[bot] wants to merge 2 commits intomainfrom
fix/validate-separator-newline
Draft

fix: validate separator newline in apply_diff to catch malformed ------- markers#12212
roomote-v0[bot] wants to merge 2 commits intomainfrom
fix/validate-separator-newline

Conversation

@roomote-v0
Copy link
Copy Markdown
Contributor

@roomote-v0 roomote-v0 Bot commented Apr 28, 2026

Related GitHub Issue

Closes: #12210

Description

This PR attempts to address Issue #12210. Feedback and guidance are welcome.

When the LLM omits the newline after the ------- separator (e.g. -------import { useTranslate }), the parser silently absorbs the separator into the search content, producing a confusing "No sufficiently similar match found" error. This causes smaller models like Qwen 3.6 to loop without recovering.

Implementation: Added detection in validateMarkerSequencing (in src/core/diff/strategies/multi-search-replace.ts) for lines starting with ------- that have non-whitespace content appended. When detected, a clear, actionable error message is returned telling the model to place the separator on its own line with search content starting on the next line.

Test Procedure

  • Added 3 new tests in src/core/diff/strategies/__tests__/multi-search-replace.spec.ts:
    1. Detects malformed separator with content on the same line (the exact scenario from the issue with :start_line: present)
    2. Detects malformed separator without :start_line:
    3. Confirms properly formatted separator on its own line still works correctly
  • All 61 tests pass: cd src && npx vitest run core/diff/strategies/__tests__/multi-search-replace.spec.ts

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue.
  • Scope: Changes are focused on the linked issue.
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New tests have been added to cover the changes.
  • Documentation Impact: No documentation updates required.
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Documentation Updates

  • No documentation updates are required.

Additional Notes

The fix is minimal and targeted -- it only adds a check in the existing AFTER_SEARCH state of the marker validation state machine. The regex /^-------\S/ catches lines where ------- is immediately followed by a non-whitespace character (i.e. missing newline). The error message includes the trailing content to help the model understand what went wrong.

Interactively review PR in Roo Code Cloud

…--- markers

When the LLM omits the newline after the ------- separator (e.g. "-------import"),
the parser silently absorbs the separator into the search content, producing a
confusing "No sufficiently similar match found" error. This causes smaller models
to loop without recovering.

Add detection in validateMarkerSequencing for lines starting with "-------" that
have non-whitespace content appended, returning a clear actionable error message
that tells the model to place the separator on its own line.

Closes #12210
@rkfg
Copy link
Copy Markdown

rkfg commented May 4, 2026

@roomote found another failure case: "diff": "<<<<<<< SEARCH\n:start_line:70\n-------\tapi.POST( Here the fix doesn't work because the regexp assumes \S (non-space characters) after the separator at the same line. In fact there could be spaces, tabs, and other characters. I think any characters after the separator except \n should be considered an error.

@roomote-v0
Copy link
Copy Markdown
Contributor Author

roomote-v0 Bot commented May 4, 2026

Fixaroo Clock   See task

Fixed the regex from /^-------\S/ to /^-------.+/ so whitespace characters (tabs, spaces) after the ------- separator are also detected as malformed. Added a test for the tab-prefixed content case. All 62 tests pass, lint and type checks clean.

View commit | Revert commit

Change regex from /^-------\S/ to /^-------.+/ so that cases like
"-------\tapi.POST(" where whitespace follows the separator are also
detected as malformed. Add test for tab-prefixed content case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Separator after :start_line: in apply_diff is not validated

2 participants