Skip to content

feat(llm): allow a separate attempt timeout for fallback LLMs - #6915

Open
roshaans wants to merge 1 commit into
livekit:mainfrom
roshaans:feat/llm-fallback-attempt-timeout
Open

feat(llm): allow a separate attempt timeout for fallback LLMs#6915
roshaans wants to merge 1 commit into
livekit:mainfrom
roshaans:feat/llm-fallback-attempt-timeout

Conversation

@roshaans

@roshaans roshaans commented Aug 19, 2026

Copy link
Copy Markdown

Motivation

llm.FallbackAdapter applies one attempt_timeout to every provider, so a fallback inherits the primary's latency target. For voice agents the two needs conflict: the primary's timeout should stay tight so a slow turn fails over quickly, while a fallback typically runs cold — no warmed prompt cache, no session affinity — and needs a longer first-token window than the primary is allowed.

With a single shared value there is no good setting: raising it to accommodate the fallback slows every ordinary failover, while keeping it tight regularly cuts off a healthy fallback mid-attempt and turns a one-provider blip into a failed request. We hit exactly this in production, which is what motivated the change.

Change

New optional fallback_attempt_timeout on FallbackAdapter.__init__, applying to every LLM after the first (serving attempts and recovery checks alike):

FallbackAdapter([primary, fallback], attempt_timeout=5.0, fallback_attempt_timeout=8.0)
  • Default is None, meaning attempt_timeout applies to all providers — existing behavior is unchanged.
  • Implementation is a small _attempt_timeout_for(llm) lookup used by FallbackLLMStream._try_generate where it previously read the single shared value.

Tests

  • test_fallback_attempt_timeout_gives_fallbacks_a_longer_window: primary misses its tight timeout, fallback's first token lands after the primary's window but within its own longer one → request served, and only the primary is marked unavailable (proving it was cut at its own timeout, not the fallback's).
  • test_attempt_timeout_applies_to_all_llms_by_default: without the new parameter, the shared timeout still applies to every provider (backward-compat pin).

Both use a local fake that enforces conn_options.timeout on the first token, the way provider plugins do.

Proposal issue per CONTRIBUTING.md: #6916 — happy to adjust scope/naming based on discussion there.

🤖 Generated with Claude Code

FallbackAdapter applies one attempt_timeout to every provider, so a
fallback inherits the primary's latency target. The two needs conflict:
the primary's timeout should stay tight so a slow turn fails over
quickly, while a fallback runs cold (no warmed prompt cache) and needs
a longer window. New optional fallback_attempt_timeout applies to every
LLM after the first; default keeps today's behavior.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@CLAassistant

CLAassistant commented Aug 19, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@roshaans
roshaans marked this pull request as ready for review August 19, 2026 17:30
@roshaans
roshaans requested a review from a team as a code owner August 19, 2026 17:30

@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: No Issues Found

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

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.

2 participants