From b2980a7d2468cac7a2e397f213d3f0f75e08f996 Mon Sep 17 00:00:00 2001 From: alpha-nerd-nomyo Date: Tue, 17 Feb 2026 15:56:09 +0100 Subject: [PATCH] fix(router): handle invalid version responses with 503 error Filter out non-string version responses (e.g., empty lists from failed requests) and return a 503 Service Unavailable error if no valid versions are received from any endpoint. --- router.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/router.py b/router.py index be8c674..d1f5797 100644 --- a/router.py +++ b/router.py @@ -2292,7 +2292,13 @@ async def version_proxy(request: Request): """ # 1. Query all endpoints for version tasks = [fetch.endpoint_details(ep, "/api/version", "version") for ep in config.endpoints if "/v1" not in ep] - all_versions = await asyncio.gather(*tasks) + all_versions_raw = await asyncio.gather(*tasks) + + # Filter out non-string values (e.g., empty lists from failed/timeout responses) + all_versions = [v for v in all_versions_raw if isinstance(v, str) and v] + + if not all_versions: + raise HTTPException(status_code=503, detail="No valid version response from any endpoint") def version_key(v): return tuple(map(int, v.split('.')))