Work effectively with AI coding agents. Understand them as language models running in a tool loop with limited context, which is why they guess, game the visible signal and report confidently. Recognise the shortcut and correctness tells in their code across Python, TypeScript/JavaScript, Rust, Java and Go, and know the damage each one does later. Verify changes instead of trusting them, review diffs fast for quality and security, judge when work is truly finished, and choose, design and steer tasks so agents can finish them well.
Races introduced by plausible concurrent code
card 1 of 6
Parallel, green, and reads cleanly
builds on: Race conditions and interleavings
You asked the agent to speed up a slow report. It wrapped the loop body in goroutines, added a `sync.WaitGroup`, and reported: "Now 4x faster, all tests green." The diff is short and reads cleanly.
The same shape appears elsewhere: a lazily created singleton in Java, a 'get or compute' cache, an async handler that loads a record, changes it and saves it. Each one looks correct line by line.
Before you merge, what do you look for, and which check would actually catch the problem?
Terms on this card
- sync.WaitGroup
- A Go counter used to wait until a group of goroutines has finished. It only waits; it does not protect shared data.
- singleton
- A class meant to have exactly one shared instance in the program.
- the agent
- The AI coding system doing the work: a chat assistant, IDE agent or terminal agent.
- diff
- The set of line changes between two versions of the code: removed lines start with '-', added lines with '+'.
- green
- A test or check that passes.
Lesson goal: Recognise races that look fine on the page: a Go map written from goroutines, unsynchronized lazy initialisation in Java, check-then-act on a cache, and async read-modify-write in JS. Name which tool or synchronization would catch or fix each one. ·
the whole lesson