Skip to content

fix: openrouter in providers and modellist length is greater than 0#766

Open
penzhan8451 wants to merge 1 commit intosipeed:mainfrom
penzhan8451:main
Open

fix: openrouter in providers and modellist length is greater than 0#766
penzhan8451 wants to merge 1 commit intosipeed:mainfrom
penzhan8451:main

Conversation

@penzhan8451
Copy link

📝 Description

🗣️ Type of Change

  • [ ☑️] 🐞 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 📖 Documentation update
  • ⚡ Code refactoring (no functional changes, no api changes)

🤖 AI Code Generation

  • [☑️ ] 🤖 Fully AI-generated (100% AI, 0% Human)
  • 🛠️ Mostly AI-generated (AI draft, Human verified/modified)
  • 👨‍💻 Mostly Human-written (Human lead, AI assisted or none)

🔗 Related Issue

📚 Technical Context (Skip for Docs)

  • Reference URL:

  • Reasoning:
    /////////////
    when user setup both:

    1. model_list length is greater than 0(but no openrouter config)
    2. providers include openrouter config

this will skip providers configuration,and will return with err
/////////////

🧪 Test Environment

  • Hardware:
  • OS: MacOS
  • Model/Provider:
  • Channels:

📸 Evidence (Optional)

Details

when user setup both:

 1. model_list length is greater than 0(but no openrouter config)
 2. providers include openrouter config

this will skip providers configuration,and will return with err

Click to view Logs/Screenshots

☑️ Checklist

  • [☑️ ] My code/docs follow the style of this project.
  • I have performed a self-review of my own changes.
  • I have updated the documentation accordingly.

Copy link
Author

@penzhan8451 penzhan8451 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case of openrouter is in providers and modellist is not empty && modellist does not contain openrouter config, an error will be returned and the process will quit.

Comment on lines +26 to +35
providerModels := config.ConvertProvidersToModelList(cfg)
existingModelNames := make(map[string]bool)
for _, m := range cfg.ModelList {
existingModelNames[m.ModelName] = true
}
for _, pm := range providerModels {
if !existingModelNames[pm.ModelName] {
cfg.ModelList = append(cfg.ModelList, pm)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
providerModels := config.ConvertProvidersToModelList(cfg)
existingModelNames := make(map[string]bool)
for _, m := range cfg.ModelList {
existingModelNames[m.ModelName] = true
}
for _, pm := range providerModels {
if !existingModelNames[pm.ModelName] {
cfg.ModelList = append(cfg.ModelList, pm)
}
}
providerModels := config.ConvertProvidersToModelList(cfg)
existing := make(map[string]struct{}, len(cfg.ModelList)+len(providerModels))
for _, m := range cfg.ModelList {
existing[m.ModelName] = struct{}{}
}
var toAdd []Model
for _, pm := range providerModels {
if _, ok := existing[pm.ModelName]; !ok {
toAdd = append(toAdd, pm)
existing[pm.ModelName] = struct{}{}
}
}
cfg.ModelList = append(cfg.ModelList, toAdd...)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yumosx It is ok for me.

@xiaket xiaket added bug Something isn't working domain: provider labels Feb 25, 2026
Copy link

@nikolasdehor nikolasdehor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good bug fix. The problem is clear: when a user has both model_list entries and providers config, the old code skipped ConvertProvidersToModelList entirely if model_list was non-empty, meaning provider-sourced models (like OpenRouter) were silently dropped.

The fix correctly merges by deduplicating on ModelName. One edge case worth noting:

  • Name collision with different config: If a model in model_list and a provider have the same ModelName but different API keys or base URLs, the explicit model_list entry wins (it is kept, the provider entry is skipped). This seems like the right precedence but may be worth documenting.

Otherwise clean and minimal. LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working domain: provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants