Skip to content

allow 499 retry#4637

Merged
chenghao-mou merged 1 commit intomainfrom
fix/google-499
Jan 30, 2026
Merged

allow 499 retry#4637
chenghao-mou merged 1 commit intomainfrom
fix/google-499

Conversation

@chenghao-mou
Copy link
Member

@chenghao-mou chenghao-mou commented Jan 28, 2026

This allows retry on 499 errors w/ Google LLM.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced error retry logic for Google services to properly handle transient failures, treating both rate-limiting and temporary service unavailability responses as retryable conditions to improve reliability.

✏️ Tip: You can customize this high-level summary in your review settings.

@chenghao-mou chenghao-mou requested a review from a team January 28, 2026 10:58
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 28, 2026

📝 Walkthrough

Walkthrough

The PR updates error retry logic to treat HTTP status codes 429 and 499 as retryable for Gemini TTS and LLM services, and corrects a comment reference in the fallback adapter from _try_synthesize to _try_generate.

Changes

Cohort / File(s) Summary
Comment correction
livekit-agents/livekit/agents/llm/fallback_adapter.py
Updated comment reference in exception handler from _try_synthesize to _try_generate
Retry logic expansion
livekit-plugins/livekit-plugins-google/livekit/plugins/google/beta/gemini_tts.py, livekit-plugins/livekit-plugins-google/livekit/plugins/google/llm.py
Expanded retryable error codes for Google API clients to include both 429 (rate limit) and 499 (client error) as transient/retryable conditions

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 Hop, skip, and a bound,
Error codes we've found!
429 and 499 now retry with glee,
Comments fixed as clear as can be!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'allow 499 retry' directly and specifically describes the main change across all modified files: enabling HTTP 499 status code as retryable in error handling logic.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f4d6a1e and 697b176.

📒 Files selected for processing (3)
  • livekit-agents/livekit/agents/llm/fallback_adapter.py
  • livekit-plugins/livekit-plugins-google/livekit/plugins/google/beta/gemini_tts.py
  • livekit-plugins/livekit-plugins-google/livekit/plugins/google/llm.py
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

**/*.py: Format code with ruff
Run ruff linter and auto-fix issues
Run mypy type checker in strict mode
Maintain line length of 100 characters maximum
Ensure Python 3.9+ compatibility
Use Google-style docstrings

Files:

  • livekit-agents/livekit/agents/llm/fallback_adapter.py
  • livekit-plugins/livekit-plugins-google/livekit/plugins/google/beta/gemini_tts.py
  • livekit-plugins/livekit-plugins-google/livekit/plugins/google/llm.py
🧠 Learnings (1)
📚 Learning: 2026-01-22T03:28:16.289Z
Learnt from: longcw
Repo: livekit/agents PR: 4563
File: livekit-agents/livekit/agents/beta/tools/end_call.py:65-65
Timestamp: 2026-01-22T03:28:16.289Z
Learning: In code paths that check capabilities or behavior of the LLM processing the current interaction, prefer using the activity's LLM obtained via ctx.session.current_agent._get_activity_or_raise().llm instead of ctx.session.llm. The session-level LLM may be a fallback and not reflect the actual agent handling the interaction. Use the activity LLM to determine capabilities and to make capability checks or feature toggles relevant to the current processing agent.

Applied to files:

  • livekit-agents/livekit/agents/llm/fallback_adapter.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: livekit-plugins-cartesia
  • GitHub Check: unit-tests
  • GitHub Check: livekit-plugins-openai
  • GitHub Check: livekit-plugins-deepgram
  • GitHub Check: type-check (3.9)
  • GitHub Check: type-check (3.13)
🔇 Additional comments (2)
livekit-agents/livekit/agents/llm/fallback_adapter.py (1)

252-262: LGTM.
No behavioral change observed in this segment.

livekit-plugins/livekit-plugins-google/livekit/plugins/google/llm.py (1)

512-519: Remove 499 from the retryable error codes.

HTTP 499 (CANCELLED) indicates the client closed the connection before the response was delivered—a client-side issue, not a server error. Per Google's official guidance, 499 should not be blindly retried; the underlying cause (client timeout, premature cancellation, streaming disconnect) must be fixed first. Retrying 499 without addressing root causes will only repeat the failure.

HTTP 429 is correctly marked as retryable with exponential backoff, but 499 should be handled separately or removed from the automatic retry logic.

Likely an incorrect or invalid review comment.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
livekit-plugins/livekit-plugins-google/livekit/plugins/google/beta/gemini_tts.py (1)

233-239: Remove HTTP 499 from retryable status codes and extract a shared constant.

Google's Gemini/GenAI API documentation explicitly advises against auto-retrying HTTP 499 (CANCELLED), which represents client-driven cancellations (e.g., timeouts, stream disconnects). Only HTTP 429 (rate limit) should be automatically retried. Additionally, this pattern is duplicated across adapters in llm.py and beta/gemini_tts.py.

♻️ Suggested fix
+RETRYABLE_CLIENT_CODES = {429}
...
-                retryable=True if e.code in {429, 499} else False,
+                retryable=e.code in RETRYABLE_CLIENT_CODES,

Apply this fix to both llm.py and beta/gemini_tts.py.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f4d6a1e and 697b176.

📒 Files selected for processing (3)
  • livekit-agents/livekit/agents/llm/fallback_adapter.py
  • livekit-plugins/livekit-plugins-google/livekit/plugins/google/beta/gemini_tts.py
  • livekit-plugins/livekit-plugins-google/livekit/plugins/google/llm.py
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

**/*.py: Format code with ruff
Run ruff linter and auto-fix issues
Run mypy type checker in strict mode
Maintain line length of 100 characters maximum
Ensure Python 3.9+ compatibility
Use Google-style docstrings

Files:

  • livekit-agents/livekit/agents/llm/fallback_adapter.py
  • livekit-plugins/livekit-plugins-google/livekit/plugins/google/beta/gemini_tts.py
  • livekit-plugins/livekit-plugins-google/livekit/plugins/google/llm.py
🧠 Learnings (1)
📚 Learning: 2026-01-22T03:28:16.289Z
Learnt from: longcw
Repo: livekit/agents PR: 4563
File: livekit-agents/livekit/agents/beta/tools/end_call.py:65-65
Timestamp: 2026-01-22T03:28:16.289Z
Learning: In code paths that check capabilities or behavior of the LLM processing the current interaction, prefer using the activity's LLM obtained via ctx.session.current_agent._get_activity_or_raise().llm instead of ctx.session.llm. The session-level LLM may be a fallback and not reflect the actual agent handling the interaction. Use the activity LLM to determine capabilities and to make capability checks or feature toggles relevant to the current processing agent.

Applied to files:

  • livekit-agents/livekit/agents/llm/fallback_adapter.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: livekit-plugins-cartesia
  • GitHub Check: unit-tests
  • GitHub Check: livekit-plugins-openai
  • GitHub Check: livekit-plugins-deepgram
  • GitHub Check: type-check (3.9)
  • GitHub Check: type-check (3.13)
🔇 Additional comments (2)
livekit-agents/livekit/agents/llm/fallback_adapter.py (1)

252-262: LGTM.
No behavioral change observed in this segment.

livekit-plugins/livekit-plugins-google/livekit/plugins/google/llm.py (1)

512-519: Remove 499 from the retryable error codes.

HTTP 499 (CANCELLED) indicates the client closed the connection before the response was delivered—a client-side issue, not a server error. Per Google's official guidance, 499 should not be blindly retried; the underlying cause (client timeout, premature cancellation, streaming disconnect) must be fixed first. Retrying 499 without addressing root causes will only repeat the failure.

HTTP 429 is correctly marked as retryable with exponential backoff, but 499 should be handled separately or removed from the automatic retry logic.

Likely an incorrect or invalid review comment.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

@chenghao-mou chenghao-mou merged commit 843ffeb into main Jan 30, 2026
20 checks passed
@chenghao-mou chenghao-mou deleted the fix/google-499 branch January 30, 2026 09:30
zach-iee pushed a commit to sendbird/livekit-agents that referenced this pull request Feb 2, 2026
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