Skip to content

fix(tavus): don't retry 4xx when calling the Tavus API, and keep the provider's error - #7494

Merged
davidzhao merged 1 commit into
livekit:mainfrom
sidxh:fix/tavus-start-retry
Oct 4, 2026
Merged

davidzhao merged 1 commit into
livekit:mainfrom
sidxh:fix/tavus-start-retry

Conversation

@sidxh

@sidxh sidxh commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

TavusAPI._post retries every failure, including 4xx responses that can never succeed. With a wrong API key the avatar takes about 4 seconds to fail, logs three tracebacks, and ends with a retryable APIConnectionError("Failed to call Tavus API after all retries") that has lost the 401 and the response body.

The loop catches Exception, which includes the APIStatusError it raises itself for a non-2xx response, logs each one with logger.exception, and always finishes with a generic, unchained APIConnectionError. It also runs range(max_retry), one attempt fewer than the other avatar plugins.

This is the same change #7314 made for Anam. A non-retryable APIStatusError is re-raised immediately. 5xx and network errors are retried max_retry times after the first attempt with a warning (status code only, no payload), and the final error is the provider's APIStatusError, or an APIConnectionError chained to the network error.

Against a local server with default connect options, on main: a 401 takes 4.00s, three tracebacks, generic APIConnectionError; a persistent 503 is the same. With this change a 401 raises APIStatusError(status_code=401) on the first attempt with no traceback, 503, 503, 200 still succeeds, and a persistent 503 raises APIStatusError(status_code=503) after four attempts (6.01s, one more attempt than before, matching Anam). Five tests added in a new tests/test_plugin_tavus.py; the four retry-classification ones fail on main, and one covers a 2xx with a malformed JSON body, which now fails once with a non-retryable APIConnectionError instead of re-sending a POST Tavus already accepted.

Closes #7493.

@sidxh
sidxh requested a review from a team as a code owner September 26, 2026 19:07
devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

…provider's error

Re-raise non-retryable APIStatusError immediately, retry 5xx and network
errors max_retry times after the first attempt, and let the final error be the
provider's status (or an APIConnectionError chained to the network error)
instead of a generic "after all retries". Same shape as livekit#7314 for Anam.
@sidxh
sidxh force-pushed the fix/tavus-start-retry branch from 874ba5c to edb3ed5 Compare September 26, 2026 19:26
@davidzhao
davidzhao merged commit 17dd7dd into livekit:main Oct 4, 2026
18 checks passed
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.

tavus: 4xx errors are retried and the provider's status is replaced by a generic error

3 participants