fix(webui): recover model failures and align chat controls

This commit is contained in:
Xubin Ren committed 2026-10-21 02:34:09 +08:00
1 parent 688976bcb9
commit 28f6c26946
42 files changed
+646 -82

No files matched your search

+20 -5
View File
@@ -361,6 +361,9 @@ class FallbackProvider(LLMProvider):
async def _call_chain(**chain_kwargs: Any) -> LLMResponse:
last_exhausted_message: str | None = None
last_exhausted_status: RetryStatusEvent | None = None
primary_attempted = False
primary_exhausted_message: str | None = None
primary_exhausted_status: RetryStatusEvent | None = None
async def _capture_exhaustion(message: str) -> None:
nonlocal last_exhausted_message
@@ -388,15 +391,22 @@ class FallbackProvider(LLMProvider):
candidate_kwargs: dict[str, Any],
) -> LLMResponse:
nonlocal last_exhausted_message, last_exhausted_status
nonlocal primary_attempted, primary_exhausted_message, primary_exhausted_status
last_exhausted_message = None
last_exhausted_status = None
return await call(provider, {
if provider is self._primary:
primary_attempted = True
response = await call(provider, {
**candidate_kwargs,
"retry_mode": "standard",
"on_retry_wait": on_retry_wait,
"on_retry_exhausted": _capture_exhaustion,
"on_retry_status": _capture_status,
})
if provider is self._primary:
primary_exhausted_message = last_exhausted_message
primary_exhausted_status = last_exhausted_status
return response
response = await self._try_with_fallback(
_call_candidate,
@@ -406,10 +416,12 @@ class FallbackProvider(LLMProvider):
on_fallback_attempt=_clear_status_for_fallback,
)
if retry_mode != "persistent" and response.finish_reason == "error":
if last_exhausted_message and on_retry_exhausted:
await on_retry_exhausted(last_exhausted_message)
if last_exhausted_status and on_retry_status:
await on_retry_status(last_exhausted_status)
terminal_message = primary_exhausted_message if primary_attempted else last_exhausted_message
terminal_status = primary_exhausted_status if primary_attempted else last_exhausted_status
if terminal_message and on_retry_exhausted:
await on_retry_exhausted(terminal_message)
if terminal_status and on_retry_status:
await on_retry_status(terminal_status)
return response
if retry_mode != "persistent":
@@ -656,6 +668,9 @@ class FallbackProvider(LLMProvider):
return replace(
last_response,
preserve_provider_state_on_error=preserve_primary_state,
primary_error_kind=(
self.public_error_kind(primary_response) if primary_response is not None else None
),
)
# Primary was skipped and no fallback returned a response. Keep the result
# transient until the primary circuit is eligible for another probe.