fix(providers): warn on duplicate name/alias registration (#30921)#30984
Open
Linux2010 wants to merge 4 commits into
Open
fix(providers): warn on duplicate name/alias registration (#30921)#30984Linux2010 wants to merge 4 commits into
Linux2010 wants to merge 4 commits into
Conversation
Collaborator
…ch#30921) register_provider() in providers/__init__.py silently overwrote entries in _REGISTRY and _ALIASES when duplicate names or aliases were registered (common with custom model-provider plugins). This made conflicts invisible — users had no way to know which profile was active. Fix: add existence checks before insertion: - If profile.name is already in _REGISTRY, log a warning showing which module registered first and which module is re-registering. - If any alias is already mapped to a different canonical name, log a warning showing the old and new mapping. Test: add test_duplicate_name_warns and test_duplicate_alias_warns to tests/providers/test_provider_profiles.py using caplog.
The tests assumed nvidia and openrouter were already registered, but discovery must be triggered first. Also switch alias test to use nvidia-nim which reliably exists after discovery. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
402dd00 to
a7dfcbc
Compare
- Add linux2010@github.com to AUTHOR_MAP for check-attribution - Restore original nvidia profile after test_duplicate_name_warns - Cleanup __test_override__ and restore nvidia-nim alias after test_duplicate_alias_warns to prevent breaking TestNvidiaProfile tests Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
What broke
register_provider()inproviders/__init__.pysilently overwrites entries in_REGISTRYand_ALIASESwhen duplicate names or aliases are registered. This is common when users add custom model-provider plugins, but there is no warning or doctor output — the last registration silently wins with no visibility.Root cause
register_provider()at lines 53-62 has no existence check or logging before inserting into_REGISTRY[profile.name]and_ALIASES[alias]. Users have no way to know which profile is active when names collide.Why this fix is minimal
Two simple guards added to
register_provider():profile.nameis already in_REGISTRY, log a warning showing which module registered first and which is re-registering.No behavior change — duplicate registrations still win (last-writer-wins), but now users are informed. No changes to discovery order,
_ALIASESstructure, or any other module.What I tested
Added two new tests in
tests/providers/test_provider_profiles.py:test_duplicate_name_warns— verifies warning is logged when same name is re-registeredtest_duplicate_alias_warns— verifies warning is logged when an overlapping alias is remapped, and that the alias is correctly updatedWhat I intentionally did not change
hermes doctoroutput (can be a follow-up PR to surface active overrides)