Skip to content

fix(llm): fall back when an attempt opens but sends no useful chunks#5793

Open
ATOM00blue wants to merge 1 commit into
livekit:mainfrom
ATOM00blue:fix/llm-fallback-no-useful-chunks
Open

fix(llm): fall back when an attempt opens but sends no useful chunks#5793
ATOM00blue wants to merge 1 commit into
livekit:mainfrom
ATOM00blue:fix/llm-fallback-no-useful-chunks

Conversation

@ATOM00blue
Copy link
Copy Markdown

Summary

The LLM FallbackAdapter accepts an attempt_timeout, but it was only forwarded to the underlying LLM as the connection timeout. If a provider opens the connection and then stays silent — no useful chunk and no HTTP error — the adapter blocks indefinitely on the first attempt instead of failing over. This has shown up in practice as provider brown-outs that leave the user hearing silence.

This change also applies attempt_timeout to the time-to-first-useful-chunk. If no chunk carrying spoken content or tool calls arrives within the timeout, the attempt times out and the adapter falls back to the next LLM (reusing the existing asyncio.TimeoutError handling). Chunks that only carry metadata (e.g. usage) don't count as progress. Once a useful chunk has been received the timeout is dropped, matching the existing retry_on_chunk_sent=False behavior.

Test plan

  • pytest tests/test_llm_fallback.py — new tests fail before the change (adapter hangs on a connected-but-silent LLM) and pass after
  • Covers: fall back on a fully silent attempt, fall back when only non-useful chunks are streamed, and APIConnectionError when every LLM stays silent
  • ruff format / ruff check clean; existing STT/TTS fallback tests still pass

Fixes #5660

The LLM FallbackAdapter forwarded attempt_timeout to the underlying LLM
as the connection timeout only. A provider could open the connection and
then stay silent (no useful chunk and no HTTP error), leaving the adapter
blocked forever instead of failing over.

Apply attempt_timeout to the time-to-first-useful-chunk as well, so a
connected-but-silent attempt times out and falls back to the next LLM.
Chunks carrying only metadata (e.g. usage) don't count as progress.

Fixes livekit#5660
Copilot AI review requested due to automatic review settings May 21, 2026 04:24
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

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.

LLM Fallback Adapter - Doesn't fall back if http connection opened but no useful chunks received

3 participants