Skip to content

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

Description

@sidxh

Bug Description

simli.AvatarSession.start() makes two POSTs (/compose/token, then /integrations/livekit/agents) with no retry, and its second error handler can crash.

The second except in livekit-plugins-simli/livekit/plugins/simli/avatar.py formats avatarConnectionRequest.status into the log message. If the request raises before a response exists (connection dropped), or json.loads(body)["session_token"] fails because the token response has no session_token, that name was never assigned and the handler itself raises UnboundLocalError, so start() crashes instead of logging and returning like the first block does. The same message interpolates body, which at that point is the token response, so a failure there can write the Simli session token to the logs.

A single transient 5xx on either request also ends the avatar for the session, since nothing is retried.

Expected Behavior

Both requests retry 5xx and network errors like the other avatar plugins (Anam after #7314). A failure is logged with its status and provider error and start() returns without replacing the audio output, as it does today for the first request.

Reproduction Steps

Point simli.AvatarSession(api_url=...) at a local server whose /compose/token returns 200 with {}, or returns a token and then drops the connection on the second request. On main both raise UnboundLocalError: cannot access local variable 'avatarConnectionRequest'. A server that returns 503 once on the token endpoint fails the avatar immediately.

Versions

livekit-agents 1.8.3, livekit-plugins-simli at main (57b3227), Python 3.13, macOS.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions