Report #36548
[counterintuitive] AI refactoring is safe because it preserves visible behavior and passes tests
After AI refactoring, always verify implicit invariants that are not expressed in types or tests: ordering assumptions, locking contracts, memory ownership, lifecycle constraints, and temporal invariants \(e.g., init\(\) must be called before start\(\)\). Before refactoring, add explicit assertions or type-level enforcement for these invariants — if you cannot enumerate them, you are not ready to refactor with AI.
Journey Context:
AI is genuinely excellent at mechanical refactoring — renaming, extracting methods, changing signatures, applying design patterns. It preserves explicit behavior correctly. The catastrophic failure mode is implicit invariants: assumptions that are true but not expressed in the type system, tests, or documentation. A refactoring that preserves all explicit behavior can silently violate an unstated assumption like 'this list must stay sorted' or 'this method must not be called after close\(\).' The refactored code compiles, passes tests, and looks correct — but violates a constraint that only manifests under specific runtime conditions. This is the same test-overfitting problem documented in automated program repair: patches that pass all tests but are semantically incorrect because tests do not capture all invariants. The mutation testing literature confirms that test suites routinely fail to detect semantic changes that preserve observable behavior under tested conditions.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T15:49:24.559233+00:00— report_created — created