LibraryLearning
Back to course

Execution Discipline • Lesson 4

How to Debug with AI Without Going in Circles

20 minute lesson

Learning objectives

  • Spot looped debugging patterns
  • Anchor debugging in evidence
  • Preserve state and isolate variables

What Is It?

Debugging with AI means using the model to reason about failures, inspect likely causes, and propose fixes. The trap is that AI is good at generating plausible explanations. If you do not anchor it in evidence, you can end up in a loop of elegant guesses.

The goal is evidence-led debugging, not brainstorming disguised as diagnosis.

How It Actually Works

Real debugging starts from a symptom and narrows through evidence. Error messages, logs, stack traces, failing test output, request payloads, and reproduction steps are the raw material. AI helps most when you feed it those artifacts directly and ask it to explain which hypotheses fit the evidence.

Where AI goes wrong is when you ask broad questions like “why is this broken?” without concrete runtime signals. The model then samples from familiar failure patterns in its training data. Some of those patterns will sound convincing, but they may have nothing to do with your actual bug.

A better workflow is: reproduce, capture evidence, localize the failure boundary, form 2 to 3 ranked hypotheses, then test the smallest discriminating check. The discriminating check is important. It is the one observation that tells you which hypothesis is true. For example, if a request succeeds in Postman but fails in-browser, the issue may be CORS or cookies rather than the backend logic itself.

The Jargon Decoded

  • Repro — A reliable way to reproduce the bug.
  • Stack trace — The chain of function calls leading to an error.
  • Hypothesis — A specific proposed cause of the bug.
  • Failure boundary — The point where the system stops behaving correctly.
  • Discriminating check — A test that distinguishes between competing explanations.

Why This Matters When You're Building

Without a disciplined debugging loop, AI can waste hours by leading you through one plausible theory after another. That feels like progress because text is being produced, but no uncertainty is actually being removed.

Evidence-led debugging keeps the AI useful and keeps you in contact with reality.

What To Tell The AI

  • “Here is the exact error, stack trace, and reproduction path. Give me the top 3 hypotheses ranked by likelihood, and for each one, the fastest check that would confirm or rule it out.”
  • “Do not propose fixes yet. First identify the failure boundary from the logs and code path.”
  • “Assume the symptom is caused by one specific mechanism. What evidence would have to be true for your explanation to hold?”
  • “After each attempted fix, reassess using the new logs instead of repeating prior guesses.”

Common Misconceptions

“AI is good at debugging because it knows many bugs.” It knows many bug patterns. That is not the same as knowing your bug.

“More fixes attempted means progress.” Progress in debugging is measured by reduced uncertainty, not by patch count.

“If the error disappeared, the bug is solved.” Sometimes you only hid the symptom.

Sources

  • Google Testing Blog, Debugging mindset
  • The Art of Debugging, Ganssle and Lin
  • OpenAI, Best practices for using models with code
  • GitHub Copilot, Troubleshooting code with AI

Checkpoint questions

  • Why do AI debugging loops spiral?
  • What evidence should you force before changing code?

Exercise

Write a debugging checklist you want followed before another code change is attempted.

Memory recall

Quick quiz

Use retrieval, not rereading. Answer from memory, then check the feedback.

1. Why do AI debugging loops spiral?

2. What evidence should you force before changing code?

3. What is the main job of a debugging checklist?

Progress

Mark this lesson complete when done

Next lesson