fix: don't flip active_provider when caching Z.AI probe result

_save_provider_state() sets auth_store['active_provider'] as a side effect.
The Z.AI endpoint probe runs from credential-pool env seeding for any user
with a Z.AI key in env — persisting the probe cache must not silently make
zai the active provider. Use _store_provider_state(set_active=False).

Follow-up to PR #41201 salvage.
This commit is contained in:
kshitijk4poor 2026-07-08 17:07:52 +05:30 committed by kshitij
parent c75e1d1b87
commit 6eeed3f1e8

View file

@ -713,7 +713,10 @@ def _resolve_zai_base_url(api_key: str, default_url: str, env_override: str) ->
auth_store = _load_auth_store()
state_under_lock = _load_provider_state(auth_store, "zai") or {}
state_under_lock["detected_endpoint"] = state["detected_endpoint"]
_save_provider_state(auth_store, "zai", state_under_lock)
# set_active=False: this runs from credential-pool env seeding
# (agent/credential_pool.py) for ANY user with a Z.AI key in env,
# and caching a probe result must not flip their active provider.
_store_provider_state(auth_store, "zai", state_under_lock, set_active=False)
_save_auth_store(auth_store)
logger.info("Z.AI: auto-detected endpoint %s (%s)", detected["label"], detected["base_url"])
return detected["base_url"]