Debugging with Coding Agents
A systematic way to hunt bugs with an agent: reproduce, isolate, hypothesize, and verify — without letting it guess and patch symptoms.
Paste an error message into a coding agent and you'll usually get a fix within a minute. Sometimes it's the right fix. Often it's a patch over the symptom: a null check where the value should never have been null, a retry around a race condition, a widened date range that hides an off-by-one. The error disappears, the bug stays, and it comes back later wearing a different stack trace.
Agents are excellent debugging partners when you make them debug the way experienced engineers do. This lesson gives you a four-step method that works with any coding agent: reproduce, isolate, hypothesize, verify. You'll get prompts for each step, a full walkthrough of a real-world bug, tricks like automated git bisect, and a playbook for when the agent starts going in circles.
Why agents patch symptoms
A coding agent is trying to finish the task you gave it. If the task is "fix this error," the fastest path to done is making the error stop appearing. That's not laziness; it's the task taken literally.
Consider this classic:
TypeError: Cannot read properties of undefined (reading 'id')
at formatOrderRow (src/admin/orders/format.ts:14:31)The one-line fix is order.customer?.id. The error vanishes. But why was customer undefined? Maybe a deleted customer left orphaned orders. Maybe a query stopped joining the customer table. Maybe a new checkout path skips creating the record. Each is a different bug, and optional chaining fixes none of them. It just turns a loud crash into a quiet blank cell.
Fix this error: TypeError: Cannot read properties of undefined
(reading 'id') at formatOrderRow (src/admin/orders/format.ts:14:31)The admin orders page crashes with this error (full trace below). Don't
fix anything yet. First find out why order.customer is undefined: which
orders have no customer, how they got into that state, and whether that
state should be possible at all. Report the root cause with evidence,
then propose a fix.
TypeError: Cannot read properties of undefined (reading 'id')
at formatOrderRow (src/admin/orders/format.ts:14:31)
at Array.map (<anonymous>)
at OrdersTable (src/admin/orders/OrdersTable.tsx:22:18)The second prompt changes the task from "make the error go away" to "explain the error." That one shift does most of the work. The rest of this lesson structures it.