Skip to content

fix(anam): retry retryable HTTP status failures when starting a session - #7314

Merged
tinalenguyen merged 2 commits into
mainfrom
tina/anam-http-retry
Sep 17, 2026
Merged

tinalenguyen merged 2 commits into
mainfrom
tina/anam-http-retry

Conversation

@tinalenguyen

Copy link
Copy Markdown
Member

AnamAPI._post raises APIStatusError for any non-OK response from
/v1/engine/session, but its retry loop only caught
(aiohttp.ClientError, asyncio.TimeoutError). The APIStatusError therefore
escaped on the first attempt, so max_retry / retry_interval were dead
config for every HTTP-status failure — a single transient 5xx from Anam killed
avatar startup with no retry.

This adds an except APIStatusError arm that:

  • re-raises immediately when retryable is False (4xx other than 408/429/499),
  • otherwise logs, sleeps retry_interval, and retries within max_retry,
  • re-raises the APIStatusError once retries are exhausted, so the caller keeps
    status_code / body instead of a wrapped APIConnectionError.

The transport arm is unchanged: aiohttp.ClientError and timeouts still end in
APIConnectionError as before.

This matches the sibling avatar plugins (protoface, avatario, liveavatar,
lemonslice, keyframe, runway), which all consult APIStatusError.retryable.

@tinalenguyen
tinalenguyen requested a review from a team as a code owner September 16, 2026 23:14

@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 found 2 potential issues.

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

Devin Review

Comment thread livekit-plugins/livekit-plugins-anam/livekit/plugins/anam/api.py Outdated
Comment thread livekit-plugins/livekit-plugins-anam/livekit/plugins/anam/api.py
APIConnectOptions.max_retry counts retries after the initial request, so
the loop must run max_retry + 1 attempts. It ran max_retry, dropping one
configured retry on every retryable failure and making max_retry=0 issue
no request at all.
session = self._session or aiohttp.ClientSession()
try:
for attempt in range(self._conn_options.max_retry):
for attempt in range(self._conn_options.max_retry + 1):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already have the retry mechanism handled inside the base class of TTS

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm i don't think there is for anam avatar API?

@tinalenguyen
tinalenguyen merged commit 30883a8 into main Sep 17, 2026
26 of 27 checks passed
@tinalenguyen
tinalenguyen deleted the tina/anam-http-retry branch September 17, 2026 19:47
sidxh added a commit to sidxh/agents that referenced this pull request Sep 26, 2026
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 added a commit to sidxh/agents that referenced this pull request Sep 26, 2026
…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 added a commit to sidxh/agents that referenced this pull request Sep 26, 2026
…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 added a commit to sidxh/agents that referenced this pull request Sep 26, 2026
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.
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