Skip to content

Extract WebSocket authorization logic to shared diagnostics module#124

Merged
alexkroman merged 1 commit into
mainfrom
claude/affectionate-hypatia-tpk7dl
Jun 12, 2026
Merged

Extract WebSocket authorization logic to shared diagnostics module#124
alexkroman merged 1 commit into
mainfrom
claude/affectionate-hypatia-tpk7dl

Conversation

@alexkroman

Copy link
Copy Markdown
Collaborator

Summary

Consolidates duplicate WebSocket connection and authorization logic from the TTS and voice agent session modules into a shared open_authorized_ws function in the diagnostics module. This reduces code duplication and ensures consistent error handling across both features.

Changes

  • New shared function: Added open_authorized_ws to aai_cli/streaming/diagnostics.py that handles Bearer token authorization and error classification for WebSocket connections
  • TTS session: Removed _open_ws function and updated synthesize() to use the shared open_authorized_ws, now explicitly passing max_size=None to lift the frame-size cap for Audio frames
  • Voice agent session: Removed duplicate _open_ws function and updated run_session() to use the shared open_authorized_ws
  • Tests: Updated test comments to reference the new shared function location and added assertions for the max_size=None parameter in TTS tests; enhanced error handling test to verify the host is included in suggestions

Implementation Details

The new open_authorized_ws is a generic function that:

  • Accepts a connect callable and wraps it with Bearer token authorization
  • Maps connection failures through classify_error for consistent error messages and suggestions
  • Supports arbitrary **connect_kwargs to accommodate different connection requirements (e.g., TTS's max_size=None)
  • Uses PEP 695 type parameter syntax for clean generic typing

https://claude.ai/code/session_016aDo6v4hCVhFZgqyruXgdr

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
@alexkroman alexkroman enabled auto-merge June 12, 2026 20:01
@alexkroman alexkroman added this pull request to the merge queue Jun 12, 2026
Merged via the queue into main with commit cf37884 Jun 12, 2026
16 checks passed
@alexkroman alexkroman deleted the claude/affectionate-hypatia-tpk7dl branch June 12, 2026 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants