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.
Sleeps, retries and longer timeouts as 'fixes'
card 4 of 6
A retry hiding a missing wait (Java)
builds on: Patching the symptom instead of the cause, Race conditions and interleavings
The agent reports: *"Upload-then-fetch was flaky (404). Added 3 retries, 1 s apart, to the fetch endpoint. Tests green."* The upload handler hands the write to an `ExecutorService` and responds before the write runs.
Tell: a retry around a failure whose cause is your own ordering. Later cost: when the executor's queue backs up past 3 s, users get 404s again, and each retry adds load. Real fix: wait on the write's `Future` before responding.
Terms on this card
- flaky
- A test that sometimes passes and sometimes fails on the same code, usually because of timing or shared state.
- tell
- An observable sign in a diff, transcript or summary that suggests a shortcut or an error.
- later cost
- The concrete damage a shortcut does after merge, such as a hidden bug or a maintenance burden.
- 404
- The HTTP status code meaning 'Not Found': the requested resource does not exist (yet).
- Future
- A handle to work running elsewhere; waiting on it (e.g. Java's `future.get()`) blocks until that work finishes.
Lesson goal: Recognise a race 'fixed' with a sleep, a flaky call wrapped in a retry loop, or a raised timeout. Explain why these pass locally and in CI but fail under load or on slower machines, and what a real ordering fix looks like. ·
the whole lesson