Skip to content
Goal: 深入原理(方法论)✓ Sources verified 2026-11-24DebuggingMinimal Reproductiongit bisect

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 guard

How it works: finding the relevant source quickly ​

TechniqueHow
Go to definitionJump into third-party library source in your IDE (site-packages / node_modules)
Walk the stack frame by frameStart from the last frame in your own code and read downward to where the library raises
Search for the error textSearch the library source or GitHub repo for the exact error message
Print the runtime pathpython -c "import anthropic; print(anthropic.__file__)" to confirm which version is actually loaded
Breakpoint debuggingPython's breakpoint() / pdb, the VS Code debugger; Chrome DevTools on the frontend
Version differencesRead the library's CHANGELOG / Release Notes and diff the source before and after the upgrade
Find where it was introducedgit 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.

  1. Reproduce: locally, use a mock server that returns 529 for the first request and watch the request count.
  2. Hypotheses: ① our tenacity retries ② retries inside the SDK ③ both stacked.
  3. Locate: read the client base class in the SDK source and find the default max_retries and the function that decides whether to retry (which status codes it checks, whether it reads retry-after). Confirm the SDK retries twice by default, and that we have retries on the outside as well.
  4. Root cause: two layers of retries stacked, and the outer timeout didn't account for the SDK's internal retry waits.
  5. Fix: set max_retries=0 at 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 ​

  1. Reading source without confirming the version: you read GitHub's main branch while an older version is installed.
  2. Changing code to "see what happens" straight away: no hypotheses or verification, just luck.
  3. A reproduction that isn't minimal: too many unrelated factors, so the conclusion can't be trusted.
  4. No test after the fix: the same problem comes back.

Common interview questions ​

  1. Tell me about a problem you located by reading source code: symptom, hypotheses, how you found the relevant code, root cause, fix.
  2. A third-party library throws an error you don't understand. What are your debugging steps?
  3. How do you find which commit introduced a bug?
  4. What does the request handling chain FastAPI → Starlette → uvicorn look like? (See How async def and def Routes Execute)
  5. Where in the source are the default retry and timeout values of the OpenAI / Anthropic SDKs defined? (See LLM API Integration)

Sources ​

Vin Amory · AI development × content creation · Technical notes cite official docs in each page’s sources section