Skip to content

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

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

fix: validate separator newline in apply_diff to catch malformed ------- markers#12212
roomote-v0[bot] wants to merge 1 commit 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
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

1 participant