Phase 3: The Generate-Validate Loop · 45 min · Claude Code · Python
Debugging AI-Generated Code
If the same test keeps un-breaking and re-breaking across attempts, more patches won't fix it — the approach needs to change.
Hiring signal: Recognizing agent thrashing from a sequence of fix attempts — not just eventually noticing you're stuck — is the debugging judgment that keeps a bad session from burning hours before someone steps back.
What you will learn
- Apply the predict-before-reveal habit to debugging: form a hypothesis before asking an agent to fix an error
- Paste errors with enough context (full traceback, command, surrounding code) for a fix attempt to be well-targeted
- Use an explain-and-retry loop to distinguish a debugging session that's converging from one that's thrashing
- Decide when to abandon incremental patching and restart from the spec instead
Introduction
Debugging AI-Generated Code
Four tests are failing after a generation pass. An engineer pastes the failures back to the agent and asks it to fix them. Attempt two: two of the four now pass, but a different test — one that was passing before — now fails. Attempt three: the original two are fixed again, but the same test from attempt two breaks again. Attempt four looks almost identical to attempt two. Forty-five minutes and six attempts later, the same two tests are still trading places between passing and failing, and the engineer hasn't once, in six attempts, stopped to ask whether patching is still the right move. This is agent thrashing, from c12-00's mindset lessons, showing up concretely: fixing one thing breaks another, in a loop, with confidence at every step and no actual progress underneath it.
Predict before you reveal the error
Before pasting a failure back to an agent, form your own hypothesis: what do you think is actually wrong, based on the error and the code? This isn't busywork — it's the struggle-principle rep from c12-00-5, applied specifically to debugging. If your prediction matches the agent's diagnosis, you've confirmed your own understanding and can evaluate the proposed fix critically instead of accepting it on faith. If your prediction doesn't match, that's valuable information regardless of which of you turns out to be right — it means there's a genuine gap in understanding somewhere that a "just fix it" exchange would have papered over instead of surfaced.
What "pasting errors effectively" actually means
A vague "it's broken, here's the error" gives an agent a fraction of what it needs. Effective error reporting includes the full traceback (not just the last line), the exact command or input that triggered it, and the relevant surrounding code — the same specificity principle from earlier in this phase, applied to bug reports instead of feature requests. "TypeError on line 42" is vague; the full traceback plus "this happens when I run parse_timestamp('1:2:3:4')" is not.
Unlock the full lesson
You've read the first 2 sections. The rest of this lesson covers Explain-and-retry: a loop that should converge, Patch versus start over, Build It — plus a hands-on lab, quiz, and project artifact.
Create a free account to unlock Phase 0 and Phase 1 of every course — no credit card.
Browse all courses · View pricing · DeVenture Academy