-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Fix dynamic provider model validation to prevent cross-contamination #9054
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
- Add getValidatedModelId() helper function to validate configured model IDs - Apply validation to all 10 dynamic providers that use routerModels - Fix issue where switching between dynamic providers would default to sonnet 4 - Ensure configured model ID exists in current provider before using it - Centralize provider default model ID logic in getProviderDefaultModelId() Fixes cross-contamination when switching from OpenRouter → Chutes (second time) where apiModelId would contain OpenRouter's model ID that doesn't exist in Chutes
Contributor
All issues have been resolved.
Mention @roomote to ask your PR Fixer agent to address the feedback. |
- Fix tests that were expecting old cross-contamination behavior - Update expectations to match new validation logic that prevents using configured model IDs when they don't exist in current provider's models - All tests now pass and validate the correct fallback-to-default behavior
- Pass raw apiConfiguration.vercelAiGatewayModelId to getValidatedModelId() - Remove ?? defaultModelId fallback that bypassed validation logic - Now consistent with all other dynamic providers (openrouter, requesty, etc) - Ensures helper function properly validates undefined cases
Also fixes issue #9047 where switching providers after selecting a model causes TypeError when router models are undefined during transitions.
mrubens
approved these changes
Nov 5, 2025
mini2s
added a commit
to zgsm-ai/costrict
that referenced
this pull request
Nov 6, 2025
Problem
When switching between dynamic providers (like OpenRouter to Chutes), the extension would sometimes default to Claude Sonnet 4 instead of the provider's default model. This happened because configured model IDs from the previous provider were being used with the new provider, even when that model doesn't exist in the new provider's model list.
Additionally, when users switch providers after selecting a model, the router models for the new provider may not be loaded yet, causing a TypeError when the code tries to access properties on undefined objects (fixes #9047).
Root Cause
The issue was cross-contamination between providers. For example:
anthropic/claude-sonnet-4.5apiConfiguration.apiModelIdstill containsanthropic/claude-sonnet-4.5Solution
1. Created reusable validation helper
Added
getValidatedModelId()function that ensures the configured model ID exists in the current provider's available models before using it.2. Applied to ALL dynamic providers
Updated all 10 dynamic providers that use
routerModels:3. Centralized default model logic
Created
getProviderDefaultModelId()function to centralize provider default model logic and reduce import bloat.4. Added optional chaining for TypeError prevention
Added optional chaining (
?.) to all router model accesses to safely handle cases where router models are undefined during provider transitions.Benefits
Testing
Fixes #9047 and supersedes #9049