fix(model): clear stale endpoint credentials across all provider switches - #49380
Merged
Conversation
Contributor
🔎 Lint report:
|
| Rule | Count |
|---|---|
unsupported-operator |
2 |
not-subscriptable |
1 |
invalid-assignment |
1 |
First entries
tests/cli/test_cli_provider_resolution.py:376: [not-subscriptable] not-subscriptable: Cannot subscript object of type `None` with no `__getitem__` method
tests/cli/test_cli_provider_resolution.py:378: [unsupported-operator] unsupported-operator: Operator `not in` is not supported between objects of type `Literal["api_mode"]` and `Unknown | None`
tests/run_agent/test_credits_notices_toggle.py:76: [invalid-assignment] invalid-assignment: Object of type `None` is not assignable to attribute `_credits_session_start_micros` of type `int`
tests/cli/test_cli_provider_resolution.py:377: [unsupported-operator] unsupported-operator: Operator `not in` is not supported between objects of type `Literal["api_key"]` and `Unknown | None`
✅ Fixed issues (2):
| Rule | Count |
|---|---|
unresolved-attribute |
2 |
First entries
run_agent.py:2984: [unresolved-attribute] unresolved-attribute: Object of type `Self@get_credits_spent_micros` has no attribute `_credits_session_start_micros`
tests/run_agent/test_credits_notices_toggle.py:76: [unresolved-attribute] unresolved-attribute: Unresolved attribute `_credits_session_start_micros` on type `AIAgent`
Unchanged: 5881 pre-existing issues carried over.
Diagnostics are surfaced as warnings — this check never fails the build.
This was referenced Jun 20, 2026
This was referenced Jun 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Switching away from a custom provider no longer leaves a stale
model.api_key(or legacymodel.api/model.api_mode) sitting inconfig.yamlto override the new provider's credential resolution.Root cause: the custom-endpoint flow persists
model.api_keytoconfig.yaml. Every other provider-switch path then wrote provider/base_url back without clearing it, so the old custom key survived and contaminated the new provider — which resolves credentials from env/auth.json/credential pool, not inline config.Changes
hermes_cli/config.py: new shared helperclear_model_endpoint_credentials()(toggles forapi_key/api_mode, also clears legacyapi).hermes_cli/model_setup_flows.py: apply the helper across all provider-switch flows — nous, openrouter, api_key_provider, azure_foundry, copilot, copilot_acp, kimi, stepfun, bedrock, bedrock_api_key, anthropic. Nous also reloads config after the auth helper writes provider state so the stale in-memory copy can't clobber it.hermes_cli/auth.py:_update_config_for_provider()now uses the shared helper (also picks up the legacymodel.apifield it previously missed).hermes_cli/web_server.py: Desktop/web main + auxiliary model assignment clear stale endpoint creds + base_url on provider change (guarded socustomkeeps its key).gateway/slash_commands.py: both/model --globalpersistence sites clear stale creds on a non-custom switch.The Bedrock Mantle custom flow is included — it previously saved
provider: customwith a changed endpoint while leaving the prior custom key, which could route Bedrock with the wrong credential.Validation
model.api_keypersists336 targeted tests pass (
tests/cli/test_cli_provider_resolution.py,tests/hermes_cli/test_update_config_clears_custom_fields.py,tests/gateway/test_model_picker_persist.py,tests/hermes_cli/test_web_server.py).Credit
Salvage of #49360 by @helix4u, who triaged the report, found the root cause, and authored the comprehensive shared-helper fix (both commits preserved via rebase-merge). Supersedes #49362 by @infinitycrew39, who correctly extended the original Nous fix to the three main CLI flows and prompted the wider audit — credited there.
Closes #49360.
Infographic