Default Country Roulette — Python Bug Hunt
Inspired by the SMS-delivery mysteries every messaging integration debugs eventually: a UK number arrives as +44 20 7946 0958, the normaliser slaps the…
- Language: Python
- Layer: Backend
- Difficulty: Medium
- Concepts: Parsing, Phones
- Modelled on: Twilio-class SMS
- Visible tests: international numbers keep their code; national numbers get the default code; double-zero prefixes convert to plus
- Reward: 50 XP for a complete fix
Incident
- Severity: SEV-2 (priority: High)
- Ticket: BUG-E164
- Reported by: OTP delivery
- Time to fix: 20 minutes, the target for a medium incident
Failing checks on the shipped build
- international numbers keep their code — expected "+442079460958" but got "+1+442079460958"
- double-zero prefixes convert to plus — expected "+4930901820" but got "+1004930901820"
How to work this incident
- Read the report: write down the expected behaviour and the actual one in a sentence each.
- Reproduce it: run the visible tests and find the failing check that matches the report.
- Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
- Follow the request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
- Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.
Briefing
Inspired by the SMS-delivery mysteries every messaging integration debugs eventually: a UK number arrives as +44 20 7946 0958, the normaliser slaps the default +1 in front anyway, and the OTP heads to a very confused landline in Kansas.
phone.py normalises to E.164.
Bug report
BUG-E164 · Priority: High · Reported by: OTP delivery
normalize(raw, default_cc="+1"):
- strip spaces, dashes, dots and parentheses
- already starts with "+" -> keep its country code
- starts with "00" -> replace the 00 with "+"
- bare national number -> prefix default_cc
- anything with letters/other symbols -> raise ValueError
Observed: every already-international number gets ANOTHER country code.
Logs
[sms] normalize("+44 20 7946 0958") -> "+1+442079460958" -> undeliverableThe code as shipped
src/sms/phone.py (editable)
# Normalises phone numbers to E.164.
def normalize(raw, default_cc="+1"):
cleaned = raw.replace(" ", "").replace("-", "").replace("(", "").replace(")", "").replace(".", "")
return default_cc + cleaned
Open the hunt to start the incident clock, edit the files, run the visible tests and submit against the hidden ones, then write the root cause down. More Python bug hunts.