fix(cli): preserve current credentials on same-provider model switch - #44502
liuhao1024 wants to merge 2 commits into
Conversation
When resolve_runtime_provider() returns an empty api_key or base_url during a same-provider switch (e.g. opencode-go mimo-v2.5 → kimi-k2.5), the code unconditionally overwrites the current working credentials with empty strings, causing 401 errors. Fallback to current_api_key / current_base_url when the resolved value is empty, matching the existing exception-path behavior. Fixes NousResearch#44490
|
Verified this against The fix is correct and the tests are genuine.
Two notes on the surrounding analysis:
LGTM. |
|
CI note: the red Fingerprint from the failing run (slice 2/6):
All other slices are green, and the added tests passed 4/4 when I ran them on the PR head locally (see my review comment above). A re-run of the failed job should go green unless the update tests land on the same slice again; the real fix is #43298. |
…o fix CI shard The standalone test file test_model_switch_same_provider_credential.py was not found by the CI sharded runner (exit code 4 on shard 2). Move the 4 tests into the existing test_model_switch_custom_providers.py which already has the required imports and mock fixtures.
|
Also checked the follow-up commit 72f8ac8: it's a pure test relocation — the four #44490 regression tests move from the standalone file into |
NousResearch#44502 follow-up) Mirrors upstream PR NousResearch#44502 commit 72f8ac8: relocates the four issue NousResearch#44490 regression tests from the standalone file into test_model_switch_custom_providers.py. Test bodies unchanged. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Thanks for the focused fix. The premise remains true on current Suggested changes
The fallback itself is appropriately narrow: it preserves empty-resolution credentials while continuing to prefer non-empty resolver output. This is an automated hermes-sweeper review. |
Pass live session URL/key as explicit_* for bare custom/local same-provider /model switches so resolve cannot fall through to OpenRouter. Drop the overlapping empty-result current_* refill (owned by NousResearch#44502). When a direct alias changes the host, clear the prior session key before validation so endpoint A's credential is never sent to host B.
What does this PR do?
Preserves current working credentials when
resolve_runtime_provider()returns emptyapi_key/base_urlduring a same-provider model switch. This fixes 401 errors when switching models on providers like opencode-go where the resolver does not re-resolve env-var credentials for the same provider.Related Issue
Fixes #44490
Type of Change
Changes Made
hermes_cli/model_switch.py: In the same-provider (provider_changed=False) branch ofswitch_model(), fallback tocurrent_api_key/current_base_urlwhenresolve_runtime_provider()returns empty values. Previously the code unconditionally overwrote credentials with empty strings.tests/hermes_cli/test_model_switch_same_provider_credential.py: New test file with 4 regression tests covering empty key fallback, empty base URL fallback, non-empty resolved values preferred, and both-empty fallback.How to Test
/model kimi-k2.5to switch frommimo-v2.5(same provider)pytest tests/hermes_cli/test_model_switch_same_provider_credential.py -vChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/ACode Intelligence
switch_model()same-provider branch (callers: 4, flows: CLI/gateway/TUI model switch)except: passalready preserves current credentials)