Skip to content

fix(anam): retry only retryable failures when starting a session - #3059

Open
sr-anam wants to merge 2 commits into
livekit:mainfrom
anam-org:anam/port-retry
Open

sr-anam wants to merge 2 commits into
livekit:mainfrom
anam-org:anam/port-retry

Conversation

@sr-anam

@sr-anam sr-anam commented Nov 24, 2026

Copy link
Copy Markdown

Description

Ports livekit/agents#7314. Starting an Anam session now retries only failures that can succeed on a retry. Before, every failure was retried, including a bad API key or a bad request, which delayed the error by several retry intervals.

Changes Made

  • Not-ok responses throw APIStatusError with the status code and response body. A 4xx other than 408, 429 or 499 fails at once.
  • Network failures are retried, and the last one throws APIConnectionError.
  • maxRetry now counts retries, as in Python, so a session start makes up to maxRetry + 1 attempts.
  • The LiveKit join token is now masked in the request logs (see below).
  • Unit tests for each retry path and a patch changeset

Before / After

Before After
401 / 403 / 400 response Retried maxRetry times, then AnamException Fails at once with APIStatusError
5xx, 408, 429 response Retried, then AnamException Retried, then APIStatusError
Network failure Retried, then the raw TypeError Retried, then APIConnectionError
Attempts with maxRetry: 3 3 4
Debug and retry logs Contained the LiveKit join token Token masked

Additional Notes

  • Breaking for some callers: code that catches AnamException around AvatarSession.start() will no longer catch API failures, because they now throw the shared APIStatusError and APIConnectionError classes, matching Python. AnamException is still thrown for configuration errors.
  • Log fix, not in the Python PR: the old code tried to mask livekitToken at the top level of the request body, but the token sits under environment, so debug and retry logs contained the full join token. The masking now covers environment.livekitToken.

Pre-Review Checklist

  • Build passes: All builds (lint, typecheck, tests) pass locally
  • AI-generated code reviewed: Removed unnecessary comments and ensured code quality
  • Changes explained: All changes are properly documented and justified above
  • Scope appropriate: All changes relate to the PR title, or explanations provided for why they're included
  • Video demo: A small video demo showing changes works as expected and did not break any existing functionality using Agent Playground (if applicable)

Testing

  • Automated tests added/updated (if applicable)
  • All tests pass
  • Make sure both restaurant_agent.ts and realtime_agent.ts work properly (for major changes)

Ran locally: pnpm vitest run plugins/anam, pnpm build and pnpm api:update in plugins/anam, pnpm eslint plugins/anam/src (no errors) and Prettier on the changed files.


Ported from livekit/agents#7314

🤖 Generated with Claude Code

Ported from livekit/agents.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sr-anam
sr-anam requested a review from a team as a code owner November 24, 2026 10:16
@changeset-bot

changeset-bot Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d7cdd13

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 42 packages
Name Type
@livekit/agents-plugin-anam Patch
@livekit/agents Patch
@livekit/agents-plugin-anthropic Patch
@livekit/agents-plugin-assemblyai Patch
@livekit/agents-plugin-azure Patch
@livekit/agents-plugin-baseten Patch
@livekit/agents-plugin-bey Patch
@livekit/agents-plugin-cartesia Patch
@livekit/agents-plugin-cerebras Patch
@livekit/agents-plugin-deepgram Patch
@livekit/agents-plugin-did Patch
@livekit/agents-plugin-elevenlabs Patch
@livekit/agents-plugin-fishaudio Patch
@livekit/agents-plugin-google Patch
@livekit/agents-plugin-hume Patch
@livekit/agents-plugin-inworld Patch
@livekit/agents-plugin-krisp Patch
@livekit/agents-plugin-lemonslice Patch
@livekit/agents-plugin-liveavatar Patch
@livekit/agents-plugin-livekit Patch
@livekit/agents-plugin-meta Patch
@livekit/agents-plugin-minimax Patch
@livekit/agents-plugin-mistral Patch
@livekit/agents-plugin-mistralai Patch
@livekit/agents-plugin-neuphonic Patch
@livekit/agents-plugin-nvidia Patch
@livekit/agents-plugin-openai Patch
@livekit/agents-plugin-perplexity Patch
@livekit/agents-plugin-phonic Patch
@livekit/agents-plugin-protoface Patch
@livekit/agents-plugin-resemble Patch
@livekit/agents-plugin-rime Patch
@livekit/agents-plugin-runway Patch
@livekit/agents-plugin-sarvam Patch
@livekit/agents-plugin-silero Patch
@livekit/agents-plugin-soniox Patch
@livekit/agents-plugin-speechify Patch
@livekit/agents-plugin-synthesia Patch
@livekit/agents-plugin-tavus Patch
@livekit/agents-plugins-test Patch
@livekit/agents-plugin-trugen Patch
@livekit/agents-plugin-xai Patch

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

devin-ai-integration[bot]

This comment was marked as resolved.

fetch rejects a scheme-less URL without sending a request, which the
retry loop treated as an outage. Also keep the underlying error in the
final APIConnectionError message.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant