Skip to content

fix(aws): don't retry Polly 4xx errors such as InvalidSsmlException - #7969

Open
omChauhanDev wants to merge 1 commit into
livekit:mainfrom
omChauhanDev:fix/aws-polly-4xx-retry
Open

omChauhanDev wants to merge 1 commit into
livekit:mainfrom
omChauhanDev:fix/aws-polly-4xx-retry

Conversation

@omChauhanDev

@omChauhanDev omChauhanDev commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Problem

ChunkedStream._run in aws/tts.py wraps every botocore ClientError in APIConnectionError(), which is retryable by default. So a request Polly rejects outright, such as an InvalidSsmlException, a TextLengthExceededException or a 403 for bad credentials, is sent again until max_retry runs out. With the default connect options that is four identical requests and about 4 seconds of backoff before it fails, and it fails as a connection error without Polly's status code or request id.

Changes

_run now catches ClientError, and when Polly rejects the request with a 4xx it raises an APIStatusError with the status code and request id, so it isn't retried. Throttling (Polly sends it as a 400 ThrottlingException), 408, 429, 5xx and ClientErrors that don't come from SynthesizeSpeech, such as STS while botocore refreshes credentials, still raise APIConnectionError as before.

Polly 4xx rejections now raise APIStatusError with the status code and request id instead of a retryable APIConnectionError. Throttling (a 400 ThrottlingException), 408, 429, 5xx and errors that don't come from SynthesizeSpeech keep the old behaviour.
@omChauhanDev
omChauhanDev requested a review from a team as a code owner October 20, 2026 05:07

@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: 1 flag

Not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

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.

2 participants