Sub topic 10
Iterate when the first fix does not work
This chapter assumes you can run Python and pytest from a terminal, use git, and have already written a debugging prompt as covered earlier. The first fix often fails. That is normal. What matters is how you report the failure back to the assistant.
Why a failed fix is new evidence
A failed fix tells you something. Either the diagnosis was wrong, the fix was incomplete, or the fix changed the failure into a different one. Each case calls for a different follow-up, so first work out which one you have.
Run the original reproduction again after applying the change. Then compare the new output with the old output.
| What you see | What it likely means | Next step |
|---|---|---|
| Same error, same line | The diagnosis was probably wrong | Send the unchanged output and ask for a new hypothesis |
| Different error | The fix moved the failure | Send the new traceback and the diff |
| No error, wrong result | The bug was hidden or only partly fixed | Send actual versus expected values |
| New failures in other tests | The fix broke other behavior | Send the failing test names and the diff |
Report back with facts
A vague reply such as "it still doesn't work" forces the assistant to guess. Give it the same kind of evidence you gave the first time.
Suppose the assistant first suggested catching the error inside average:
def average(values):
try:
return sum(values) / len(values)
except ZeroDivisionError:
return 0The traceback is gone, but your test expecting a clear error now fails. A useful follow-up looks like this:
I applied your change to average() in stats.py. The ZeroDivisionError is gone,
but average([]) now returns 0.
Expected: a ValueError telling the caller the input is empty.
Actual: returns 0, so test_average_of_empty_list_raises fails with
"DID NOT RAISE <class 'ValueError'>".
Diff I applied:
<paste the diff>
Why did this not meet the expected behavior? Do not change the tests.
Propose the smallest change that raises ValueError.This message names what you applied, what happened, and what you expected. It also sets one constraint: do not change the tests. Without that constraint, an assistant may edit the test to match the code.
Change one thing at a time
Before you send a follow-up, make sure the code is in a known state. If the first attempt left a mess, undo it.
git diff
git restore stats.pygit restore discards uncommitted changes to that file, so check git diff first and keep anything you want. Working from a clean state means each new fix is tested alone. If you stack three unverified fixes, you cannot tell which one helped.
The loop looks like this:
Keep the conversation useful
Long threads drift. After several failed attempts, the assistant may repeat earlier suggestions or lose track of constraints. Watch for these signs:
- It proposes a fix you already tried.
- It contradicts a fact you gave earlier.
- Its answers get longer but add no new evidence.
When this happens, start a fresh conversation. Summarize what you know: the environment, the reproduction, what you tried, and what each attempt showed. A short summary often works better than a long history.
You can also ask for a different angle: "List two other possible causes and one check that would tell them apart." A check you can run beats another guess.
Set a limit
Decide in advance how many attempts you will allow, for example three. If each attempt gives you new information, continue. If you are looping with no new evidence, that is the signal to debug by hand, which a later chapter covers.
Exercise
You applied an assistant's fix and the same ZeroDivisionError appears on the same line. What should your follow-up message contain, and what should it ask for?
Show answer
Include the unchanged traceback, the diff you applied, and a statement that the output did not change. Ask the assistant to explain why its diagnosis did not hold and to give a new hypothesis, ideally with a check you can run to confirm it. Do not stack another fix on top before testing.