Sub topic 13
Know when to stop prompting and debug by hand
This chapter assumes you can run code and tests from a terminal, use basic git commands, and have followed the earlier chapters on reading errors, writing prompts, and verifying fixes. The workflow so far leans on the assistant. It has limits, though, and a skilled developer notices when the conversation has stopped helping. This chapter covers how to recognize that point, what to do by hand, and how to bring the assistant back in afterwards.
Why prompting stops paying off
An assistant diagnoses a bug from the evidence you give it. Each follow-up prompt is useful only if it adds evidence: a new traceback, a log line, a failing test, a changed result. When the new information stops, the assistant has only its own earlier guesses to work from. It then produces more guesses with the same confidence as before.
Time also matters. Ten minutes spent on one prompt and one reply feels cheap. Ten rounds of that is more than an hour, and the code usually ends up in worse shape than where it began. Deciding when to stop is a skill, and it is easier if you decide the rule before you start.
Signals that it is time to stop
Watch for these patterns. One of them alone may be noise. Two together are a clear sign.
| Signal | What it looks like | What it usually means |
|---|---|---|
| Repeated fixes | The assistant proposes a change you already tried, in different words | The conversation has run out of new hypotheses |
| Flip-flopping | Fix A is replaced by fix B, then B is replaced by A | Neither is based on evidence about the real cause |
| Growing diff | Each attempt touches more files or adds more code | The fix is working around the bug, not removing it |
| Moving error | Every fix produces a different error | The assistant is changing behavior without understanding it |
| Contradiction | The reply conflicts with an earlier reply or with your traceback | The conversation is too long, or the assistant lacks context you have |
| Unverifiable claims | The assistant cites a function, flag, or setting you cannot find in the documentation | A hallucinated API, covered in an earlier chapter |
| Unreproducible failure | The bug appears only sometimes, or only on another machine | The assistant cannot see the thing that varies |
The last signal deserves attention. Intermittent failures, timing problems, and environment-specific bugs depend on facts the assistant cannot observe. You can observe them, so you are the better debugger for that class of problem.
Set a budget before you start
The simplest protection is a rule you write down at the start of a debugging session. For example:
- Allow three fix attempts per hypothesis.
- Allow 20 minutes in total before changing approach.
- Stop earlier if the diff has grown beyond the size of the original function.
The numbers are arbitrary. What matters is that you chose them before you were frustrated and invested in the current approach. A time-box turns "just one more try" into a decision you make deliberately.
A decision flow
The flow below shows when to follow up, when to stop, and where to go next.
Notice that reverting comes before debugging by hand. Failed attempts leave behind partial edits, and you do not want to investigate a bug while also investigating changes that someone else made to your code.
Reset to a known state
Run git status and git diff first. Then decide what to keep. If you committed small steps as earlier chapters advised, going back is cheap.
git status
git diff --stat
git stash push -m "assistant attempts, not working"Using git stash instead of git checkout . or git reset --hard keeps the attempts recoverable. You may want to look at them later, since a failed fix sometimes points to the right area of the code. Remember that git stash does not include untracked files by default. Add -u if the assistant created new files.
Debug by hand
Manual debugging is not a fallback for people who cannot prompt well. It is a separate set of techniques, and for some bugs it is faster. Four are worth knowing.
Use an interactive debugger
A debugger lets you stop the program at a chosen point and inspect real values instead of guessing at them. In Python, breakpoint() starts pdb.
def average(values):
breakpoint()
return sum(values) / len(values)
print(average([]))Run it with python stats.py. The program pauses and shows a (Pdb) prompt. These commands cover most needs:
| Command | Action |
|---|---|
| `p expr` | Print the value of an expression, such as `p values` |
| `n` | Run the next line, stepping over function calls |
| `s` | Step into a function call |
| `c` | Continue until the next breakpoint or the end |
| `w` | Show the call stack |
| `u` / `d` | Move up or down one frame in the stack |
| `q` | Quit the debugger |
Typing p len(values) here prints 0, which confirms the cause in the traceback with a real observation. In a larger program, you would set the breakpoint earlier and step toward the point where a value first becomes wrong. The goal is to find the earliest place where the program's state differs from what you expected. The error line is usually only where the damage becomes visible.
JavaScript has debugger; statements and the browser or Node inspector, and most IDEs can set breakpoints with a click. The method is the same in all of them.
Find the change that broke it with git bisect
If the code worked last week and fails now, git bisect finds the commit that introduced the failure by binary search. With a test that reproduces the failure, it can run unattended.
git bisect start
git bisect bad
git bisect good v1.4.0
git bisect run pytest tests/test_stats.py -x -q
git bisect resetReplace v1.4.0 with any commit or tag where the code was known to work. Git checks out the midpoint, runs the command, and narrows the range based on its exit code. With 128 commits in the range, it needs about seven steps. The result is a single commit, which is often a far smaller area to examine than the whole project. You can then give that commit's diff to the assistant as strong evidence.
Add targeted logging
For code you cannot pause, such as a server handling requests, log the values that matter at the boundaries of the suspect section.
import logging
logging.basicConfig(level=logging.DEBUG)
log = logging.getLogger(__name__)
def average(values):
log.debug("average called with %r (len=%d)", values, len(values))
return sum(values) / len(values)Log the input and the output of each step, and use %r so empty strings, None, and whitespace are visible. Compare what you see with what you expected at each step. The first mismatch marks the location of the bug.
Explain the problem out loud
Describe the code line by line to a colleague, or to a rubber duck on your desk. Saying what each line does forces you to state your assumptions, and a false assumption often becomes obvious as you speak it. Writing a prompt can have the same effect, so if the answer occurs to you halfway through composing one, the prompt did its job.
Check your assumptions
When you debug by hand, list what you believe is true, then test each belief:
- The code I am editing is the code that runs. Check for a stale build, a cached module, or a second installed copy.
- The input is what I think it is. Print it.
- The environment matches. Compare language version, dependency versions, and environment variables with a machine where the code works.
- The failing test fails for the reason I think. Read its output, not only its name.
A surprising number of long debugging conversations end when someone finds a broken assumption in item 1 or 2. The assistant could not have found it, because it never saw the real values.
Return to the assistant with something new
Stopping is not permanent. After manual work you usually hold information the assistant lacked, and a new, short conversation can be productive. Do not continue the old, long one. Its history contains discarded theories that can mislead the next answer.
A good restart prompt states what you now know:
I am running Python 3.12. average() in stats.py raises ZeroDivisionError.
Using pdb I confirmed that values is [] at the call from report.py line 41.
git bisect shows the failure began in commit 3f2a9c1, which changed how
report.py builds the list (diff below).
<paste the diff of that commit and the traceback>
Why would the new code produce an empty list for this input?
Explain your reasoning from the diff, then suggest the smallest change.This prompt is better than the original because it narrows the question and supplies verified facts. It also asks about one specific piece of code. Apply the same checks as before to whatever comes back: compare the explanation with the evidence, make one change, and verify it with a test.
Common mistakes
- Continuing because of sunk cost. Ten prompts of effort do not make the eleventh more likely to work. Judge the next step by the evidence you have, not by the time already spent.
- Debugging by hand on top of the assistant's edits. Revert or stash first so you know which behavior belongs to the original code.
- Skipping the written budget. Without a limit, the stopping decision happens when you are tired, not when it is useful.
- Never stopping at all. Some developers hand every bug to the assistant. That slows learning, and the skills above are the ones that make your prompts better.
- Treating manual debugging as a defeat. It is the point at which you produce the evidence the assistant needs.
Exercise
You asked an assistant to fix a test that fails about one run in five. After four attempts, each proposing a different change to the retry logic, the test still fails intermittently and the diff now touches six files. Name the signals that tell you to stop prompting, state what you do to the code first, and name one manual technique you would use next.
Show answer
The signals are the growing diff, the repeated and differing fixes without new evidence, and an intermittent failure that depends on runtime facts the assistant cannot see. First, revert or stash the changes (for example git stash push -m "assistant attempts") so you debug the original code. Then use a manual technique such as adding targeted logging around the suspect section, running the test repeatedly with a debugger or logs to capture a failing run, or using git bisect run if the test used to pass reliably. Afterwards, start a fresh prompt that includes the captured evidence.
Exercise
Why should you start a new conversation, not continue the old one, after debugging by hand?
Show answer
The old conversation contains discarded theories and failed fixes, which can bias later answers. A new, short prompt with only the verified facts (observed values, the commit found by bisect, the traceback) gives the assistant a narrower and more accurate problem.