FAILURE MAP
← Case archive

FA-7081 / Network routing / Open access

Longest prefix route wins over first matching route · case 01

Longest prefix route wins over first matching route.

Verified by executionVariant 1 · 4 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

The faulty implementation uses `next((r for r in routes if ipaddress.ip_address(address) in ipaddress.ip_network(r)),None)` for the longest-prefix-route-wins-over-first-matching-route decision.

VERIFIED REPAIR

Apply the explicit longest-prefix-route-wins-over-first-matching-route contract, including the tested boundary and negative cases.

Unsuccessful approach: The attempted repair uses `max(routes,key=lambda r:ipaddress.ip_network(r).prefixlen) if routes else None` and still violates a separate fixture.

Case contract

Bounded offline decision model: longest prefix route wins over first matching route. Inputs are already validated protocol fields; the explicit fixtures define the supported policy, not a complete protocol implementation.

Why this case matters

This deterministic network routing model isolates the longest-prefix-route-wins-over-first-matching-route policy at a network component boundary.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import ipaddress
import re
from urllib.parse import urlsplit, urljoin
N = 1
observations = []
def solve(address, routes):
    return next((r for r in routes if ipaddress.ip_address(address) in ipaddress.ip_network(r)),None)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_fixtures = ["check('fixture 1', solve('10.1.2.3', ['0.0.0.0/0', '10.0.0.0/8']), '10.0.0.0/8')", "check('fixture 2', solve('192.0.2.1', ['10.0.0.0/8']), None)", "check('fixture 3', solve('10.1.2.3', []), None)", "check('fixture 4', solve('10.1.2.3', ['10.0.0.0/8']), '10.0.0.0/8')"]
for _line in _fixtures[N % len(_fixtures):] + _fixtures[:N % len(_fixtures)]:
    exec(_line)
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 fixtureActualExpectedOutcome
fixture 2NoneNonePassed
fixture 3NoneNonePassed
fixture 410.0.0.0/810.0.0.0/8Passed
fixture 10.0.0.0/010.0.0.0/8Failed

SHA-256 / 32fc2d78b43a6efe923907267abc42fb18c64e4cb8bc4b5cdf6088da3a99b464

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import ipaddress
import re
from urllib.parse import urlsplit, urljoin
N = 1
observations = []
def solve(address, routes):
    return max(routes,key=lambda r:ipaddress.ip_network(r).prefixlen) if routes else None
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_fixtures = ["check('fixture 1', solve('10.1.2.3', ['0.0.0.0/0', '10.0.0.0/8']), '10.0.0.0/8')", "check('fixture 2', solve('192.0.2.1', ['10.0.0.0/8']), None)", "check('fixture 3', solve('10.1.2.3', []), None)", "check('fixture 4', solve('10.1.2.3', ['10.0.0.0/8']), '10.0.0.0/8')"]
for _line in _fixtures[N % len(_fixtures):] + _fixtures[:N % len(_fixtures)]:
    exec(_line)
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 fixtureActualExpectedOutcome
fixture 210.0.0.0/8NoneFailed
fixture 3NoneNonePassed
fixture 410.0.0.0/810.0.0.0/8Passed
fixture 110.0.0.0/810.0.0.0/8Passed

SHA-256 / 1501e8e5560b3771d344d1a5365e4b35bc2458da3b968f4443cd575ad7faf454

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
import ipaddress
import re
from urllib.parse import urlsplit, urljoin
N = 1
observations = []
def solve(address, routes):
    return max((r for r in routes if ipaddress.ip_address(address) in ipaddress.ip_network(r)), key=lambda r:ipaddress.ip_network(r).prefixlen, default=None)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_fixtures = ["check('fixture 1', solve('10.1.2.3', ['0.0.0.0/0', '10.0.0.0/8']), '10.0.0.0/8')", "check('fixture 2', solve('192.0.2.1', ['10.0.0.0/8']), None)", "check('fixture 3', solve('10.1.2.3', []), None)", "check('fixture 4', solve('10.1.2.3', ['10.0.0.0/8']), '10.0.0.0/8')"]
for _line in _fixtures[N % len(_fixtures):] + _fixtures[:N % len(_fixtures)]:
    exec(_line)
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 fixtureActualExpectedOutcome
fixture 2NoneNonePassed
fixture 3NoneNonePassed
fixture 410.0.0.0/810.0.0.0/8Passed
fixture 110.0.0.0/810.0.0.0/8Passed

SHA-256 / ab427c182d93a30860ff39422844de6c5dd8244b3adb043dc2c29ba63a2cffb9

Verification & scope

Bounded deterministic policy model over validated inputs; not a complete protocol stack or an interoperability claim. The five variants rotate the same explicit fixture set. 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:38:08.102411+00:00.

Case digest / fd87177df7608b88e2856ea10dfc427fc871ae99e6a2fe4656bc584474168d92