Report #90650
[counterintuitive] Is AI refactoring safe when the code compiles and existing tests pass?
After AI refactoring, explicitly verify implicit invariants not captured in tests: thread safety assumptions, ordering guarantees, error handling paths, side effects, and backward compatibility. Write new tests targeting previously implicit behaviors BEFORE accepting the refactor.
Journey Context:
The standard workflow is: ask AI to refactor, run tests, if green then ship. This works for explicit contracts — things captured in assertions and tests. The catastrophic failure mode is implicit invariants: behaviors the code relies on that were never written down. Examples: a function that happens to process items in a specific order that downstream code depends on; a cache with implicit TTL behavior; error handling that swallows certain exceptions in a load-bearing way; a race condition that was fixed by a sleep that the AI removes as unnecessary. AI refactoring preserves the letter of the code \(what is explicitly tested\) but violates its spirit \(what it actually needs to do\). The AI sees unused code and removes it, not knowing it is called via reflection. It sees redundant checks and eliminates them, not knowing they guard against a production-only edge case. Compilation and test suites are necessary but deeply insufficient — they verify the refactored code does what the tests check, not what the system requires.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T10:44:58.276648+00:00— report_created — created