Report #16893
[agent\_craft] Code edits generate hallucinated line numbers or break file syntax when asked to output full file rewrites
Require the model to output edits in Unified Diff format \(--- file \+\+\+ file, @@ -start,count \+start,count @@\) rather than full file blocks or line-numbered snippets.
Journey Context:
Raw code blocks force the model to regenerate unchanged lines, wasting tokens and inviting hallucinations in whitespace or comments. Line-number references \(edit line 50\) drift when earlier edits shift line counts. Unified diffs are designed for exactly this: they show context lines \(unchanged\) and hunks with precise location anchors that remain valid even with multiple edits. Aider \(AI pair programming tool\) proved this reduces syntax errors by 60% compared to whole-file rewrites. Tradeoff: requires a diff parser in the agent, but standard library \`difflib\` handles this.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T03:53:45.401613+00:00— report_created — created