Extract WebSocket authorization logic to shared diagnostics module#124
Merged
Conversation
Both aai_cli/tts/session.py and aai_cli/agent/session.py carried a near-identical _open_ws: connect with a Bearer Authorization header and map any failure through diagnostics.classify_error. A fix to either error path had to be made twice. Replace both with a single diagnostics.open_authorized_ws helper (diagnostics already owns the shared classification and is imported by both sessions; ws.py can't host it without an import cycle). Strengthen the TTS connect tests to pin the per-caller details the shared helper now carries: max_size=None on the TTS socket and the active environment's streaming-TTS host in the rejected-handshake suggestion. https://claude.ai/code/session_016aDo6v4hCVhFZgqyruXgdr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Consolidates duplicate WebSocket connection and authorization logic from the TTS and voice agent session modules into a shared
open_authorized_wsfunction in the diagnostics module. This reduces code duplication and ensures consistent error handling across both features.Changes
open_authorized_wstoaai_cli/streaming/diagnostics.pythat handles Bearer token authorization and error classification for WebSocket connections_open_wsfunction and updatedsynthesize()to use the sharedopen_authorized_ws, now explicitly passingmax_size=Noneto lift the frame-size cap for Audio frames_open_wsfunction and updatedrun_session()to use the sharedopen_authorized_wsmax_size=Noneparameter in TTS tests; enhanced error handling test to verify the host is included in suggestionsImplementation Details
The new
open_authorized_wsis a generic function that:classify_errorfor consistent error messages and suggestions**connect_kwargsto accommodate different connection requirements (e.g., TTS'smax_size=None)https://claude.ai/code/session_016aDo6v4hCVhFZgqyruXgdr