fix(tui): fall back on primary AuthError during agent creation - #43861
fix(tui): fall back on primary AuthError during agent creation#43861VrtxOmega wants to merge 3 commits into
Conversation
|
Two test assertions will fail when CI runs: 1.
assert captured["api_key"] == "fallback-key"The mock resolution for assert captured["api_key"] == "***"2.
assert captured["fallback_model"] == fallback_chainwhere |
|
Thanks @liuhao1024 — took another pass on the assertions:
.venv/bin/python3 -m pytest \
tests/test_tui_gateway_server.py::test_resolve_runtime_with_auth_fallback_returns_fallback_entry_model \
tests/test_tui_gateway_server.py::test_make_agent_falls_back_on_primary_auth_error \
tests/test_tui_gateway_server.py::test_make_agent_auth_fallback_skips_stale_session_overrides \
tests/gateway/test_auth_fallback.py -q7 passed locally. |
…esearch#43588) Desktop/TUI gateway called resolve_runtime_provider() directly in _make_agent without trying fallback_providers, so a dead xAI OAuth primary hard-errored on the first message while CLI and messaging gateway already fell through. Mirror gateway/CLI auth-fallback resolution at TUI agent build time and add regression tests for the happy and no-fallback paths.
When _make_agent falls back from a dead primary, do not re-apply persisted model_override credentials from the failed provider — they would clobber the healthy fallback runtime.
Add a direct _resolve_runtime_with_auth_fallback unit test documenting that the helper's second return value is the config entry model string, while AIAgent.fallback_model still receives the full chain from _load_fallback_model(). Derive api_key assertions from the mock runtime dict so expectations stay tied to fake_resolve output.
88edff5 to
e521b87
Compare
|
Thanks for the focused regression coverage. Current main contains an overlapping init-time AuthError fallback from Problems
Suggested changes
Automated hermes-sweeper review. |
A fallback chain entry can name its API key via key_env (or the api_key_env alias) per the fallback-providers docs, but only the gateway path resolved it — TUI/desktop, cron, and CLI setup fallbacks ignored it, so a fallback provider whose key lives in a non-standard env var never resolved on those surfaces. Centralize the inline-api_key-then-key_env lookup in hermes_cli/fallback_config.resolve_entry_api_key() and use it at all four fallback resolution sites (tui_gateway, cron scheduler, gateway runner, CLI setup mixin); the CLI mixin also gains the base_url passthrough the other surfaces already had. Salvaged from PR #43861 (surgical reapply — the original branch predates the #65264 fallback restructuring).
A fallback chain entry can name its API key via key_env (or the api_key_env alias) per the fallback-providers docs, but only the gateway path resolved it — TUI/desktop, cron, and CLI setup fallbacks ignored it, so a fallback provider whose key lives in a non-standard env var never resolved on those surfaces. Centralize the inline-api_key-then-key_env lookup in hermes_cli/fallback_config.resolve_entry_api_key() and use it at all four fallback resolution sites (tui_gateway, cron scheduler, gateway runner, CLI setup mixin); the CLI mixin also gains the base_url passthrough the other surfaces already had. Salvaged from PR #43861 (surgical reapply — the original branch predates the #65264 fallback restructuring).
|
Merged via PR #65682 with you credited as commit author ( |
A fallback chain entry can name its API key via key_env (or the api_key_env alias) per the fallback-providers docs, but only the gateway path resolved it — TUI/desktop, cron, and CLI setup fallbacks ignored it, so a fallback provider whose key lives in a non-standard env var never resolved on those surfaces. Centralize the inline-api_key-then-key_env lookup in hermes_cli/fallback_config.resolve_entry_api_key() and use it at all four fallback resolution sites (tui_gateway, cron scheduler, gateway runner, CLI setup mixin); the CLI mixin also gains the base_url passthrough the other surfaces already had. Salvaged from PR NousResearch#43861 (surgical reapply — the original branch predates the NousResearch#65264 fallback restructuring).
A fallback chain entry can name its API key via key_env (or the api_key_env alias) per the fallback-providers docs, but only the gateway path resolved it — TUI/desktop, cron, and CLI setup fallbacks ignored it, so a fallback provider whose key lives in a non-standard env var never resolved on those surfaces. Centralize the inline-api_key-then-key_env lookup in hermes_cli/fallback_config.resolve_entry_api_key() and use it at all four fallback resolution sites (tui_gateway, cron scheduler, gateway runner, CLI setup mixin); the CLI mixin also gains the base_url passthrough the other surfaces already had. Salvaged from PR NousResearch#43861 (surgical reapply — the original branch predates the NousResearch#65264 fallback restructuring).
Fixes #43588
Problem
When
model.provideris an OAuth provider with invalid/revoked credentials (e.g.xai-oauth) butfallback_providersis configured, the CLI and messaging gateway already fall through to the fallback chain. Desktop/TUI hard-errored on the first message because_make_agent()calledresolve_runtime_provider()directly with noAuthError→ fallback handling.Fix
Add
_resolve_runtime_with_auth_fallback()intui_gateway/server.py, mirroringgateway/run.py::_resolve_runtime_agent_kwargsand CLI_ensure_runtime_credentials._make_agent()now tries the configured fallback chain on primaryAuthErrorand switches to the fallback model when resolution succeeds.Tests
test_make_agent_falls_back_on_primary_auth_error— dead xAI OAuth → openrouter fallbacktest_make_agent_auth_error_without_fallback_raises— no fallback configured still surfaces error