FA-96701 / Phone number formatting / Open access
Emergency and service code classifier: emergency codes are matched as prefixes · case 01
Service code "1331" is classified as emergency.
ROOT CAUSE
The emergency list is matched with startswith.
THE FAILURE
The emergency list is matched with startswith.
Unsuccessful approach: Also matching the code after stripping trunk zeros turns "0133" into an emergency call.
Case contract
Input [dialed, country] with toy tables AA (emergency 133/144, service = 4 digits starting 1, trunk 0, 9 national digits) and BB (emergency 755, service = 3 digits starting 7, no trunk, 7 national digits). Remove spaces; strip any number of leading "*NN" feature codes into tags. The rest must be digits. Classify in order: exact emergency code, service code, then a national number (trunk required and removed when the country has one). Return tags + [class].
Why this case matters
Emergency and short service codes must be recognized before any national formatting, or emergency calls are rewritten or blocked.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
s, country = x
T = {'AA': {'emergency': ('133', '144'), 'svc': '1', 'svc_len': 4, 'trunk': '0', 'nsn': 9},
'BB': {'emergency': ('755',), 'svc': '7', 'svc_len': 3, 'trunk': '', 'nsn': 7}}
c = T[country]
tags = []
s = s.replace(' ', '')
while s.startswith('*') and len(s) >= 3 and s[1:3].isdigit():
tags.append('feature:' + s[1:3])
s = s[3:]
if not s.isdigit():
return tags + ['invalid']
if any(s.startswith(e) for e in c['emergency']):
return tags + ['emergency']
if s.startswith(c['svc']) and len(s) == c['svc_len']:
return tags + ['service']
if c['trunk'] and s.startswith(c['trunk']):
s = s[len(c['trunk']):]
elif c['trunk']:
return tags + ['invalid']
return tags + (['national'] if len(s) == c['nsn'] else ['invalid'])
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['emergency code', ['133', 'AA'], ['emergency']], ['emergency code inside the service range', ['755', 'BB'], ['emergency']], ['feature code before emergency code', ['*67 755', 'BB'], ['feature:67', 'emergency']], ['service code sharing the emergency prefix', ['1331', 'AA'], ['service']], ['trunk before an emergency code', ['0133', 'AA'], ['invalid']], ['two feature codes', ['*67*82 0555010111', 'AA'], ['feature:67', 'feature:82', 'national']], ['national number without trunk', ['555010111', 'AA'], ['invalid']], ['too short for a service code', ['11', 'AA'], ['invalid']], ['too long for a service code', ['11111', 'AA'], ['invalid']], ['hash inside a number', ['5550#11', 'BB'], ['invalid']], ['BB national number', ['555 0111', 'BB'], ['national']], ['BB service code', ['712', 'BB'], ['service']]], [['emergency code', ['133', 'AA'], ['emergency']], ['emergency code inside the service range', ['755', 'BB'], ['emergency']], ['feature code before emergency code', ['*67 755', 'BB'], ['feature:67', 'emergency']], ['service code sharing the emergency prefix', ['1332', 'AA'], ['service']], ['trunk before an emergency code', ['0133', 'AA'], ['invalid']], ['two feature codes', ['*67*82 0555010222', 'AA'], ['feature:67', 'feature:82', 'national']], ['national number without trunk', ['555010222', 'AA'], ['invalid']], ['too short for a service code', ['12', 'AA'], ['invalid']], ['too long for a service code', ['12222', 'AA'], ['invalid']], ['hash inside a number', ['5550#12', 'BB'], ['invalid']], ['BB national number', ['555 0122', 'BB'], ['national']], ['BB service code', ['723', 'BB'], ['service']]], [['emergency code', ['133', 'AA'], ['emergency']], ['emergency code inside the service range', ['755', 'BB'], ['emergency']], ['feature code before emergency code', ['*67 755', 'BB'], ['feature:67', 'emergency']], ['service code sharing the emergency prefix', ['1333', 'AA'], ['service']], ['trunk before an emergency code', ['0133', 'AA'], ['invalid']], ['two feature codes', ['*67*82 0555010333', 'AA'], ['feature:67', 'feature:82', 'national']], ['national number without trunk', ['555010333', 'AA'], ['invalid']], ['too short for a service code', ['13', 'AA'], ['invalid']], ['too long for a service code', ['13333', 'AA'], ['invalid']], ['hash inside a number', ['5550#13', 'BB'], ['invalid']], ['BB national number', ['555 0133', 'BB'], ['national']], ['BB service code', ['734', 'BB'], ['service']]], [['emergency code', ['133', 'AA'], ['emergency']], ['emergency code inside the service range', ['755', 'BB'], ['emergency']], ['feature code before emergency code', ['*67 755', 'BB'], ['feature:67', 'emergency']], ['service code sharing the emergency prefix', ['1334', 'AA'], ['service']], ['trunk before an emergency code', ['0133', 'AA'], ['invalid']], ['two feature codes', ['*67*82 0555010444', 'AA'], ['feature:67', 'feature:82', 'national']], ['national number without trunk', ['555010444', 'AA'], ['invalid']], ['too short for a service code', ['14', 'AA'], ['invalid']], ['too long for a service code', ['14444', 'AA'], ['invalid']], ['hash inside a number', ['5550#14', 'BB'], ['invalid']], ['BB national number', ['555 0144', 'BB'], ['national']], ['BB service code', ['745', 'BB'], ['service']]], [['emergency code', ['133', 'AA'], ['emergency']], ['emergency code inside the service range', ['755', 'BB'], ['emergency']], ['feature code before emergency code', ['*67 755', 'BB'], ['feature:67', 'emergency']], ['service code sharing the emergency prefix', ['1335', 'AA'], ['service']], ['trunk before an emergency code', ['0133', 'AA'], ['invalid']], ['two feature codes', ['*67*82 0555010555', 'AA'], ['feature:67', 'feature:82', 'national']], ['national number without trunk', ['555010555', 'AA'], ['invalid']], ['too short for a service code', ['15', 'AA'], ['invalid']], ['too long for a service code', ['15555', 'AA'], ['invalid']], ['hash inside a number', ['5550#15', 'BB'], ['invalid']], ['BB national number', ['555 0155', 'BB'], ['national']], ['BB service code', ['756', 'BB'], ['service']]]]
for label, arg, expected in fixtures[N - 1]:
check(label, solve(arg), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| emergency code | ['emergency'] | ['emergency'] | Passed |
| emergency code inside the service range | ['emergency'] | ['emergency'] | Passed |
| feature code before emergency code | ['feature:67', 'emergency'] | ['feature:67', 'emergency'] | Passed |
| service code sharing the emergency prefix | ['emergency'] | ['service'] | Failed |
| trunk before an emergency code | ['invalid'] | ['invalid'] | Passed |
| two feature codes | ['feature:67', 'feature:82', 'national'] | ['feature:67', 'feature:82', 'national'] | Passed |
| national number without trunk | ['invalid'] | ['invalid'] | Passed |
| too short for a service code | ['invalid'] | ['invalid'] | Passed |
| too long for a service code | ['invalid'] | ['invalid'] | Passed |
| hash inside a number | ['invalid'] | ['invalid'] | Passed |
| BB national number | ['national'] | ['national'] | Passed |
| BB service code | ['service'] | ['service'] | Passed |
SHA-256 / 93749f4c94ba52b20c75a74c0704a491419a7ca18cda2b78c1677ae33e9180d8
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
s, country = x
T = {'AA': {'emergency': ('133', '144'), 'svc': '1', 'svc_len': 4, 'trunk': '0', 'nsn': 9},
'BB': {'emergency': ('755',), 'svc': '7', 'svc_len': 3, 'trunk': '', 'nsn': 7}}
c = T[country]
tags = []
s = s.replace(' ', '')
while s.startswith('*') and len(s) >= 3 and s[1:3].isdigit():
tags.append('feature:' + s[1:3])
s = s[3:]
if not s.isdigit():
return tags + ['invalid']
if s in c['emergency'] or s.lstrip('0') in c['emergency']:
return tags + ['emergency']
if s.startswith(c['svc']) and len(s) == c['svc_len']:
return tags + ['service']
if c['trunk'] and s.startswith(c['trunk']):
s = s[len(c['trunk']):]
elif c['trunk']:
return tags + ['invalid']
return tags + (['national'] if len(s) == c['nsn'] else ['invalid'])
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['emergency code', ['133', 'AA'], ['emergency']], ['emergency code inside the service range', ['755', 'BB'], ['emergency']], ['feature code before emergency code', ['*67 755', 'BB'], ['feature:67', 'emergency']], ['service code sharing the emergency prefix', ['1331', 'AA'], ['service']], ['trunk before an emergency code', ['0133', 'AA'], ['invalid']], ['two feature codes', ['*67*82 0555010111', 'AA'], ['feature:67', 'feature:82', 'national']], ['national number without trunk', ['555010111', 'AA'], ['invalid']], ['too short for a service code', ['11', 'AA'], ['invalid']], ['too long for a service code', ['11111', 'AA'], ['invalid']], ['hash inside a number', ['5550#11', 'BB'], ['invalid']], ['BB national number', ['555 0111', 'BB'], ['national']], ['BB service code', ['712', 'BB'], ['service']]], [['emergency code', ['133', 'AA'], ['emergency']], ['emergency code inside the service range', ['755', 'BB'], ['emergency']], ['feature code before emergency code', ['*67 755', 'BB'], ['feature:67', 'emergency']], ['service code sharing the emergency prefix', ['1332', 'AA'], ['service']], ['trunk before an emergency code', ['0133', 'AA'], ['invalid']], ['two feature codes', ['*67*82 0555010222', 'AA'], ['feature:67', 'feature:82', 'national']], ['national number without trunk', ['555010222', 'AA'], ['invalid']], ['too short for a service code', ['12', 'AA'], ['invalid']], ['too long for a service code', ['12222', 'AA'], ['invalid']], ['hash inside a number', ['5550#12', 'BB'], ['invalid']], ['BB national number', ['555 0122', 'BB'], ['national']], ['BB service code', ['723', 'BB'], ['service']]], [['emergency code', ['133', 'AA'], ['emergency']], ['emergency code inside the service range', ['755', 'BB'], ['emergency']], ['feature code before emergency code', ['*67 755', 'BB'], ['feature:67', 'emergency']], ['service code sharing the emergency prefix', ['1333', 'AA'], ['service']], ['trunk before an emergency code', ['0133', 'AA'], ['invalid']], ['two feature codes', ['*67*82 0555010333', 'AA'], ['feature:67', 'feature:82', 'national']], ['national number without trunk', ['555010333', 'AA'], ['invalid']], ['too short for a service code', ['13', 'AA'], ['invalid']], ['too long for a service code', ['13333', 'AA'], ['invalid']], ['hash inside a number', ['5550#13', 'BB'], ['invalid']], ['BB national number', ['555 0133', 'BB'], ['national']], ['BB service code', ['734', 'BB'], ['service']]], [['emergency code', ['133', 'AA'], ['emergency']], ['emergency code inside the service range', ['755', 'BB'], ['emergency']], ['feature code before emergency code', ['*67 755', 'BB'], ['feature:67', 'emergency']], ['service code sharing the emergency prefix', ['1334', 'AA'], ['service']], ['trunk before an emergency code', ['0133', 'AA'], ['invalid']], ['two feature codes', ['*67*82 0555010444', 'AA'], ['feature:67', 'feature:82', 'national']], ['national number without trunk', ['555010444', 'AA'], ['invalid']], ['too short for a service code', ['14', 'AA'], ['invalid']], ['too long for a service code', ['14444', 'AA'], ['invalid']], ['hash inside a number', ['5550#14', 'BB'], ['invalid']], ['BB national number', ['555 0144', 'BB'], ['national']], ['BB service code', ['745', 'BB'], ['service']]], [['emergency code', ['133', 'AA'], ['emergency']], ['emergency code inside the service range', ['755', 'BB'], ['emergency']], ['feature code before emergency code', ['*67 755', 'BB'], ['feature:67', 'emergency']], ['service code sharing the emergency prefix', ['1335', 'AA'], ['service']], ['trunk before an emergency code', ['0133', 'AA'], ['invalid']], ['two feature codes', ['*67*82 0555010555', 'AA'], ['feature:67', 'feature:82', 'national']], ['national number without trunk', ['555010555', 'AA'], ['invalid']], ['too short for a service code', ['15', 'AA'], ['invalid']], ['too long for a service code', ['15555', 'AA'], ['invalid']], ['hash inside a number', ['5550#15', 'BB'], ['invalid']], ['BB national number', ['555 0155', 'BB'], ['national']], ['BB service code', ['756', 'BB'], ['service']]]]
for label, arg, expected in fixtures[N - 1]:
check(label, solve(arg), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| emergency code | ['emergency'] | ['emergency'] | Passed |
| emergency code inside the service range | ['emergency'] | ['emergency'] | Passed |
| feature code before emergency code | ['feature:67', 'emergency'] | ['feature:67', 'emergency'] | Passed |
| service code sharing the emergency prefix | ['service'] | ['service'] | Passed |
| trunk before an emergency code | ['emergency'] | ['invalid'] | Failed |
| two feature codes | ['feature:67', 'feature:82', 'national'] | ['feature:67', 'feature:82', 'national'] | Passed |
| national number without trunk | ['invalid'] | ['invalid'] | Passed |
| too short for a service code | ['invalid'] | ['invalid'] | Passed |
| too long for a service code | ['invalid'] | ['invalid'] | Passed |
| hash inside a number | ['invalid'] | ['invalid'] | Passed |
| BB national number | ['national'] | ['national'] | Passed |
| BB service code | ['service'] | ['service'] | Passed |
SHA-256 / e9c3ef8c07188fb968748eccdaaf36d1692a4a73cda66ee342d83d6a0560d3f8
HELD IN THE MEMBER ARCHIVE
The verified repair and its recorded checks are member-only.
This mechanism has 12 recorded checks per implementation. The open-access tier publishes the failure and the unsuccessful fix; the repaired source that passes every check, and the observations that prove it, are available to members.
Every case sharing this mechanism uses the same contract and the same repair, so this one record is held back for all of them.
Member access is invitation-based. Sign in with your invited account to inspect the repair.
Sign in to the archive ↗Verification & scope
A deterministic toy contract over synthetic, obviously fictitious telephone numbers and toy country tables. The rules are stipulated for this model only and make no claim of conformance with any numbering plan or telecommunications standard. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.
Observations recorded using Python 3.12.14 at 2026-09-29T14:52:25.320062+00:00.
Case digest / 2c3917711af6199b96e654a22d690c439eb047c1448328bcb3a51754eb705385