Overview
Curated: · Written: · Reviewed:
AI-Assisted Debugging in Legacy Codebases
In the AI-assisted debugging round the interviewer is not grading whether you can write code. The assistant writes plenty of code. They are grading whether you can tell which code is wrong, prove it, change as little as possible, and show that every change was checked. A candidate who hands over a clean patch with no evidence behind it loses to one who finds the fault more slowly and can say why each step was taken.
The model to carry: the assistant is a fast, confident collaborator with no memory of your repo and no stake in whether the fix is right. Your job is to hold the contract (the failing test), the hypothesis, and the evidence, and let the assistant do the typing.
Why this round tests debugging, not generation
TrueInterview's question bank records 78 AI-assisted coding questions across 18 big-tech companies, and debugging is the most common subtype among the 64 reported for onsite rounds. The usual format is a live session in which the company provides an approved assistant and grades how you use it. Generation is the easy half. Almost any assistant will produce a plausible function. What separates candidates is whether they can enter a repository they did not write, find the fault, and avoid breaking the rest.
Interviewers probe three things: whether you reproduce before you touch anything, whether your hypotheses are falsifiable, and whether your verification would catch a bad patch. A weak answer sounds like "I asked the assistant what was wrong and it fixed it." A strong one sounds like "The failing test pins the behaviour, I confirmed the failure on a clean checkout, and the assistant's first patch passed the test but changed a public signature, so I rejected it."
Reproduce first: the failing test is the contract
Before you open a file, get the bug to fail on demand. A failing test, a ticket with a precise symptom, or a commit that fixed a bug whose parent you can check out in a scratch copy will all do. Run it on a clean checkout and record the exact output. That output is the contract. Every later change is measured against it.
# Python 3.12, pytest 8.x
git stash --include-untracked # start from clean state
pytest tests/billing/test_proration.py::test_mid_cycle_upgrade -x -q
# FAILED ... AssertionError: assert 1249 == 1333
If you cannot reproduce it, do not let the assistant guess. Say so, and narrow the conditions (input, environment, ordering) until the failure is deterministic. A bug you cannot reproduce is a bug you cannot verify fixed.
Interviewers probe whether you ran the test before the assistant did. A weak answer skips this and begins with a patch. They also check whether you can tell a test that fails for the reported reason from one that fails for an unrelated reason, such as a missing fixture.
Giving the assistant the right context
An assistant working from a whole repository tends to be wrong in a specific way: it reads the nearest file that resembles the bug and fixes that. Give it the failing test, the traceback, the function under suspicion, and the one or two interfaces it depends on. State the constraints explicitly: no public signature changes, no new dependencies, the test must pass unchanged.
Paste the actual traceback, not a paraphrase. Paraphrased errors lead to invented causes. Tell the assistant what you have already ruled out, or it will re-derive the same obvious suspect.
At scale, a monorepo with generated code, vendored dependencies, or several services sharing a schema can lead the assistant to edit a generated file that will be overwritten. Check which file is the source of truth before accepting an edit to it.
Mapping unfamiliar code and tracing call paths
You need a map before you need a patch. Use the language server's find-references and go-to-definition rather than grep alone, because grep misses dynamic dispatch and re-exports. Walk from the entry point (the route handler, the CLI command, the consumer) down to the failing line, and write the path down as a list of function names with file and line.
POST /invoices/{id}/upgrade
billing/api.py:88 upgrade_plan()
billing/proration.py:31 prorate() <- suspect
billing/calendar.py:12 days_in_period()
Ask the assistant to explain the path, then check its explanation against the code. Where it disagrees, the code wins.
Forming and checking hypotheses
A hypothesis is only useful if a single observation could kill it. "Something in proration is off" is not a hypothesis. "days_in_period returns 30 for February, so the mid-cycle fraction is computed against the wrong denominator" is one, because you can print the value and see whether it is 28 or 30.
Write each hypothesis with the check that would falsify it, run the check, and record the result. Keep a short log in the session. Interviewers often ask to see it, and it is the clearest evidence that you were reasoning rather than accepting output.
The assistant generates hypotheses quickly and will offer several with equal confidence. Ask it which one your evidence distinguishes. If none does, the next step is an observation, not a fix.
Narrowing the fault: logs, debugger, bisect and blame
Choose the cheapest instrument that separates your hypotheses. A log line or a print of an intermediate value is usually fastest. A debugger breakpoint helps when the state is large and you do not yet know which value matters. Use git bisect when the bug is a regression and you know a good commit:
git bisect start HEAD v4.2.0
git bisect run pytest tests/billing/test_proration.py::test_mid_cycle_upgrade -q
# first bad commit: 3e9a1c4 "Use calendar month length for proration"
git blame on the suspect lines gives the author and commit, which often explains why the code is shaped the way it is. Read that commit message before you change the code, since it may record an intentional decision.
A weak answer here is "I added logging everywhere and something showed up." Name the single observation that narrowed the fault.
Reading generated diffs for side effects and invented APIs
Treat every generated diff as code from an unreviewed contributor. Read the whole diff, not only the lines you asked for. Check three things specifically.
Side effects: did the change touch a shared helper, a default argument, a module-level cache, or a file outside the bug's path? Invented APIs: does every called method exist in the version the repo pins? Check against the installed package, not the assistant's memory. A method that exists in a newer release and not in the pinned one fails only at runtime on certain paths, which is exactly where the test will not look.
python -c "import calendar; print(hasattr(calendar, 'monthrange'))"
Third, whether the diff changed behaviour the test does not cover. A patch that makes one test pass by widening an exception handler has not fixed the bug.
Minimal patches, regression runs and what counts as verified
The smallest change that makes the reproduction pass, with no unrelated cleanup, is the target. Unrelated reformatting makes review harder and hides the real change. If the assistant proposes a refactor, defer it.
Verified means four things, in order:
- The reproducing test now passes, and it failed for the reported reason before the change.
- The module's full test suite passes, not only the new test.
- Any test that exercises the changed function's callers passes.
- You can state, in one sentence, why the change is correct and what input would break it.
Run the full suite, not only the module. A fix in proration.py can break a report generator three packages away. Record the command and the result in the session.
Not verified: a green run you did not read, a test you edited to match the new output, or a patch you reviewed only by asking the assistant whether it looks right.
Flaky, concurrency and state bugs the assistant misreads
Flaky tests, race conditions and shared-state bugs are where assistants are most confidently wrong. They tend to add a sleep, a retry, or a lock around the symptom, which makes the test pass and leaves the fault in place.
For a flaky test, run it in a loop before and after the change and report the failure rate, for example "fails 14 of 200 runs before, 0 of 200 after." Even then, the number only proves the symptom is gone. It says nothing about the mechanism. Find out what state the test shares with others: a module global, a database row, a clock, an environment variable, or test execution order.
pytest -p no:randomly tests/billing/ && pytest -p randomly tests/billing/ # compare order sensitivity
For a race, ask what two actors read and write and in what order. A lock that serialises the critical section is a fix. A retry that hides the second writer is not.
Interviewers probe whether you can tell a masked symptom from a removed cause. A weak answer is "I added a retry and it stopped failing."
Narrating the session to the interviewer
The interviewer is evaluating your process as much as your patch, so narrate it as it happens. Say what you are about to check, what you expect, and what you observed. When the assistant proposes something, say whether you accept it and why. When you reject a suggestion, say what evidence led you to reject it.
Keep the narration specific. "Checking the leap-year branch because the failure only occurs for February start dates" is useful. "Let me look at this" is not.
At the end, give a short account: the reproduction, the root cause in one sentence, the patch, the verification you ran and its result, and any residual risk you did not test. Stating the residual risk is often what interviewers remember most, because it shows you knew where the boundary of your verification was.
A candidate who can say "I verified the proration fix against the reproducing test and the billing suite, and I did not test the leap-year path under the timezone change, which is the next thing I would check" has shown the judgment the round exists to measure.