feat(llm): allow a separate attempt timeout for fallback LLMs - #6915
Open
roshaans wants to merge 1 commit into
Open
feat(llm): allow a separate attempt timeout for fallback LLMs#6915roshaans wants to merge 1 commit into
roshaans wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
llm.FallbackAdapterapplies oneattempt_timeoutto 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_timeoutonFallbackAdapter.__init__, applying to every LLM after the first (serving attempts and recovery checks alike):None, meaningattempt_timeoutapplies to all providers — existing behavior is unchanged._attempt_timeout_for(llm)lookup used byFallbackLLMStream._try_generatewhere 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.timeouton 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