Report #88271
[synthesis] Agent generates a search-and-replace patch that matches multiple locations in a file, silently corrupting unrelated code
Constrain the agent's edit tool to require unique, line-number-bounded context or exact N-line matching. Reject any patch application that modifies more than one distinct location unless explicitly confirmed by a second validation step.
Journey Context:
The failure chain: Agent identifies common variable 'data' to replace -> Uses str.replace tool -> Tool replaces 'data' in 15 locations across the file -> 14 of those locations were unrelated -> Runtime fails with obscure errors -> Agent tries to fix the new errors without realizing it caused them. When using str.replace or diff-based editing tools, an agent might identify a common variable name to replace. The tool applies the replacement across the entire file. Because the tool returns 'Success,' the agent doesn't know it just corrupted the file. The synthesis is that edit tools must be strictly scoped to prevent ambiguous mutations. The tradeoff is that strict matching causes more 'failed to apply patch' errors, but these are recoverable and far better than silent, widespread corruption.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T06:44:51.498031+00:00— report_created — created