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.

Read
11 min
Practice MCQs
24
Interview Q&A
25
Edition
v1
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..

Curated: · Written: · Reviewed:

24 questions · Flow follows Relevance until this set has a learning order.

MCQ-1A checkout service logs a NullPointerException at `OrderTotals.applyCoupon` (line 142) on about 1 in 300 orders. The assistant proposes a null guard at that line and calls it safe. The existing suite passes on main, but no test applies a coupon to an order with no tax region. What should you do before accepting the patch?
MCQ-2A candidate is debugging a duplicate-charge bug in one payment-retry function inside a 400-file legacy repository. Given the whole repo, the assistant keeps blaming a logging helper that the retry path never calls. Which context should the candidate send next?
MCQ-3A Flask-style service's refund handler reaches `Ledger.write` without the tenant tax check. The assistant's call graph, built from static reads, shows `handler` to `RefundService.issue` to `Ledger.write` and omits a stage registered with `@pipeline_stage(order=2)`. The dispatcher runs stages through `getattr(stage_module, name)` for names in a config list, and you can run one failing request locally. Which check verifies the map?
MCQ-4A legacy Python module defines `class Ledger:` with `entries = []` in the class body and an `add(self, amount)` method that runs `self.entries.append(amount)`. Two Ledger objects built for different customers in one request show each other's entries, and a second test sees the first test's entries. Which change scopes the state to each instance?
MCQ-5A legacy Python invoicing service totals invoice 4417 0.01 higher than its printed line items. The lines before tax are 0.125, 0.125 and 2.50, each line's tax is rounded with `round()`, and the total is summed from unrounded values. An AI assistant ranks float drift in the running sum first. Which check tells the two causes apart?
MCQ-6A nightly batch job runs for six hours over about 2 million rows, and a wrong total appears only on a few rows in the output at the end. The job cannot be paused or stepped through interactively. What do you add to the job first?
MCQ-7A regression lies somewhere in 400 commits between a good tag and a bad one, and bisect will take about nine steps. The target test fails on the bad commit about one run in four and has never failed on a good commit. Each commit gets the same fixed number of runs, and a commit is marked good only if every run passes. What is the fewest runs per commit that keeps the chance of landing on a wrong commit anywhere in the search under 5%?
MCQ-8A legacy Python refund service calls the billing SDK with `charge(amount, idempotency_key=key)`, a line the assistant wrote. The lockfile pins `billing-sdk` 3.4.2, and the changelog says `idempotency_key` arrived in 3.6.0. The suite passes because its client is a MagicMock that accepts any keyword, and staging installs from the lockfile. Which check shows whether the call is valid where it actually runs?
MCQ-9An AI assistant fixes a bug where SKUs with trailing spaces miss the lookup in a legacy Python warehouse importer by stripping input in `load_sku(code)`. Its diff also makes a blank code raise `KeyError` from a dict lookup instead of `ValueError` from `int('')`. The nightly import catches `ValueError` per row and skips bad rows, so one blank row now aborts the run. What do you do with the patch?
MCQ-10A patch makes the new test for `load_rates` pass. An untouched report module calls `len(load_rates(region))`, which used to receive `[]` for a region with no rates, and the patch now returns `None` for that region. What does that `len()` call do after the patch?
MCQ-11A patch branch fails `test_split_tax_on_refund` in CI, asserting 1199 cents where 1200 is expected. On a clean checkout of the parent commit the same test also fails with 1199, yet main passes it, and only when the tax-table cache is warm. Which step settles whether the failure predates the patch?
MCQ-12A legacy Python service has a worker thread that appends to a module-level list `_pending`. An assistant added `time.sleep(2)` before the assert in `test_export_flushes`. Run alone, the test passes every time. Run after `test_bulk_import` in the same module, the assertion sees 7 items where 3 were expected, and the extra four are bulk-import rows. Which fix addresses this failure?
MCQ-13A checkout service runs 12 worker processes across 3 hosts. `charge_order(order_id)` selects from `charges` for the order, and if no row exists it calls the card processor, then inserts the charge row. The processor takes no idempotency key and `charges` has no unique constraint on `order_id`. About 0.3% of orders are charged twice, only when the pool is saturated. Which change stops the second charge?
MCQ-14A test module fills a module-level dict in `load_rates`, and `test_quote_defaults` fails only when it runs after `test_bulk_discount`. Which one-line fixture change makes `test_quote_defaults` see an empty dict every time?
MCQ-15A pricing service raises decimal.InvalidOperation in `Decimal.quantize` at invoice.py:88 for about 1 in 500 invoices. The traceback has no chained cause, and the failing amount reaches pricing as the signalling NaN `sNaN`, which the ingest service writes only when a feature flag is off. Pricing sits two services downstream of ingest.
MCQ-16A nightly export in a legacy Python billing service puts about 40 rows a night into the wrong day bucket. Every bad row has a naive local timestamp between 01:00 and 02:00 on 1 November 2026. Only the two hosts with TZ set to America/Chicago fail, and the three UTC hosts are clean. An assistant blames the timezone conversion and offers a rewrite that stores UTC everywhere. Before you accept the rewrite, which check settles the hypothesis?
MCQ-17A CI run fails with `TypeError: allocate() got an unexpected keyword argument 'rounding'` at the call in `invoice_split.py`. The same commit passes on your laptop. Both runs report `ledgerkit` 2.8.1, the version in the lockfile, and the branch's code passes `rounding=` to `allocate()`. What do you check first?
MCQ-18A legacy helper `initials(name)` returns the first letter of each word, and the assistant's fix was checked only against `'Ada Lovelace'`. Production failures hit the empty string and names with accented letters such as `'Émile Zola'`. Which rows should the table-driven test add to cover the failing input space?
MCQ-19A fulfilment consumer on RabbitMQ acks each `order.paid` message only after its shipment call returns. The producer confirms publishes with a 5-second timeout and, on timeout, republishes with a fresh message ID and a fresh correlation ID. The body keeps `order_id` and `parcel_line_id`. Duplicate shipments for parcel line 2 of order 4417 appear only during deploys. Which change stops them while keeping split parcels legal?
MCQ-20While fixing a one-cent refund rounding bug in a legacy Python service, you see `sql = "SELECT * FROM orders WHERE ref = '" + ref + "'"` in an export route, where `ref` comes straight from the request query string. The refund fix does not touch that route. Which evidence should go into the security flag you send with the patch?
MCQ-21A nightly SKU sync in a legacy Python service calls `upsert_sku(row)` inside a try block whose `except KeyError` logs a WARNING and skips the row. The log holds about 90,000 such lines a night, and 0.4% of rows lack a field. An assistant's patch deletes the except so the noise stops, and the job now exits at row 312 with 60,000 rows unsynced. What is the targeted fix?
MCQ-22A candidate's AI-assisted patch fixes a one-cent refund rounding bug. The targeted test for the reported case passes, and the module's full suite has not been run on this branch. What is the accurate statement of what the candidate has verified?
MCQ-23A legacy Python export module drops the final row whenever the row count is an exact multiple of 50. The bug is an off-by-one in `page_bounds(total, page)`, which returns `(start, end)`, and all 14 callers read only `[0]`. The assistant wants to rewrite the 2,300-line module as a generator-based pager before fixing anything. CI takes six minutes and the release freeze is in one hour. What do you ship before the freeze?
MCQ-24Round two gives you 35 minutes on a 300-file legacy pricing module. Your assistant has been generating a full-file rewrite for four minutes and has produced nothing you can check. Your working hypothesis is that the half-cent is lost in the discount step, and one print statement plus a 10-second test run can confirm or kill it. What do you do now?