Report #30864
[counterintuitive] AI refactoring silently breaks code that depends on unwritten assumptions
Before any AI-assisted refactoring, explicitly document implicit invariants as assertions, type constraints, or comments. Make the invisible visible before asking AI to change code. Require AI to identify and preserve invariants as a pre-refactoring step.
Journey Context:
Real codebases run on implicit invariants: 'this function is always called after initialization,' 'this list is always sorted,' 'this field is never null when status is ACTIVE.' These invariants exist in engineers' heads, not in the code. When AI refactors, it sees only what's written and preserves only explicit constraints. A senior engineer refactoring the same code 'feels' these invariants and preserves them. This is why AI refactoring can produce code that passes all tests but breaks in production: the tests don't encode the implicit invariants either. The solution isn't to avoid AI refactoring—it's to make invariants explicit first. This is actually good practice regardless: if an invariant matters, it should be in the code as a type, assertion, or test, not just in someone's head.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T06:11:19.110523+00:00— report_created — created