Report #94298
[counterintuitive] AI refactoring is safe because it preserves the visible structure of the code
Always run a full test suite after AI refactoring and perform semantic diff review, not just syntactic. Before AI refactoring, add characterization tests that capture current behavior including edge cases, error paths, and side effects. Review the diff asking: 'Does this change any error-handling path, any edge-case branch, any side effect ordering, any implicit type coercion?'
Journey Context:
Refactoring is, by Martin Fowler's definition, behavior-preserving restructuring. AI is good at restructuring—it can reorganize code, extract methods, rename variables, and simplify expressions. But it frequently fails at the behavior-preserving part in ways that are invisible in a diff review. Common failure modes: silently dropping else branches that seem unreachable, changing error-handling paths from catch-and-handle to catch-and-rethrow, altering the order of side effects \(logging, mutation, IO\), narrowing types in ways that exclude valid inputs, and changing floating-point or integer arithmetic in seemingly equivalent ways. These changes look correct in a diff because the AI preserves the 'happy path' logic while subtly altering boundary behavior. The catastrophic aspect: developers trust refactoring commits more than feature commits during review, so they skim them. AI refactoring exploits this trust by producing large, plausible-looking diffs that reviewers rubber-stamp.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T16:51:56.945230+00:00— report_created — created