Debugging by Reading Source Code
When a problem comes up, read the source to locate it rather than relying on others. Interviewers will often ask you to tell a real story, or to debug a bug on the spot.
Core concepts: the five-step method
1. Symptom: describe it precisely (input, expected, actual, full error text, versions, frequency)
2. Minimal reproduction: strip out unrelated code until only the fewest steps that trigger the problem remain
3. Hypotheses: list 2–3 possible causes based on the stack trace and symptoms
4. Locate: verify the hypotheses by reading source / breakpoints / logs, and find the line of code where the root cause lies
5. Fix and prevent: fix + regression test + (for third-party issues) file an issue / PR or add a guardHow it works: finding the relevant source quickly
| Technique | How |
|---|---|
| Go to definition | Jump into third-party library source in your IDE (site-packages / node_modules) |
| Walk the stack frame by frame | Start from the last frame in your own code and read downward to where the library raises |
| Search for the error text | Search the library source or GitHub repo for the exact error message |
| Print the runtime path | python -c "import anthropic; print(anthropic.__file__)" to confirm which version is actually loaded |
| Breakpoint debugging | Python's breakpoint() / pdb, the VS Code debugger; Chrome DevTools on the frontend |
| Version differences | Read the library's CHANGELOG / Release Notes and diff the source before and after the upgrade |
| Find where it was introduced | git log -S "key code" to see when a piece of code appeared; git bisect to binary-search for the commit that introduced the bug |
In practice: an example investigation (demonstrating the method, not a real incident)
Symptom: after release, occasional "LLM call timed out after 30 seconds", yet the logs show the same request was actually sent 3 times.
- Reproduce: locally, use a mock server that returns 529 for the first request and watch the request count.
- Hypotheses: ① our tenacity retries ② retries inside the SDK ③ both stacked.
- Locate: read the client base class in the SDK source and find the default
max_retriesand the function that decides whether to retry (which status codes it checks, whether it readsretry-after). Confirm the SDK retries twice by default, and that we have retries on the outside as well. - Root cause: two layers of retries stacked, and the outer timeout didn't account for the SDK's internal retry waits.
- Fix: set
max_retries=0at the SDK layer and control retries centrally in the Gateway; add logs and metrics for "every actual HTTP request"; write a test asserting the request count.
In an interview, tell your own real experience in this structure, focusing on how you found the place in the source and the chain of evidence.
Common pitfalls
- Reading source without confirming the version: you read GitHub's main branch while an older version is installed.
- Changing code to "see what happens" straight away: no hypotheses or verification, just luck.
- A reproduction that isn't minimal: too many unrelated factors, so the conclusion can't be trusted.
- No test after the fix: the same problem comes back.
Common interview questions
- Tell me about a problem you located by reading source code: symptom, hypotheses, how you found the relevant code, root cause, fix.
- A third-party library throws an error you don't understand. What are your debugging steps?
- How do you find which commit introduced a bug?
- What does the request handling chain FastAPI → Starlette → uvicorn look like? (See How async def and def Routes Execute)
- Where in the source are the default retry and timeout values of the OpenAI / Anthropic SDKs defined? (See LLM API Integration)
