fix(providers): allow retry and fallback on stream stalled timeout

When a stream stalls mid-response, both the retry layer and
FallbackProvider blocked recovery because content had already been
emitted via on_content_delta. This left users with truncated replies
and no automatic recovery.

For error_kind="timeout" specifically:
- _run_with_retry now suppresses delta callbacks and retries the same
  model instead of returning immediately
- FallbackProvider now allows failover to a different model with
  delta callbacks suppressed

Non-timeout errors retain the original "skip retry/failover after
streamed content" behavior to avoid duplicate output.
This commit is contained in:
aiguozhi123456 authored and Xubin Ren committed 2026-06-10 18:10:44 +08:00
1 parent dadb35af49
commit 2c5a4e0703
4 files changed
+97 -11

No files matched your search

+14 -4
View File
@@ -149,10 +149,20 @@ class FallbackProvider(LLMProvider):
return response
if has_streamed is not None and has_streamed[0]:
logger.warning(
"Primary model error but content already streamed; skipping failover"
)
return response
is_timeout = (response.error_kind or "").lower() == "timeout"
if is_timeout:
logger.warning(
"Primary model '{}' stream stalled after content was emitted; "
"attempting failover anyway",
primary_model,
)
has_streamed[0] = False
kwargs["on_content_delta"] = None
else:
logger.warning(
"Primary model error but content already streamed; skipping failover"
)
return response
if not self._should_fallback(response):
logger.warning(