From 54818207a3b2a98311a34a41e49b45a50d73582d Mon Sep 17 00:00:00 2001 From: Alex Kroman <12372+alexkroman@users.noreply.github.com> Date: Fri, 12 Jun 2026 11:14:30 -0700 Subject: [PATCH 1/2] Apply suggested fix to aai_cli/ws.py from Copilot Autofix Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> --- aai_cli/ws.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/aai_cli/ws.py b/aai_cli/ws.py index 65dff4ba..547fa67a 100644 --- a/aai_cli/ws.py +++ b/aai_cli/ws.py @@ -63,8 +63,11 @@ def is_rejected_key(exc: object) -> bool: Agent's 1008 policy-violation close, or an explicitly auth-worded message (`is_auth_failure`'s text hints) count as a rejected key. """ - if handshake_status(exc) == _HTTP_FORBIDDEN: + status = handshake_status(exc) + if status == _HTTP_FORBIDDEN: return False + if status == 401: + return True return is_auth_failure(exc) From 967aa4148571dc08e73dd868f0d21fd4ee7718f2 Mon Sep 17 00:00:00 2001 From: Alex Kroman <12372+alexkroman@users.noreply.github.com> Date: Fri, 12 Jun 2026 11:14:31 -0700 Subject: [PATCH 2/2] Apply suggested fix to aai_cli/ws.py from Copilot Autofix Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> --- aai_cli/ws.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/aai_cli/ws.py b/aai_cli/ws.py index 547fa67a..36eab4ac 100644 --- a/aai_cli/ws.py +++ b/aai_cli/ws.py @@ -36,6 +36,14 @@ def silence_websockets_logging() -> None: logging.getLogger(name).setLevel(logging.CRITICAL) +def _as_int_status(value: object) -> int | None: + """Best-effort conversion of a status-like value to int, else None.""" + try: + return int(value) + except (TypeError, ValueError): + return None + + def handshake_status(exc: object) -> int | None: """The HTTP status of a rejected WebSocket handshake (401/403), else None. @@ -44,12 +52,12 @@ def handshake_status(exc: object) -> int | None: ``.response.status_code`` — never the message text. The single classifier for every realtime path (stream, agent, speak), so 401-vs-403 handling can't drift. """ - code = getattr(exc, "code", None) + code = _as_int_status(getattr(exc, "code", None)) if code in _HANDSHAKE_AUTH_STATUSES: - return int(code) - status = getattr(getattr(exc, "response", None), "status_code", None) + return code + status = _as_int_status(getattr(getattr(exc, "response", None), "status_code", None)) if status in _HANDSHAKE_AUTH_STATUSES: - return int(status) + return status return None