All writing

What coding agents get wrong when they debug, and what caught it

For the last few months most of my debugging has gone through a coding agent, Claude Code on a personal iOS reading app (SwiftUI and Core Data, with a test suite that grew from about eleven to nearly nineteen thousand tests over that time) and Cursor at work on a payments frontend that embeds a third-party wallet button. The two codebases have nothing in common, and neither do the tools, but when I went back through the sessions the same few mistakes kept turning up in both, and the checks that caught them were also the same few, so this post goes through the mistakes with an example or two each and then the checks.

We make most of these ourselves when we debug by hand. The difference is that an agent makes them with a lot of confidence and writes a tidy summary afterwards, which makes them easier to miss.

Taking a label as a fact

The reading app had four dedup test suites that only failed in full-suite runs, and an agent memory note from an earlier session filed them as “environmental, rerun scoped, don’t chase”. The agent read the note and believed it, the same way the sessions that wrote it had. It did try one real fix (it replaced a process-global fault-injection singleton with a per-store one across 10 files), the scoped runs went green, the next full run failed the same tests, and at that point it went back to the note and explained the rest away as nondeterminism in Core Data’s persistent history.

What turned it around was one temporary log line at the entry of the sweep these tests exercise. A test that runs the sweep three times logged four sweep executions, each from a different thread, plus a full-library fallback running at the same time. The extra work came from the tests themselves, which called start() on the actor under test. On a fresh temp store with no history cursor, start() enters a recovery pass, and it also installs a change observer whose debounced sweeps fire on the test’s own saves. So the test re-deferred a row, its save triggered an extra sweep, that sweep loaded the deferred set before the write landed and saved it back empty, and the assertion saw []. None of the threads were other tests the runner defaults to running tests serially, so it was all the actor’s own background work inside a single test.

The same thing happened at work with a saved learning note instead of a memory. A merchant’s wallet button wasn’t showing, and a note from a couple of months earlier said that mounting the button inside a display: none container leaves Stripe’s iframe at zero height. After a detour through container width, the agent matched the logs to the note, told me the merchant had to stop using display: none and then remount, and started writing that up as integration advice. The real cause was a bug in our code (since fixed) that sent its state events to whichever button mounted last, and the merchant’s page had two of them. Their main button mounted first, so its “ready” event went to the other one, and their slot, which waits for that event to unhide itself, stayed hidden. display: none wasn’t the cause here, since in our test Stripe laid the button out again as soon as the slot became visible.

A note in memory or in docs/ is something a previous session believed, so we treat it as a lead and keep looking.

That’s a bit awkward to write, since I’ve argued in the post about giving agents a foundation that those notes are the part that matters most. I still think so, but they need the same check as anything else an agent tells you.

Sizing the fix so it can be declined

Back to the flaky suites. After the singleton fix didn’t help, the agent recommended leaving things as they were and described a real fix as “a substantial reconciler-test-isolation overhaul”, large and uncertain. When I asked it to compare the options against the ideal outcome instead of against each other, it wrote that it had “inflated” the job of making those tests deterministic into a wholesale overhaul so it could decline it, and that its persistent-history theory was unproven. The fix that came out of it was bounded to the four suites, where the tests either drive the sweep directly or use an actor that was never started.

This one shows up a lot in a milder form, where the agent lists three options and the one that fixes the problem is described as the expensive one, which makes the cheap workaround look reasonable. Asking where the size estimate came from usually takes care of it.

Trusting output that was cut off

On the reading app, Mac Catalyst unit tests were opening the developer’s real Core Data store. On Catalyst the test host is the app itself running in your real home folder (in my setup it isn’t sandboxed), not a throwaway simulator container, and in Debug a schema mismatch runs a recovery path that backs up and then recreates both stores, which means a test run could wipe your own library. I wrote about the whole fix in the post on isolating the Catalyst test host. The agent fixed the obvious entry points and searched for remaining uses of CoreDataStack.shared, but piped the search through head -20, so what it reported as the complete list was only the first twenty lines, and a review later found six more tests that reached the shared stack indirectly (through a holder’s getOrCreate() and a parameterless live dependency). Since grep can’t see a reach through a dependency’s live value anyway, that fix ended in a Debug-only runtime fence, where the app refuses .shared once the test bundle is loaded, so any offender traps and the test runner names it.

Protecting a bug’s side effects

The reading app imported MOBI, AZW3 and FB2 books by converting them to EPUB, but stored the source format in the book’s format field, so the cover loader saw “MOBI”, didn’t look for an EPUB cover, and those books had no covers. The fix was to store .epub and keep the original in a new field, and the plan went through two rounds of reviewer agents, who found real problems in it but were also very insistent on behaviour preservation, which meant they kept defending things that only existed because of the bug.

Converted books counted toward a “text-based” achievements bucket, and a UAT scenario encoded the tally, so the reviewers wanted a task to keep that. When I asked why achievements cared about the original format at all, the answer was that they didn’t, the bucketing was a side effect of the wrong field value, and the task was dropped. A “MOBI” badge on what was now an EPUB went the same way a bit later, after I looked at a screenshot of it, and ended up as an “Imported from” row on the details page.

Reviewer agents treat current behaviour as the spec, which is the right default for a refactor and the wrong one for a bug fix, so in a bug fix we have to ask what the field or the behaviour is for.

Predicting instead of running

This is the most common one, and the cheapest to fix, because the answer is usually one command away.

  • A reviewer agent said that removing nonisolated from a handler would go unnoticed by the tests. Run as a mutant, it crashed the test host.
  • While designing a fix for a wallet payment where the charged amount didn’t match the cart, the agent built part of its reasoning on buyers changing the cart while the Google Pay sheet was open. The sheet is modal, so they can’t, and a late update was always the buyer’s own last change arriving late (a debounced quantity stepper) or a server recalculation. That also broke a planned device-test step (“press + while the sheet is open”), which had to become a setTimeout in the console before tapping Pay.
  • In the display: none case above, the remount advice was contradicted by a test we had already run, where forcing the slot visible made the button render with no remount at all. I only had to type “remount?” for the agent to go back and read its own evidence.

Testing against old code

At work a fix for Stripe’s “Unexpected call to paymentFailed()” error lived in a separate git worktree, and the manual check in the browser failed with the same error. I remembered that the fix wasn’t in the main checkout, the agent then compared the line numbers in the stack trace with both versions and they matched the old code, and the dev server turned out to be running from the main checkout. The fix was fine all along. It’s an easy one to miss with agents because they like worktrees, and the thing you’re testing against (a dev server, a simulator build, a CDN bundle) usually isn’t part of the worktree.

What caught them

Most of the checks were a question or a single command, and they’re all in the sections above, so here they are in one place:

  • Asking for the ideal outcome before choosing between options, which is what got the inflated fix size admitted.
  • Asking what a field or behaviour is for, whenever reviewers want to keep something that sits around a bug.
  • Mutation checks, breaking the production line a test claims to cover and making sure the test fails, which disproved the nonisolated prediction. There’s more on that in the TDD and mutation testing post.
  • Live probes instead of reasoning, a real device run, a console snippet on the merchant’s page, an A/B run.
  • A temporary log line where you think the problem is, like the one at sweep entry for the flaky suites.
  • A runtime check instead of a search, when the thing you’re looking for can hide behind a dependency.
  • Checking the build you’re testing, the line numbers in a stack trace, a version string, which directory the server runs from.

Nothing here needed a better prompt, and I don’t think a longer AGENTS.md would have prevented any of it. The agents were fine at finding a cause once something made them look at evidence, and every mistake above sat somewhere they could get away with not looking (a note that already had an answer, a size estimate nobody checked, a search that stopped at line 20, a behaviour that was already there, a prediction instead of a run). When we review an agent’s debugging, it helps to look at what each conclusion rests on, and when it rests on a note, a guess or a truncated output instead of something that ran, to ask for the run before going any further.

Email address copied [email protected]