fix(tavus): don't retry 4xx and preserve provider errors - #2635
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: 58eb1c4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 39 packages
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 |
davidzhao
approved these changes
Oct 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ports livekit/agents#7494.
Summary
@livekit/agents-plugin-tavusSource diff coverage
livekit-plugins/livekit-plugins-tavus/livekit/plugins/tavus/api.py: adapted toplugins/tavus/src/api.ts. The Pythonaiohttpexception branches map to FetchTypeErrorand timeoutDOMException; Python exception chaining maps to JavaScriptError.cause. Existing target retry timing remains in milliseconds throughintervalForRetry.tests/test_plugin_tavus.py: adapted toplugins/tavus/src/api.test.ts, the target plugin's existing co-located Vitest suite. All five source tests are ported: 4xx classification/status preservation, 5xx retry-to-success, persistent 5xx provider error preservation, malformed success JSON without retry, and network retry/cause chaining.Validation
pnpm test plugins/tavus(16 tests across the complete Tavus package suite)pnpm --filter @livekit/agents-plugin-tavus buildpnpm --filter @livekit/agents-plugin-tavus lintpnpm build(40 workspace packages)pnpm lintreaches an unrelated pre-existing error atplugins/openai/src/ws/llm.ts:127(@typescript-eslint/no-misused-promises); Tavus package lint passes.Ported from livekit/agents#7494
Original PR description
TavusAPI._postretries 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 retryableAPIConnectionError("Failed to call Tavus API after all retries")that has lost the 401 and the response body.The loop catches
Exception, which includes theAPIStatusErrorit raises itself for a non-2xx response, logs each one withlogger.exception, and always finishes with a generic, unchainedAPIConnectionError. It also runsrange(max_retry), one attempt fewer than the other avatar plugins.This is the same change #7314 made for Anam. A non-retryable
APIStatusErroris re-raised immediately. 5xx and network errors are retriedmax_retrytimes after the first attempt with a warning (status code only, no payload), and the final error is the provider'sAPIStatusError, or anAPIConnectionErrorchained to the network error.Against a local server with default connect options, on
main: a 401 takes 4.00s, three tracebacks, genericAPIConnectionError; a persistent 503 is the same. With this change a 401 raisesAPIStatusError(status_code=401)on the first attempt with no traceback, 503, 503, 200 still succeeds, and a persistent 503 raisesAPIStatusError(status_code=503)after four attempts (6.01s, one more attempt than before, matching Anam). Five tests added in a newtests/test_plugin_tavus.py; the four retry-classification ones fail onmain, and one covers a 2xx with a malformed JSON body, which now fails once with a non-retryableAPIConnectionErrorinstead of re-sending a POST Tavus already accepted.Closes #7493.