Where an AI coding tool was wrong, and how I caught it
A concrete case study showing subtle bugs introduced by AI code generators in boundary conditions, and the property-based tests that exposed them.
Contents
4 sectionsThe Setup
While working on phoneme candidate ranking in lekhani-ai, I asked an AI model to optimize the scoring loop for n-gram frequency lookups across transliterated strings with complex conjuncts.
The initial code looked convincing:
| 1 | // AI drafted ranking fallback |
| 2 | - let best = candidates.first(); |
| 3 | + let best = rank(&candidates, &context); // illustrative diff |
What It Produced
On standard ASCII input, the function returned 0 errors. But when tested against Unicode character sequences containing zero-width joiners (U+200D ZWJ) and vowel diacritics, the heuristic completely scrambled the syllable cluster boundaries.
How I Caught It
I run proptest property tests against a corpus of 100,000 real Bengali editorial sentences. The property test asserted that:
The test instantly panicked on words like "স্মৃতি" (smriti) and "বিজ্ঞান" (bijnan).
WHAT I CHECKED: Never trust an AI model with grapheme cluster segmentation without an invariant property test verifying Unicode normal forms (NFC/NFD) across dialectal edges.
What I Would Do Differently
Write the acceptance criteria and test corpus before asking the model for any code.

Discussion & Peer Review
Questions, empirical pushbacks, and architecture discussions.
No published discussion threads yet.
Be the first to challenge a premise or start an inquiry.