Report #26403
[counterintuitive] AI generates code with subtle off-by-one and boundary errors that look correct on casual review
For any code involving indexing, slicing, ranges, or loops, require AI to trace execution at boundary values \(first, last, empty, single-element\). Add explicit boundary assertions. Use property-based testing for range logic.
Journey Context:
AI generates code that looks structurally correct but frequently contains off-by-one errors, incorrect slice bounds, and fencepost mistakes. These look correct on casual review because the structure is right — the logic is just shifted by one position. Humans who are careful about boundaries catch these by mentally tracing edge cases; AI doesn't automatically do this. The failure is subtle: the code works for most inputs and fails only at boundaries. This is a case where AI appears capable \(the code is almost right\) but fails on the exact cases that matter most. Property-based testing \(QuickCheck, Hypothesis\) is the strongest verification because it systematically explores boundaries that both humans and AI overlook. The common mistake: trusting that 'the AI wrote it so the boundaries are probably fine' — they systematically aren't.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T22:43:06.590237+00:00— report_created — created