fix(credential_pool): resolve key mix-up when custom providers share base_url#19094
Closed
shellybotmoyer wants to merge 1 commit into
Closed
Conversation
…base_url When multiple custom_providers share the same base_url but have different API keys, get_custom_provider_pool_key() always returned the first match, causing wrong-key unauthorized errors. Add provider_name parameter to prefer exact name matches over base_url-only matching, with fallback for backward compatibility. Fixes NousResearch#19083
Collaborator
|
Related to #14142 and #18804 — all three PRs fix the same credential pool key mix-up when custom providers share base_url (root issue #14141). This PR takes a different approach (adding provider_name param to get_custom_provider_pool_key) vs #14142 (prioritizing provider's own api_key) and #18804 (credential isolation via slug). Maintainer should pick one approach. |
Collaborator
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.
Fix: Credential pool key mix-up when custom providers share base_url
Fixes #19083
Problem
When multiple
custom_providersshare the samebase_urlbut have differentapi_keyvalues,get_custom_provider_pool_key(base_url)always returns the first match in iteration order, causing API requests to use the wrong key (401 Unauthorized).Root Cause
get_custom_provider_pool_key()inagent/credential_pool.pymatches only bybase_url, ignoring which provider name was actually requested. When two providers share a base URL, the first one always wins.Fix
get_custom_provider_pool_key(base_url, provider_name=None)— Add optionalprovider_nameparameter. When provided, prefer exact name match over base_url matching. Falls back to base_url-only matching when no name match is found (backward compatible)._try_resolve_from_custom_pool()— Addprovider_nameparameter and forward it toget_custom_provider_pool_key().Call sites in
hermes_cli/runtime_provider.py:_get_named_custom_provider()path: passcustom_provider.get("name")as the provider name_resolve_openrouter_runtime()path: passrequested_providerwhen it's a named custom provider (not bare"custom")Test
Added
test_get_custom_provider_pool_key_prefers_name_over_base_urlcovering:provider_name: first match wins (backward compatible)provider_name: exact name match wins regardless of iteration orderprovider_name: falls back to base_url matchingprovider_name: same as None (backward compatible)Reproduction