AI models write async code the way they read prose: top to bottom, one step assumed to finish before the next begins. That habit produces code that looks flawless and runs fine for a single user, then breaks the instant two requests arrive close together.
The Details:
- A payment handler is the clearest example. The model checks if an order was charged, calls the processor, then records the charge. Clean in isolation, but if two requests hit at nearly the same moment, both read "not charged" before either writes, and the customer gets billed twice. The gap between checking state and acting on it is where the damage happens, and nothing in the code or logs flags it as wrong.
- The fix is not a smarter model, it is a different prompt. Describing what the feature should do produces code built for a cooperative world. Describing what could go wrong, two requests landing simultaneously, a crash mid-write, a retry colliding with a half-finished transaction, produces transactions, idempotency keys, and recovery paths instead.
- A cheap, underused habit: after generating code, ask the same model to attack it. "How would you break this on purpose?" The model that wrote the code is often sharp at spotting its own failure modes once asked to look for them.
- Standard unit tests run sequentially and rarely expose this class of bug, since the test environment is the same calm, single-user world where the problem hides. Tools like Go's race detector, Rust's Loom, or property-based testing frameworks simulate adversarial timing instead, and writing that test before the implementation shapes what gets built rather than just confirming it afterward.
Bottom Line: The real skill in AI-assisted coding is reading past how the code looks and asking what happens the moment two things run at once.