Skip to content
Tech Interview Prep
Technical interview guideNew

AI-Assisted Debugging in Legacy Codebases

How to reproduce, localise, diagnose and patch a bug in a large unfamiliar repository while directing an AI coding assistant, and how to show the interviewer that you verified every change. Covers the debugging round where the assistant is allowed for the whole session.

Minutes to read
3
Practice MCQs
24
Interview Q&A
25
Edition
v2
Editorial status
Reviewed

Scope: Method is tool-independent and current to mainstream AI coding assistants and Python, Java, TypeScript and C# codebases as of 2026. Assistant-specific features (context limits, agent modes, tool permissions) change often and should be checked against the vendor's current documentation before the interview..

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 run over 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 ⌈log⁡2n⌉\lceil \log_2 n \rceil 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.

yes no Reproduce on clean checkout Map call path with find-references Write hypothesis plus falsifying check Observation kills it? Minimal patch from assistant Read whole diff for side effects Targeted test, module suite, callers

When to use and when not to

SituationUse the assistant for the whole loopNarrow it first
Deterministic failure with a reproducing testYes, for the patch and the diff reviewNo
Flaky or ordering-dependent failureOnly for running loops and measuring ratesYes: find the shared state yourself
Regression between two tagsYes, to drive git bisect runYes: confirm the commit's cause, not just its position
Unfamiliar large repo, no testsOnly to explain paths you then checkYes: write the characterisation test first
Security-adjacent code seen in passingNo patch in this changeYes: flag it separately

Traps interviewers probe

  1. Patching before reproducing. Fix: run the test on a clean checkout and record the exact output as the contract.
  2. 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.
  3. 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.
  4. 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.
  5. 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.

  1. Reproduced: the test fails with the exact output, on a clean checkout.
  2. Cause: one sentence, with the observation that proved it.
  3. Patch: the minimal diff, and why the assistant's broader suggestions were rejected.
  4. Verified: reproducer now passes, module suite passes, callers checked. Command and result.
  5. 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.