AI-generated code debugging

If two rounds of prompting haven't fixed a bug, a third won't either. The model doesn't have the context it's missing, and each round adds another locally-plausible change to a system that already doesn't cohere. At that point someone needs to read the code.

The loop that doesn't close

The pattern is recognisable. You describe the symptom, the model changes something, the symptom moves. You describe the new symptom. Four rounds later you have four modifications, each of which looks reasonable on its own, and a bug that has migrated rather than disappeared.

This happens because the model is reasoning about your description, not about your system. It cannot see the file that contradicts the fix it just wrote, and you have no particular reason to suspect that file either.

Try these first

A few of these close the loop without anyone else involved. They're worth twenty minutes before asking for help.

  • Write down the exact steps that reproduce the failure, every time
  • Log the data at each boundary with JSON.stringify, and compare both sides
  • Check the failing field's name and casing in both the sender and the receiver
  • Try it with an empty list, a null value, a slow network and a logged-out session
  • Read the server logs rather than the browser console
  • Revert your last three changes and confirm the bug predates them

What I do differently

  1. 01

    Reproduce before changing

    A bug that can't be triggered on demand can't be confirmed fixed. Getting a reliable reproduction is often most of the diagnosis.

  2. 02

    Follow the data, not the code

    I trace one value from entry to failure rather than reading files top to bottom. The hop where it stops matching expectations is the bug.

  3. 03

    Fix the cause

    A try/catch that hides the error is not a fix — it's the same bug with less visibility. If the real fix is bigger, I'll tell you that before doing it.

  4. 04

    Check the neighbours

    Generated code repeats its mistakes. Where one seam is wrong, the ones built the same way usually are too.

Common questions

Can you work on code generated by ChatGPT?

Yes, and it’s a large part of what I do. Generated code tends to be locally sensible but globally inconsistent, which is exactly the kind of problem that’s hard to prompt your way out of. I read it the same way I’d read any unfamiliar codebase.

Can you fix production bugs?

Yes. If something is broken for real users right now, say so when you get in touch and I’ll treat it accordingly. I’ll want access to logs and the deployment, not just the code.

The service

AI Code Debugging

The app half-works. You've described the bug to the AI six times, and each fix moves the problem somewhere else. At some point the loop stops being cheaper than reading the code.

Further reading

Your AI-built app doesn’t need another prompt.

Sometimes it needs an engineer.

Send the messy version. That’s usually the useful version.

Show me what’s stuck.

Don’t spend another six hours fighting the same bug. Send me what you’ve got — the messy version is usually the useful version.

Both open with a short template already filled in.