Skip to content

fix: preserve TTS websocket path for query-bearing base URLs - #117

Draft
Kayvan-Zahiri wants to merge 2 commits into
cartesia-ai:mainfrom
Kayvan-Zahiri:codex/preserve-websocket-route-with-base-query
Draft

Kayvan-Zahiri wants to merge 2 commits into
cartesia-ai:mainfrom
Kayvan-Zahiri:codex/preserve-websocket-route-with-base-query

Conversation

@Kayvan-Zahiri

@Kayvan-Zahiri Kayvan-Zahiri commented Oct 18, 2026 •

Copy link
Copy Markdown

A client configured with a query-bearing base URL, such as https://proxy.example/api/v1/?route=speech, currently opens its TTS WebSocket at /api/v1/ instead of /api/v1/tts/websocket. Query values can also gain a trailing slash during base URL normalization.

HTTPX's raw_path includes the query string. Appending a path segment to that value puts the segment inside the query; replacing the query afterward removes the WebSocket suffix completely.

Strip the query before inspecting or extending the raw path. Base URL normalization reattaches the original query in a separate copy_with call (HTTPX gives raw_path precedence when both are supplied in one call), while the sync and async TTS managers continue to merge base URL parameters with per-connection extras. Encoded path segments remain encoded. The TTS changes are in the generator-protected lib directory; the small shared base-client change is a manual generated-code patch permitted by CONTRIBUTING.md. Two existing multiline expressions in _tts.py are normalized by the repository-pinned Ruff formatter.

Validation:

  • 16 new public websocket_connect().enter() / async cases: 8 fail before the fix and 8 controls pass. Covers root/nested/encoded paths, query/no-query URLs, query values containing encoded slashes, and extra connection parameters. Connect is stubbed, so no live connections or speech generation occur.
  • Offline suite excluding API-resource mock-server tests: 593 passed, 2 skipped with Pydantic 2; separately 580 passed, 15 skipped with Pydantic 1.
  • Repository Ruff lint and changed-file format checks pass using pinned Ruff 0.14.13.
  • Changed-source/test Pyright passes with pinned 1.1.409 and the isolated interpreter; git diff --check passes.
  • Source distribution and wheel build successfully.
  • Full-source mypy with pinned 1.17 reports 3 pre-existing errors in 2 files. Restoring both original source files reproduces the same 3 errors; these are not changed here.

This branch has not been deployed

No deployments
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.

1 participant