跪拜 Guibai
← All articles
Frontend

A One-Sentence Bug Took 12 Rounds to Find Because AI Won't Tell You to Add Logs

By mmsx ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

AI coding assistants amplify confirmation bias: they elaborate whatever assumption you feed them instead of questioning it. Combined with the low cost of generating new code, this pushes developers toward “blind fixing” and away from the instrumentation discipline that finds real root causes, especially for device‑specific behavior that no model has in its training data.

Summary

On a rugged Android handheld, pressing any letter key inside a numeric field deleted one digit instead of being ignored. The root cause was a device‑specific physical‑keyboard IME that emits a real DEL key event before every letter key, effectively backspacing on each press. The fix uses a 300 ms time‑window: snapshot the text on DEL, and if a letter key arrives within the window, undo the deletion.

The real story is the debugging process. The first eight rounds chased a phantom “select‑all residue” theory because the developer fed that assumption to the AI assistant, which dutifully elaborated it instead of challenging it. Only after instrumenting every event entry point with logcat did the triple‑event pattern become visible. The author argues that AI‑assisted coding lowers the cost of making changes so much that it tempts developers to keep guessing instead of stopping to instrument, turning a 20‑minute fix into a day‑long ordeal.

The post distills five rules for AI‑assisted troubleshooting: instrument after two consecutive failed fixes, return to the original requirement rather than an imagined root cause, remember that `return false` does not consume an Android key event, accept that device‑specific IME behavior cannot be reasoned about, and expect symptoms to shift as each layer of interception is added.

Takeaways
On the affected handheld, the physical‑keyboard IME emits DEL (keyCode 67) + SHIFT (keyCode 59) + the letter key for every single letter press, and the DEL actually deletes a character.
The fix snapshots the text on DEL, then undoes the deletion if a letter key arrives within 300 ms; genuine user backspaces exceed that window.
Eight of the twelve debugging rounds were wasted on a wrong hypothesis (select‑all residue) that the AI assistant reinforced rather than corrected.
In Android key dispatch, `return false` passes the event downstream so the TextView still inserts text; only `return true` consumes the event.
Logcat instrumentation added at round five immediately revealed the DEL‑SHIFT‑letter triple‑event pattern that reasoning and documentation could not predict.
Stop and add logs after two consecutive failed fixes; each compile‑deploy‑test cycle on the handheld took 10–20 minutes, so guessing cost most of a day.
Conclusions

AI coding assistants are compliance engines, not skeptics — they will build an elaborate justification for whatever hypothesis you put in the prompt, making wrong paths feel more credible.

The lower the cost of generating a code change, the stronger the temptation to try “one more version” instead of instrumenting, which inverts the discipline that debugging actually requires.

Device‑specific IME behavior is a class of bug that is invisible to documentation, Stack Overflow, and LLM training data; the only reliable detection method is raw event logging.

Android’s key‑event return‑value semantics (`false` means “don’t consume”) are a persistent footgun because they read opposite to how many developers intuitively interpret a boolean return.

Symptoms shift as interception layers are added, so a bug that appears to change form across rounds is often a single root cause being partially masked — not multiple separate issues.

Concepts & terms
logcat
Android’s system-wide logging utility that captures real-time diagnostic output from apps and the OS, accessible via ADB. Essential for observing raw key events and IME behavior that documentation doesn’t describe.
IME (Input Method Editor)
The software component on Android that interprets hardware key presses or on-screen input and delivers text or key events to applications. Non‑standard IMEs on specialized devices can emit unexpected key sequences.
Android key event dispatch (dispatchKeyEvent / onKeyDown)
The chain through which hardware key presses travel in Android. Returning `true` from a handler consumes the event and stops propagation; returning `false` allows it to continue to the next receiver, such as a TextView inserting the character.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗