Skip to content

fix(simli): retry session start and stop the error handler from crashing - #7498

Open
sidxh wants to merge 1 commit into
livekit:mainfrom
sidxh:fix/simli-start-retry
Open

sidxh wants to merge 1 commit into
livekit:mainfrom
sidxh:fix/simli-start-retry

Conversation

@sidxh

@sidxh sidxh commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

simli.AvatarSession.start() makes two POSTs with no retry, and its second error handler references avatarConnectionRequest even when the request raised before a response existed. A dropped connection on that request, or a token response without session_token, ends in UnboundLocalError instead of the log-and-return the first block does. The same handler interpolates body, which is the token response at that point, so it can log the Simli session token. And one transient 5xx on either request ends the avatar for the session.

Both requests now go through _post_with_retry, with the same shape #7314 gave Anam: a non-retryable APIStatusError is raised immediately, 5xx and network errors are retried max_retry times after the first attempt, and the final error is the provider's status or an APIConnectionError chained to the network error. start() catches those per request, logs the status and provider error (never the request or the token body), and returns without replacing the audio output, which keeps the existing behaviour when the avatar can't start. AvatarSession gains a conn_options argument defaulting to DEFAULT_API_CONNECT_OPTIONS, like Bey and Tavus; its timeout bounds the connect, and the session's total limit (300s by default) still bounds each request. The "... in dir()" checks are gone.

Against a local server with default connect options, on main: a token response without session_token and a dropped second request both raise UnboundLocalError; a 503 once on the token endpoint fails the avatar in 0.00s. With this change those two cases log and return, 503, 503, 200 starts the avatar after 4.01s, and a 401 still fails on the first attempt. Five tests added in a new tests/test_plugin_simli.py, including one for the crash and one for the timeout; all fail on main.

Closes #7497.

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

This comment was marked as resolved.

@sidxh
sidxh force-pushed the fix/simli-start-retry branch from f8df0d9 to e1c8dc4 Compare September 26, 2026 19:19
Send both session-start requests through a retry helper with the same shape as
livekit#7314 for Anam (4xx fails fast, 5xx and network errors retry), add a
conn_options argument, and log failures by status and provider error. The old
second handler referenced the response even when the request raised, so a
dropped connection or a token response without session_token ended in
UnboundLocalError, and on error it could log the Simli session token.
@sidxh
sidxh force-pushed the fix/simli-start-retry branch from e1c8dc4 to ec3f152 Compare September 26, 2026 19:27

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.

simli: start() crashes with UnboundLocalError when the second request fails, and never retries

1 participant