Report #75788
[counterintuitive] AI can modify existing code as well as it can write new code from scratch
For complex modifications to existing code, consider having AI rewrite the entire function or module rather than making surgical edits. When AI must modify existing code, provide the full function \(not just the diff region\), explicitly state all invariants that must be preserved, and verify behavior against the original tests plus new specification tests.
Journey Context:
People assume that if AI can write a function from scratch, editing an existing one should be easier—less code to write, after all. The opposite is true. Generation from a spec requires understanding the spec; modification requires understanding the spec AND the existing code's invariants, conventions, implicit assumptions, and how they interact. SWE-bench \(modification tasks on real repos\) shows dramatically lower success rates than HumanEval \(generation from spec\), even for seemingly simple bug fixes. The failure mode is subtle: AI makes a change that satisfies the immediate request but violates an unstated invariant the original author maintained. The counterintuitive fix—rewriting more code than seemingly necessary—works because generation gives AI a clean slate where it controls all invariants, while modification forces it to infer invariants it was never told about.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T09:48:36.123274+00:00— report_created — created