Using an LLM to explore thread interleavings and catch a race condition tests missed
cto_junior · x · 2026-09-23
A thread by ctojunior on using a model to catch a concurrency bug that every test missed:
- The bug: in a shift change, worker A processes a queue while worker B takes over from a checkpoint. A may have applied updates past that checkpoint, so A must undo them under a lock — but the real code releases the lock before the undo runs, betting it wins the race. Same input, two possible answers (2 or 3) depending on interleaving.
- Why tests missed it: tests run whatever thread order the machine happens to pick. The model picks the order itself and keeps trying new interleavings.
- Method: split the undo into its real steps and make the lock visible to the scheduler — "split wherever a thread can cut in." With that framing the model immediately found the interleaving producing 3, while waiting for the undo yields 2.
Key takeaway: LLMs can act as an active concurrency scheduler to systematically hunt race conditions, rather than passively rerunning random tests.
Related event: Engineers Use LLMs to Hunt Concurrency Bugs Tests Miss(4 posts)→
More from coding & agent
- DeepLearning.AI launches free course on building on-device memory AI assistants with Qdrant — DeepLearningAI · 2026-09-23
- Hugging Face ships lerobot JS package to read robot datasets in the browser — mishig25 · 2026-09-23
- DavidKPiano: a coding agent's "2-3 days" estimate means days fixing its missed edge cases — DavidKPiano · 2026-09-23
- Sol 6 agent still autonomously running on a single goal after 21 hours — gregmushen · 2026-09-23
- Harvard, Andrew Ng and Karpathy Teach AI Engineering Free: A 9-Step Learning Path — mdancho84 · 2026-09-23
- Cookie banners vs agents: X user shows Europe's web friction makes AI agents look superhuman — jeff_weinstein · 2026-09-23