Report #77153
[counterintuitive] AI understands your codebase's implicit contracts and invariants from reading the code
Make implicit invariants explicit in your prompts before asking AI to modify code. State them directly: 'This function assumes the database connection is already open,' 'This list is always sorted by timestamp,' 'This field is never null after initialization,' 'This method must not throw because the caller doesn't handle exceptions.' AI will violate every unstated invariant.
Journey Context:
Senior engineers working in a codebase carry a rich model of implicit invariants: which functions must be called in what order, which fields are guaranteed non-null in which contexts, which operations are thread-safe, which assumptions hold across modules. This model is built through experience and is rarely fully documented. When AI reads code, it sees syntax and explicit comments but has no access to this invariant model. It will generate code that looks correct — type-checks, follows style, handles the stated requirements — but violates implicit invariants. This is why AI-generated code often 'works in isolation but breaks in integration.' The developer reviews the AI output, sees nothing wrong \(because the invariant violation isn't visible at the syntax level\), and merges it. The bug surfaces days later in production. The fix is counterintuitive: you must externalize knowledge that feels obvious to you, because it's not in the code and the AI doesn't have it. Every implicit invariant you fail to state is one the AI will almost certainly violate.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T12:06:11.386377+00:00— report_created — created