fix: don't fall back when a model is explicitly configured in registry

Previously any backend error would silently fall back to Claude.
Now if the user has a model configured via the model registry, errors
propagate to the UI so the actual problem is visible rather than hidden
behind a transparent backend switch.

Fallback still applies when using the default/auto backend with no
registry config.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Scott Idem
2026-04-08 22:30:55 -04:00
parent 3b3456600a
commit 869a596f4b

View File

@@ -87,9 +87,15 @@ async def complete(
return response, primary
except Exception as e:
err_str = str(e)
logger.warning("%s failed (%s) — falling back to %s", primary, e, fallback)
if primary == "claude" and any(k in err_str for k in ("401", "authenticate", "expired", "OAuth")):
await event_bus.publish({"type": "claude_auth_expired"})
# Only fall back when using a default/auto backend.
# If the user has explicitly configured a model via the registry,
# surface the error so they know something is wrong.
if resolved_cfg is not None:
logger.error("%s failed (no fallback — model explicitly configured): %s", primary, e)
raise
logger.warning("%s failed (%s) — falling back to %s", primary, e, fallback)
response = await _dispatch(fallback, system_prompt, messages, None)
return response, fallback