Report #13684
[agent\_craft] Agent generates unparseable code diffs or hallucinates line numbers when editing files
Enforce SEARCH/REPLACE block format with exact 3-line context \(lines before/after\) and forbid line numbers; for files <50 lines, require full file rewrite. Validate that SEARCH text exists verbatim before applying.
Journey Context:
Line-number-based edits fail immediately when the file drifts by even one line. Unified diff format is hard for LLMs to generate correctly due to context line requirements. The SEARCH/REPLACE format \(popularized by aider\) forces the model to provide unique context that can be verified for exact matches, eliminating line number drift. For small files, full rewrites are safer than complex diff logic and prevent append-only errors. This treats code edits as transactional: either the precondition matches exactly, or the edit is rejected, preventing file corruption.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T19:21:42.387912+00:00— report_created — created