Skip to content

fix(cartesia): stop sending max_buffer_delay_ms on /tts/bytes - #2442

Open
brodie-avoca wants to merge 1 commit into
livekit:mainfrom
brodie-avoca:fix/cartesia-bytes-max-buffer-delay
Open

fix(cartesia): stop sending max_buffer_delay_ms on /tts/bytes#2442
brodie-avoca wants to merge 1 commit into
livekit:mainfrom
brodie-avoca:fix/cartesia-bytes-max-buffer-delay

Conversation

@brodie-avoca

@brodie-avoca brodie-avoca commented Sep 8, 2026

Copy link
Copy Markdown

Description

toCartesiaOptions puts max_buffer_delay_ms: 0 in the shared payload, so it goes out on /tts/bytes as well as the websocket. Cartesia rejects every non-streaming request with:

400 Invalid request: Your request was invalid: max buffer delay is only supported for websocket requests

#1107 added the field for the websocket message ("Add max_buffer_delay_ms = 0 to ws msg"); the placement made it apply to both paths. The main caller of synthesize() in a voice pipeline is the TTS FallbackAdapter recovery probe, so once a session fails over from Cartesia it can never recover to it. We observed one failover followed by 99 consecutive rejected recovery probes on a production call.

Parity: the Python plugin only adds max_buffer_delay_ms in the websocket sentence stream (tts.py#L433-L434) and never sends it on /tts/bytes (tts.py#L366).

Changes Made

  • Move max_buffer_delay_ms: 0 under the existing streaming guard in toCartesiaOptions, next to add_timestamps.
  • Pick node:http or node:https from the base URL protocol in ChunkedStream (the port calculation already did), so the non-streaming path can be tested against a local plain-HTTP server the same way the websocket tests already are.
  • Tests: the /tts/bytes payload has no max_buffer_delay_ms; websocket packets still carry it.

Pre-Review Checklist

  • Build passes: All builds (lint, typecheck, tests) pass locally
  • AI-generated code reviewed: Removed unnecessary comments and ensured code quality
  • Changes explained: All changes are properly documented and justified above
  • Scope appropriate: All changes relate to the PR title
  • Video demo: n/a, request-payload change covered by tests

Testing

  • Automated tests added/updated
  • All tests pass
  • restaurant_agent.ts / realtime_agent.ts: n/a, not a major change
pnpm build
pnpm vitest run plugins/cartesia/src/tts.test.ts   # 11 passed, 1 skipped (credential-gated)
pnpm exec eslint plugins/cartesia/src/tts.ts plugins/cartesia/src/tts.test.ts
pnpm exec prettier --check plugins/cartesia/src/tts.ts plugins/cartesia/src/tts.test.ts

Additional Notes

The same handler never checks the response status, which is why this 400 showed up as silent empty audio rather than an error. That is a separate fix in #2443, which is stacked on this branch and should be reviewed after this one.

@changeset-bot

changeset-bot Bot commented Sep 8, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a4a4f56

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 38 packages
Name Type
@livekit/agents-plugin-cartesia Patch
@livekit/agents Patch
@livekit/agents-plugin-anam Patch
@livekit/agents-plugin-anthropic Patch
@livekit/agents-plugin-assemblyai Patch
@livekit/agents-plugin-azure Patch
@livekit/agents-plugin-baseten Patch
@livekit/agents-plugin-bey Patch
@livekit/agents-plugin-cerebras Patch
@livekit/agents-plugin-deepgram Patch
@livekit/agents-plugin-did Patch
@livekit/agents-plugin-elevenlabs Patch
@livekit/agents-plugin-fishaudio Patch
@livekit/agents-plugin-google Patch
@livekit/agents-plugin-hume Patch
@livekit/agents-plugin-inworld Patch
@livekit/agents-plugin-krisp Patch
@livekit/agents-plugin-lemonslice Patch
@livekit/agents-plugin-liveavatar Patch
@livekit/agents-plugin-livekit Patch
@livekit/agents-plugin-minimax Patch
@livekit/agents-plugin-mistral Patch
@livekit/agents-plugin-mistralai Patch
@livekit/agents-plugin-neuphonic Patch
@livekit/agents-plugin-openai Patch
@livekit/agents-plugin-perplexity Patch
@livekit/agents-plugin-phonic Patch
@livekit/agents-plugin-protoface Patch
@livekit/agents-plugin-resemble Patch
@livekit/agents-plugin-rime Patch
@livekit/agents-plugin-runway Patch
@livekit/agents-plugin-sarvam Patch
@livekit/agents-plugin-silero Patch
@livekit/agents-plugin-soniox Patch
@livekit/agents-plugin-tavus Patch
@livekit/agents-plugins-test Patch
@livekit/agents-plugin-trugen Patch
@livekit/agents-plugin-xai Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@CLAassistant

CLAassistant commented Sep 8, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

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