Finding and Fixing Bugs
Debugging fundamentals and two approaches — quick fixes for simple errors, and evidence-based debug mode.
As coding agents write more code, engineers spend more time reviewing and validating than typing. Finding and fixing bugs becomes an increasingly important skill.
Debugging fundamentals
Good debugging follows the same principles whether the work is done by a human or an agent:
- Create a reliable reproduction. If you cannot reproduce the bug, you cannot verify the fix.
- Reduce it to the smallest case. Remove everything unrelated to the bug.
- Read the error carefully. The error often tells you where to start.
- Make a specific hypothesis. "The bug may be in
calculateTotal()when discounts are applied" is a testable hypothesis. - Instrument the code. Add logging around inputs and outputs in the area you suspect.
- Prevent regression with a test. Once you find and fix the bug, write a test that catches it.
Agents can help with every step, but they still need evidence.
Fixing simple errors quickly
For bugs with a clear error message or obvious cause, agents can often fix them quickly.
The checkout page crashes with this error:
TypeError: Cannot read properties of undefined (reading 'total')
Find the cause and fix it. Add a regression test if the existing test setup supports it.This approach works well when the cause is visible in the error message. The agent can read the stack trace, understand what went wrong, and propose a fix.
Evidence-based debug mode
For more complex bugs, use a different approach: instead of guessing the fix, gather evidence first.
Follow these five steps, mirroring debugging fundamentals:
- Generate hypotheses about what might be wrong.
- Instrument the code with targeted logging.
- Run the reproduction and collect output.
- Analyze logs to identify the root cause.
- Make a focused fix based on evidence.
Example prompt:
Do not fix this yet.
List three likely hypotheses for why stacked discounts produce the wrong total.
Then add temporary logging to the pricing calculation so we can confirm which hypothesis is true.This keeps the agent from jumping to a plausible but wrong solution.
What you learned
Now that you understand debugging and how coding agents can speed up investigations, let us discuss how to validate that work through code review, testing, and production readiness.