docs(model_switch): say what the fallback actually relies on

The switched-provider comment implied the guard catches the resolver raise;
it is suppress() leaving st.* at the session values that does. The
stay-on-provider comment now states the one semantic widening of moving to
the shared helper: an empty resolver result keeps the session endpoint on
any host, not only off openrouter.ai.
This commit is contained in:
kshitijk4poor
2026-09-19 10:37:41 +05:30
committed by kshitij
parent 0cb3760383
commit 9dee8863e1

View File

@@ -1380,11 +1380,10 @@ def _creds_for_switched_provider(st: _Switch) -> Optional[ModelSwitchResult]:
st.api_key, st.base_url, st.api_mode = ukey, user_pdef.base_url, ""
elif st.target_provider == "custom" and st.current_base_url:
# A bare-custom session switching models stays on its endpoint (#45597). Arriving from
# ANOTHER provider (the per-turn config sync adopting ``provider: custom``), the configured
# custom endpoint wins: keeping the session's URL pairs the new model with the previous
# provider's host and key (#73680). The resolver raises with no endpoint and no key, and
# lands on the OpenRouter DEFAULT with a key but no ``model.base_url`` (#74143) — both mean
# "nothing configured": keep the current endpoint.
# ANOTHER provider (the per-turn config sync adopting ``provider: custom``) the configured
# endpoint wins, or the new model is paired with the old provider's host and key (#73680).
# With nothing configured the resolver either raises (st.* keep the session values) or
# lands on OpenRouter's default (#74143) — the session endpoint is kept in both cases.
key, url = st.current_api_key, st.current_base_url
if st.current_provider != "custom":
with suppress(Exception):
@@ -1446,8 +1445,9 @@ def _creds_for_current_provider(st: _Switch) -> None:
pass
# Bare ``custom``/``local`` sessions whose base_url is session-only (not a trusted config
# ``model.base_url``) re-resolve to the OpenRouter DEFAULT — a host the user never picked
# (#74143). Keep the session endpoint + key then; a config-backed custom URL still wins so
# key/endpoint rotation is not pinned to a stale session.
# (#74143). Keep the session endpoint + key then (also when the resolver came back empty,
# whatever host the session is on); a config-backed custom URL still wins so key/endpoint
# rotation is not pinned to a stale session.
if (
st.current_provider in {"custom", "local"} and st.current_base_url
and (not st.base_url or _fell_back_to_openrouter_default(st))