Skip to content

edit tool can catastrophically delete content when oldString match is overly broad #24959

Description

@Yassire1

Description

Summary
The edit tool silently deleted approximately 50% of a LaTeX document (~190 lines) when attempting a simple string replacement. The oldString parameter matched a much larger block than intended, replacing it with a 10-character snippet and destroying everything in between.
What happened
I was making a targeted spacing adjustment to a .tex file. I issued an edit command with an oldString intended to match a single figure/table boundary (e.g., \end{figure} followed by a section header). Instead, the tool matched a spanning boundary that started at the end of Table 1 and ended somewhere before the Conclusion section. The replacement deleted:

  • Table 1 content and caption
  • All Taxonomy subsections (3.1–3.6)
  • Section 4 (Training and Adaptation) + Table 2
  • Section 5 (Applications to PdM) + Table 3
  • Section 6 (Challenges and Future Directions)
    File dropped from 453 lines → 266 lines without any warning.
    Root cause
    The edit tool performs exact string replacement using the first match found. When the oldString is constructed from multi-line context, it can accidentally match a boundary that spans much more content than the user intended. There is:
  • No preview/diff before applying
  • No "match too large" safeguard
  • No confirmation prompt for multi-line replacements exceeding a threshold

Plugins

No response

OpenCode version

1.3.17

Steps to reproduce

  1. Open any multi-section .tex or .md file with repeating patterns (e.g., multiple \end{table} blocks)
  2. Issue an edit with an oldString that includes context lines before and after a target
  3. If that context happens to appear earlier in the file with a wider span, the tool replaces the first and largest match
  4. Result: everything between the matched start and end is deleted

Screenshot and/or share link

No response

Operating System

Windows 11

Terminal

WSL

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions