esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
Let’s talk

I’ll build the agent for it.

Re-Engineering Round: Fix Bugs in Unfamiliar Code

How to find and fix a bug in code you have never seen: reproduce it, find the cause, fix it once, and prove it stays fixed, for your AI interview.

In short

Don't start by editing. Reproduce the bug first, find its cause with evidence, make the smallest fix, then add a test so the bug can't return quietly. Each step is one you can say out loud.

12 min readIntermediateCommon · estimateFacts checked 27 November 2026

Say it out loud

Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.

In this round you get code I have never seen and a bug report. I don't start by editing. First I reproduce the bug, so I can watch it fail. Then I find the cause with evidence, using a debugger or a log line, not a guess. I make the smallest fix in the right place, check the other places that call it, and add a test that fails before the fix and passes after. I say each step out loud as I go.

What is a re-engineering round, in plain words?

In this kind of round you may get a small codebase you have never seen, a bug report, and a time limit. Plan to show how you work: how you find the bug, how you prove it, and how you fix it without breaking anything else.

Think of a mechanic handed a stranger's car with a strange noise. A good one doesn't swap parts first. They listen, reproduce the noise, check the likely causes, then fix one thing and drive the car again.

In an AI codebase the same steps apply: a retrieval function returns the wrong document for a customer, and you reproduce it with that one question before touching the code.

Ask the recruiter which language and tools you may use. The example below is made up, but the steps are the ones that count.

Key words

Reproduce
Make the bug happen again on purpose, with the smallest input you can.
Root cause
The real reason the bug happens, not just the line where it shows up.
Stack trace
The list of calls that led to an error, printed when the code fails.
Regression test
A test that fails on the bug, so the same bug can't come back unnoticed.

What is the method, step by step?

Do the steps in order. Each one stops you from guessing.

  1. 1

    Read the report

    Write down the exact input, the expected result and the actual result. A vague report wastes the round.

  2. 2

    Reproduce it

    Run the smallest input that shows the bug. If you can't make it fail, you can't prove a fix.

  3. 3

    Find the cause with evidence

    Use a debugger, a log line or the stack trace to see the real values. Change one thing at a time.

  4. 4

    Fix the cause once

    Change the code where the mistake is. Keep the change small enough to explain in one sentence.

  5. 5

    Check the other callers

    Search for the same pattern elsewhere. One bug often has siblings.

  6. 6

    Prove it with a test

    The test fails before the fix and passes after. Then run the whole test set, not only the new test.

From bug report to a proven fix

Bug report

a user sees a wrong result

Reproduce it

the smallest input that fails

Find the cause

values from a debugger, not guesses

Fix it once

change the place the mistake is

Prove it with a test

fails before, passes after

  1. 1You turn the report into a run you can repeat.
  2. 2Once the bug fails on cue, you look for its cause.
  3. 3You make one small fix in the place the mistake is.
  4. 4A test that fails before and passes after proves it.
The main path from a bug report to a proven fix: reproduce it, find the cause with evidence, fix it once, then prove it with a test that fails before and passes after. The written method also checks the other callers before the test.

Which tools find the cause fastest?

If the round uses Python, it ships with its own tools, so you need nothing extra in the room. Start with the error message. Errors that happen while a program runs are called exceptions. The stack trace shows the calls that led to one.

  • A print or a log line

    The fastest check, fine for a small fix. Remove the noise before you finish. The logging guide says debug() is for very detailed output for diagnostic purposes.

  • The debugger, pdb

    Python's standard debugger. It pauses the code at a line you choose and lets you step line by line. In code, breakpoint() opens it at the line where it is called. Inside the pause you can look at the stack and run Python code.

  • The stack trace

    Read it from the bottom: the last line names the error, and the lines above show the calls that led to it.

  • A unit test

    A small check that fails on the bug. The unittest module in the standard library runs these tests.

Tip

Say which tool you chose and why. Values that change across calls, for example, are a good reason to pick the debugger.

How do you trace a real bug to its cause?

Here is the worked case in plain Python. Two claims call the same function, and the second claim's file appears on the first claim.

Python
# Claims intake at a mid-size insurer. Each claim should get its own attachment list.
def attach(claim_id, file_name, attachments=[]):  # the bug: one list is shared by every call
    attachments.append(file_name)
    return {"claim": claim_id, "attachments": attachments}

def attach_fixed(claim_id, file_name, attachments=None):
    if attachments is None:
        attachments = []  # a new list for each claim
    attachments.append(file_name)
    return {"claim": claim_id, "attachments": attachments}

a = attach("CL-1001", "photo-front.jpg")
b = attach("CL-1002", "repair-quote.pdf")
print("CL-1001:", a["attachments"])
print("CL-1002:", b["attachments"])
print("Same list object:", a["attachments"] is b["attachments"])

c = attach_fixed("CL-1003", "police-report.pdf")
d = attach_fixed("CL-1004", "invoice.pdf")
print("CL-1003:", c["attachments"])
print("CL-1004:", d["attachments"])

Output

CL-1001: ['photo-front.jpg', 'repair-quote.pdf']
CL-1002: ['photo-front.jpg', 'repair-quote.pdf']
Same list object: True
CL-1003: ['police-report.pdf']
CL-1004: ['invoice.pdf']

The first three lines of output show the bug: both claims hold both files. The third line, True, means both names point at one list object, which is one list in memory. The cause is the empty list default in the first line of the function, the part that names its inputs. Python makes that default once, so every call that skips the argument adds to the same list.

How one default list leaks between claims

Claim CL-1001

adds a photo of the car

Claim CL-1002

adds a repair quote

attach() call

the default [] is made once

One shared list

both claims write into it

CL-1001 gets the quote

a wrong file on a claim

  1. 1Claim 1001 calls attach() with its photo.
  2. 2Claim 1002 calls the same function with its quote.
  3. 3Both calls add to one list, made once when the def ran.
  4. 4Claim 1001 now shows the quote from claim 1002.
Both claims write into one list, because the default was made once. Each call returns that same list, so claim CL-1001 ends up with the quote from CL-1002.
  • “The default value is evaluated only once.”

    Python tutorial, default argument values

  • “This function drops you into the debugger at the call site.”

    Python standard library, breakpoint()

The fix is in the smallest place: default to None, and make a fresh list inside the function when the argument is None. Then search the codebase for the same pattern, and add a test that calls the function twice and checks that each claim has only its own file. The second half of the script already shows that result.

Tip

Read the function before you change it. Editing first would have hidden the cause.

How would you fix code that has no tests?

Write a small test that records what the code does now, even if you suspect it is wrong. Run it before you change anything. Then your fix shows up as a change you chose, not a surprise.

  1. 1

    Pick one input

    Use the report's input, or the smallest input that shows the bug.

  2. 2

    Record the output

    Save what the code returns today. That is your starting point.

  3. 3

    Fix, then compare

    Change the cause, run the test again, and explain every difference.

Tip

Name the risk out loud: without a test, the same bug can come back.

What does the interviewer want to hear?

A strong answer covers

  • A method you follow every time: read, reproduce, find the cause, fix, prove.
  • Evidence for the cause: a debugger, a log or the stack trace, not a guess.
  • A small fix in the right place, and a check of the other callers.
  • A test that fails before the fix and passes after.
  • Clear talk about what you did not check, and what you would check next.
  • The reason behind each change, said in one sentence.

Common traps

  • Trap"Rewrite the whole module, it's faster."

    BetterA rewrite can add new bugs and hide the cause. Fix the cause in the smallest place, then check the callers.

  • Trap"It works now, so I'm done."

    BetterShow the test that failed before and passes now, and say what else you ran.

  • Trap"This line looked wrong, so I changed it."

    BetterGuesses waste the clock. Reproduce first, then use a debugger or a log to see the real values.

Palantir's interview post, which collects advice from its own team members, makes a similar point:

  • “You don't need to remember the algorithm to a question.”

    Palantir blog, a team member's account

  • “One thing I found really helpful was the technique of deconstructing a problem and articulating how you would address it step-by-step.”

    Palantir blog, a team member's advice

Can you spot the bug?

Spot the bug

A teammate sent four small functions. Which one causes claims to share files?

Quick check

A bug appears only when many users hit the app at once. What is the best first step?

Can you answer these from memory?

Flash cards · tap a card to flip it

1 / 6

What will they ask next?

  1. Q402Learning round: pick up a new codebase or API fast.13 min
  2. Q151"The answer was in the docs, but the bot missed it." How do you debug?12 min
  3. Q190How do you trace and debug an agent run?11 min
  4. Q484Refactor messy code into testable code.10 min
  5. Q485Write tests and evals for an LLM function.12 min
  6. Q275Eval scores dropped but the model is unchanged. How do you debug?12 min

Last updated on 27 November 2026

Got a bug you can't trace?

I design and build AI products and agents, the UI and the system behind them. Book a short call and tell me what is broken and what you need fixed.