A Systematic Debugging Method for Unfamiliar Code
Apply a systematic method for debugging unfamiliar code, the core skill in Palantir's FDSE re-engineering round. Establish the expected contract, reproduce a failure while preserving the shared state that causes it, and follow the call path from the failing assertion to the earliest point where a value diverges. State a falsifiable hypothesis with controlled predictions, apply a minimal repair at the root cause instead of patching output, and add regression tests that prove what you fixed.
We'll cover the following...
A French greeting comes back in English, but only after an English greeting has already been rendered. The visible error is a string; the cause depends on state shared across calls. A disciplined investigation preserves that sequence, predicts what a competing sequence would do, and repairs the earliest contract violation it can demonstrate.
What must you establish before opening every file?
The failure report says that, in one process:
render(‘welcome’, ‘en’, ‘Ari’, cache)returns‘Hello, Ari!’.render(‘welcome’, ‘fr’, ‘Bo’, cache)returns‘Hello, Bo!’, although the expected result is‘Bonjour, Bo!’.
Establish the contract first: Locale selects the template on every call, and the recipient name is substituted afterward. Earlier calls must not change language selection. The template table is fixed, inputs identify supplied template/locale pairs, execution is sequential, and cache storage is internal to this application.
A reproduction records the input, relevant initial state, execution sequence, expected behavior, and actual behavior. Here, the initial cache is empty, and both calls share it.
Palantir identifies working inside existing systems, codebases, and infrastructure as an engineering competency; its published guidance emphasizes debugging, modifying, and extending existing code. Third-party preparation guidance recommends tracing unfamiliar code, identifying a defect, and explaining the fix before changing it. That supports this preparation exercise rather than establishing a guaranteed interview format.
How do you preserve the two-call failure?
Create an independent Python 3.12 folder containing these three files. No earlier exercise files are needed.
template_catalog.py:
TEMPLATES = {('welcome', 'en'): 'Hello, {name}!',('welcome', 'fr'): 'Bonjour, {name}!',}def load_template(template_id, locale, cache):key = template_idif key not in cache:cache[key] = TEMPLATES[(template_id, locale)]return cache[key]
Lines 1–4: Define the independently specified English and French templates.
Lines 7–8: Accept the request and choose the defective cache key.
Lines 9–11: Populate a missing entry from the table, then return the cached template.
greeting_service.py:
from template_catalog import load_templatedef render(template_id, locale, name, cache):template = load_template(template_id, locale, cache)return template.format(name=name)
Line 1: ...