commaai/openpilot · error · Exception
unable to get max_segment_number. ensure you have access to
Error message
unable to get max_segment_number. ensure you have access to this route or the route is public.
What it means
get_max_seg_number_cached() calls the comma API '/v1/route/<name>' to read 'maxqlog'; any exception (auth failure, 404, network, or a non-int response) is re-raised as a generic Exception with an access hint. SegmentRange operations that expand unbounded ranges (e.g. 'route/3+') need this number.
Source
Thrown at openpilot/tools/lib/route.py:316
az_prefix = '/'.join(key.split('/')[:3])
return SegmentName.from_azure_prefix(az_prefix)
@staticmethod
def from_azure_prefix(prefix):
# xxxxxxxx/1111-11-11-11--11-11-11/0
dongle_id, route_name, segment_num = prefix.split("/")
return SegmentName(dongle_id + "|" + route_name + "--" + segment_num)
@cache
def get_max_seg_number_cached(sr: 'SegmentRange') -> int:
try:
api = CommaApi(get_token())
max_seg_number = api.get("/v1/route/" + sr.route_name.replace("/", "|"))["maxqlog"]
assert isinstance(max_seg_number, int)
return max_seg_number
except Exception as e:
raise Exception("unable to get max_segment_number. ensure you have access to this route or the route is public.") from e
class SegmentRange:
def __init__(self, segment_range: str):
m = re.fullmatch(RE.SEGMENT_RANGE, segment_range)
assert m is not None, f"Segment range is not valid {segment_range}"
self.m = m
@property
def route_name(self) -> str:
return self.m.group("route_name")
@property
def dongle_id(self) -> str:
return self.m.group("dongle_id")
@property
def log_id(self) -> str:View on GitHub (pinned to 516ec1e682)
Solutions
- Authenticate: run `python tools/lib/auth.py` (or re-login) so get_token() returns a valid token
- Confirm the route exists and is accessible to your account via cabana/connect
- Avoid the API call by giving an explicit end segment ('route/2--8' instead of 'route/2--')
Example fix
# before
sr = SegmentRange('b0c9d232|2022-01-01--00-00-00/3+')
# after
sr = SegmentRange('b0c9d232|2022-01-01--00-00-00/3--7') # explicit end: no max_seg_number lookup Defensive patterns
Strategy: validation
Validate before calling
from openpilot.tools.lib.api import CommaApi
from openpilot.tools.lib.auth import get_token
def route_accessible(route_name: str) -> bool:
try:
CommaApi(get_token()).get('/v1/route/' + route_name.replace('/', '|'))
return True
except Exception:
return False Try / catch
try:
sr = SegmentRange('route/3+')
_ = get_max_seg_number_cached(sr)
except Exception as e:
if 'max_segment_number' in str(e):
sr = SegmentRange('route/3--7') # explicit end, no API needed Prevention
- Prefer explicit segment ranges ('route/2--8') over open-ended ones in scripts
- Log in (auth) before running tools that hit the API
- Verify route name spelling and access rights first
When it happens
Trigger: Using an open-ended SegmentRange like 'route/2--' or route/3+, which must ask the API how many segments exist; calling it for a route your token cannot access, a non-existent route, or while offline.
Common situations: Not logged in (get_token() fails) or expired comma account token; typo'd route name; running tools in an environment without network; private route owned by another user.
Related errors
- error getting events for segment {self._name}
- Call to {path} failed with {r.status_code}
- {error_prefix} failed: {reason}/{subject} - {sd.get('message
- Maximum retries exceeded
- {func.__name__} failed after retry
AI-assisted analysis of commaai/openpilot@516ec1e682 (2026-08-15).
Data as JSON: /api/errors/681bd3085adc331f.
Report an issue: GitHub.