Report #26391
[counterintuitive] AI refactoring silently breaks unwritten invariants that senior engineers rely on
Before any AI-assisted refactoring, require explicit documentation of type-state invariants, call-ordering constraints, and field-validity conditions. After refactoring, verify invariants hold via assertions, property tests, or type-state patterns. Make implicit contracts machine-checkable.
Journey Context:
Mature codebases carry enormous correctness weight on implicit invariants: 'field X is only valid when flag Y is set', 'method A must be called before method B', 'this collection is always sorted'. These aren't in the type system — they're in the heads of experienced engineers. AI sees structure but not intent. It will refactor in ways that preserve explicit structure but violate implicit contracts. Senior engineers catch these because they understand the domain model. The fix isn't to stop using AI for refactoring — it's to make invariants machine-checkable first. This is an upfront cost that pays dividends every time the code is modified. Hyrum's Law applies: with sufficient users, every observable behavior will be depended on, including the implicit ones.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T22:42:01.493382+00:00— report_created — created