fix(fallback): let custom_providers shadow built-in aliases#18185
Merged
Conversation
Collaborator
When a user defines `custom_providers: [{name: kimi, ...}]` and references
`provider: kimi` from fallback_model or the main config, the built-in alias
rewriting (`kimi` → `kimi-coding`) was hijacking the request before the
named-custom lookup ran. `_get_named_custom_provider` also refused to
return a match when the raw name resolved to any built-in (including aliases),
so the custom endpoint was unreachable.
Fix at both layers of the resolution chain so every caller benefits, not
just `_try_activate_fallback`:
- hermes_cli/runtime_provider.py: narrow `_get_named_custom_provider`'s
built-in-wins guard to canonical provider names only. An alias like
`kimi` that resolves to a different canonical (`kimi-coding`) no longer
blocks the custom lookup; a canonical name like `nous` still does.
- agent/auxiliary_client.py: in `resolve_provider_client`, try the named-
custom lookup with the original (pre-alias-normalization) name before the
alias-normalized one, so aliased requests reach the user's custom entry.
Also honour `explicit_base_url` and `explicit_api_key` in the API-key
provider branch so callers that pass explicit hints (e.g. fallback
activation) can override the registered defaults.
Tests added for:
- custom `kimi` shadowing built-in alias (regression for #15743)
- custom `nous` NOT shadowing canonical built-in (behaviour preserved)
- bare `kimi` without any custom entry still routing to built-in
- explicit base_url/api_key override on the API-key provider branch
Original PR #17827 by @Feranmi10 identified the same bug class and
implemented a narrower fix in `_try_activate_fallback`; this reshapes the
fix to live in the shared resolution layer so all callers benefit.
Fixes #15743
Co-authored-by: Feranmi10 <89228157+Feranmi10@users.noreply.github.com>
72c7132 to
8097c4d
Compare
1 task
This was referenced May 24, 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
When a user defines a
custom_providersentry whose name coincidentally matches a built-in alias (e.g.kimi→kimi-coding), the built-in alias rewriting was hijacking the request before the named-custom lookup ran, so the custom endpoint was unreachable. Fallback activation in particular would silently drop the custom fallback and leave the primary provider's base_url in place.Fixed at the shared resolution layer so every caller benefits —
_try_activate_fallback,resolve_provider_clientfrom auxiliary routing, and_resolve_named_custom_runtimefor main provider resolution — not just the fallback path.Changes
_get_named_custom_provider's built-in-wins guard now only fires for canonical provider names (nous,openrouter, …). Raw names that are aliases to a different canonical (kimi→kimi-coding) no longer block the custom lookup.resolve_provider_clienttries the named-custom lookup with the original (pre-alias-normalization) name before the normalized one. Also honoursexplicit_base_url/explicit_api_keyin the API-key branch so callers that pass explicit hints can override the registered defaults.kimishadowing built-in alias, customnousNOT shadowing canonical (behaviour preserved), barekimiwithout custom still routing to built-in, explicit overrides on the API-key branch.Validation
kimi→ falls backaliyun-singapore→ falls backnouswith shadow customkimiwithout any custom entryFull relevant test suite:
tests/hermes_cli/test_runtime_provider_resolution.py+tests/hermes_cli/test_user_providers_model_switch.py+tests/agent/test_auxiliary_named_custom_providers.py→ 167 passed.Credit
Original PR #17827 by @Feranmi10 identified the same bug class and implemented a narrower fix in
_try_activate_fallback. This reshapes the fix to live in the shared resolution layer so all callers benefit; Feranmi10 is credited viaCo-authored-by:.Fixes #15743
Closes #17827