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.
Leaked resources: files, connections, goroutines
card 4 of 6
A lock that is never released
builds on: Error handling idioms across languages
In Python, the agent adds a cache refill: `lock.acquire()`, then `rows = db.fetch()`, then `lock.release()`. Tests pass. In production, `db.fetch()` times out once. The exception skips `release()`, the lock stays held, and every later request blocks on `acquire()` forever. No garbage collector frees a held lock. **Tell:** acquire and release written as separate statements. **Later cost:** one timeout freezes the feature until a restart. **BETTER:** wrap the fetch in `with lock:`, which releases the lock on return and on exception alike.
Terms on this card
- garbage collector
- The runtime part that frees memory nothing refers to anymore. It does not reliably close files or connections, and it never frees held locks or blocked goroutines.
- 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, an outage or extra maintenance.
- the agent
- The AI coding system doing the work: a chat assistant, IDE agent or terminal agent.
- pass
- Python statement that does nothing; used as a body, it makes a function or handler an empty shell.
Lesson goal: Spot files, connections and locks opened without `with`, try-with-resources or `defer`, as well as `defer` inside loops, goroutines blocked forever and contexts never cancelled. Explain why these pass tests but exhaust resources in production. ·
the whole lesson