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.
Catch plausible-but-wrong code
card 4 of 6
Two traps behind one green summary
builds on: Happy-path code: the edge cases it skipped, Text, time and money: classic data traps, Fine on test data, broken at scale, Unawaited async work and floating promises, Leaked resources: files, connections, goroutines, Races introduced by plausible concurrent code, Retrying operations that aren't idempotent, Half-finished changes: the call sites it missed, Refactors that quietly change behavior, Invented APIs, flags, config keys and packages
Summary: *'Renamed `getUser` to `fetchUser` everywhere and simplified `syncAll`; build and tests green.'*
Trap 1: `syncAll` now calls `users.forEach(async u => await push(u))`. It returns before any push finishes, and the test never waits for the pushes. Later cost: callers think the sync is done while pushes are still running, and a failed push is never reported.
Trap 2: 'everywhere' means the files the agent read. `rg getUser` finds the old name as a string in a job config. Later cost: the job breaks the next time it runs.
Checks: the `no-misused-promises` lint and a repo-wide search. Fix: `for...of` with `await`, or `await Promise.all(...)`.
Terms on this card
- `no-misused-promises`
- A typescript-eslint rule that flags async functions passed where a non-promise callback is expected, such as `forEach(async ...)`.
- rg
- ripgrep, a fast command-line tool that searches text across a whole repository.
- `for...of`
- JS/TS loop over the items of an array. Inside an async function, `await` in its body waits for each item before moving to the next.
- the agent
- The AI coding system doing the work: a chat assistant, IDE agent or terminal agent.
- green
- A test or check that passes.
Lesson goal: Find bugs in code that compiles, reads well and passes its tests: skipped edge cases, text, time and money traps, scale problems, unawaited async work, leaked resources, races, unsafe retries, missed call sites, behaviour-changing refactors and invented APIs. Choose the check that would expose each one. ·
the whole lesson