Overview
Curated: · Written: · Reviewed:
AI-Assisted Debugging in Legacy Codebases
In one line
Reproduce the bug on demand, localise it with falsifiable hypotheses, let the assistant type a minimal patch, and verify it against the reproducing test, the full suite and the callers before you claim it works. Reach for this whenever the debugging round allows the assistant for the whole session.
Key definitions
- Contract: the failing test or exact reported symptom that every later change is measured against.
- Falsifiable hypothesis: a claim with one observation that would kill it, such as printing
days_in_period()and seeing 28 or 30. - Masked symptom vs removed cause: a sleep, retry or guard that hides a failure without fixing the mechanism.
- Bisect:
git bisect runover commits with a deterministic test, used for regressions between a good and a bad ref. - Blast radius: every caller, default argument, shared helper and module-level state the diff can reach.
Formulas and complexity
For a flaky test run N times, quote the observed failure rate with its sample size, for example 14 of 200 before and 0 of 200 after. Bisect over n commits needs about steps, so 400 commits take 9.
How it works
The loop is reproduce, then map the path, then hypothesise, observe, patch, verify. The assistant does the typing; you hold the contract and the evidence.
When to use and when not to
| Situation | Use the assistant for the whole loop | Narrow it first |
|---|---|---|
| Deterministic failure with a reproducing test | Yes, for the patch and the diff review | No |
| Flaky or ordering-dependent failure | Only for running loops and measuring rates | Yes: find the shared state yourself |
| Regression between two tags | Yes, to drive git bisect run | Yes: confirm the commit's cause, not just its position |
| Unfamiliar large repo, no tests | Only to explain paths you then check | Yes: write the characterisation test first |
| Security-adjacent code seen in passing | No patch in this change | Yes: flag it separately |
Traps interviewers probe
- Patching before reproducing. Fix: run the test on a clean checkout and record the exact output as the contract.
- Accepting a guard as proof. Fix: check the input class the guard protects. A null guard on a path no test covers is unverified until a test applies the failing input.
- Trusting an invented API. Fix: check the method exists in the pinned version, for example
python -c "import calendar; print(hasattr(calendar, 'monthrange'))". Mock-based tests accept any keyword and will not catch it. - Treating a sleep or retry as the fix. Fix: measure the flake rate before and after, then find the shared state (global, row, clock, order) that causes it.
- Merging a whole-file rewrite. Fix: keep the smallest change that passes the reproducer. Defer renames and reformatting.
Interview tips
Opening. "I'll reproduce the failure on a clean checkout first, then localise with one observation per hypothesis, and I'll verify the patch against the reproducer, the module suite and the callers."
Expect these follow-ups.
- Which observation distinguishes your top two causes?
- How do you know the change caused the failure and was not already there? Run the same test on the parent commit.
- Which callers depend on the old return value?
- What residual risk did you not test?
30-second answer outline.
- Reproduced: the test fails with the exact output, on a clean checkout.
- Cause: one sentence, with the observation that proved it.
- Patch: the minimal diff, and why the assistant's broader suggestions were rejected.
- Verified: reproducer now passes, module suite passes, callers checked. Command and result.
- Not verified: the named remaining risk and the next check. Name the residual risk, and state the next check you would run to close it.
Feedback on this overview
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.