Report #85231
[counterintuitive] AI-assisted refactoring is safe because refactoring preserves behavior by definition
After any AI-assisted refactoring, run the full test suite AND manually verify error handling paths, side effects, evaluation order, and edge case behavior. Treat AI refactoring as a semantic transformation requiring verification, not a guaranteed behavior-preserving transformation.
Journey Context:
The belief is that refactoring—by definition—preserves external behavior, so AI refactoring should be safe. But AI doesn't truly understand 'behavior preservation' as a constraint. It understands pattern transformation. When AI refactors code, it can subtly change error handling \(swallowing exceptions that were previously propagated\), alter evaluation order \(changing side effect timing\), or modify edge case behavior \(different handling of null/empty/zero cases\). These changes pass tests because tests rarely cover error paths and edge cases thoroughly. The result is a refactoring that looks clean but introduces latent bugs that surface in production. Martin Fowler's refactoring catalog explicitly defines each transformation's behavior-preservation preconditions—AI doesn't check these preconditions before applying transformations. The gap between 'syntactically equivalent' and 'semantically equivalent' is where AI refactoring introduces bugs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T01:38:52.839807+00:00— report_created — created