fix(hermes_cli): preserve unset-active dashboard xAI OAuth and cover token save modes

Use mark_provider_active_if_unset after dashboard token save, unsuppress
device_code after TTS setup login, and lock default-active plus refresh
active_provider contracts in tests.
This commit is contained in:
Fangliquan 2026-07-25 20:50:37 +08:00 • committed by Teknium
parent fce06e909d
commit f42be94049
3 changed files with 80 additions and 2 deletions

View file

@ -908,6 +908,7 @@ def _run_xai_oauth_login_from_setup() -> bool:
_is_remote_session,
_save_xai_oauth_tokens,
_xai_oauth_device_code_login,
unsuppress_credential_source,
)
except Exception as exc:
print_warning(f"xAI Grok OAuth helpers unavailable: {exc}")
@ -926,6 +927,9 @@ def _run_xai_oauth_login_from_setup() -> bool:
auth_mode="oauth_device_code",
set_active=False,
)
# Mirror model/dashboard re-login: clear device_code suppression so
# the pool can seed from the singleton after a prior `auth remove`.
unsuppress_credential_source("xai-oauth", "device_code")
return True
except Exception as exc:
print_warning(f"xAI Grok OAuth login failed: {exc}")

View file

@ -11117,6 +11117,7 @@ def _xai_device_poller(session_id: str) -> None:
_save_xai_oauth_tokens,
_xai_oauth_discovery,
_xai_oauth_poll_device_token,
mark_provider_active_if_unset,
unsuppress_credential_source,
)
@ -11153,10 +11154,13 @@ def _xai_device_poller(session_id: str) -> None:
discovery=discovery,
last_refresh=datetime.now(timezone.utc).isoformat().replace("+00:00", "Z"),
auth_mode="oauth_device_code",
# Dashboard OAuth only bootstraps credentials for side tools;
# do not hijack the active chat inference provider.
# Persist credentials without hijacking an existing active
# chat provider.
set_active=False,
)
# Mirror `hermes auth add xai-oauth`: first credential may become
# active when none is set yet; never overwrite an existing choice.
mark_provider_active_if_unset("xai-oauth")
# The singleton write above is the single source of truth: the
# credential-pool load seeds it as the canonical ``device_code``
# entry. Do NOT also insert a parallel ``manual:dashboard_*`` pool