From 15721dd1c9b7f3aad8baefc622ce5e76ad0900fb Mon Sep 17 00:00:00 2001 From: "Khoa (Revenovich) Tran Gia" Date: Tue, 3 Mar 2026 11:47:47 +0700 Subject: [PATCH] fix: correctly call websocket_endpoint from _WSInterceptMiddleware The middleware was calling the handler as a raw ASGI callable (scope, receive, send), but websocket_endpoint expects (WebSocket, token). This caused an AttributeError on every connection attempt, which made the frontend hit its 30s exponential backoff cap and spam reconnects. Fix: construct a WebSocket object from scope/receive/send and extract the ?token= query param before calling the handler, matching what FastAPI's routing machinery would do. Co-Authored-By: Claude Sonnet 4.6 --- web/app.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/web/app.py b/web/app.py index 4dc6e75..bdae264 100644 --- a/web/app.py +++ b/web/app.py @@ -88,7 +88,11 @@ class _WSInterceptMiddleware: async def __call__(self, scope, receive, send) -> None: if scope["type"] == "websocket" and scope.get("path") == "/ws": - await self._ws(scope, receive, send) + from urllib.parse import parse_qs + from starlette.websockets import WebSocket as _WS + qs = parse_qs(scope.get("query_string", b"").decode()) + token = qs.get("token", [""])[0] + await self._ws(_WS(scope, receive=receive, send=send), token) else: await self._app(scope, receive, send)