From 7572e3b95d2a7a0f612306b84932da35c449643e Mon Sep 17 00:00:00 2001 From: yinwm Date: Fri, 20 Feb 2026 11:46:28 +0800 Subject: [PATCH] fix(config): allow duplicate model_name for load balancing Remove duplicate model_name check in ValidateModelList to support load balancing feature where multiple configs can share the same model_name for round-robin selection. Update tests to reflect the new behavior. Co-Authored-By: Claude Opus 4.6 --- pkg/config/config.go | 11 ++--------- pkg/config/model_config_test.go | 12 ++++++------ 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index a33bd81e3..2dd188572 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -583,20 +583,13 @@ func (c *Config) HasProvidersConfig() bool { } // ValidateModelList validates all ModelConfig entries in the model_list. -// It checks that each model_name/model combination is valid and that -// model_name is unique across all entries. +// It checks that each model config is valid. +// Note: Multiple entries with the same model_name are allowed for load balancing. func (c *Config) ValidateModelList() error { - seen := make(map[string]int) for i := range c.ModelList { if err := c.ModelList[i].Validate(); err != nil { return fmt.Errorf("model_list[%d]: %w", i, err) } - // Check for duplicate model_name - name := c.ModelList[i].ModelName - if prevIdx, exists := seen[name]; exists { - return fmt.Errorf("model_list: duplicate model_name %q at index %d and %d", name, prevIdx, i) - } - seen[name] = i } return nil } diff --git a/pkg/config/model_config_test.go b/pkg/config/model_config_test.go index 867e9ebf1..3c411dc0f 100644 --- a/pkg/config/model_config_test.go +++ b/pkg/config/model_config_test.go @@ -195,18 +195,19 @@ func TestConfig_ValidateModelList(t *testing.T) { wantErr: false, }, { - name: "duplicate model_name", + // Load balancing: multiple entries with same model_name are allowed + name: "duplicate model_name for load balancing", config: &Config{ ModelList: []ModelConfig{ {ModelName: "gpt-4", Model: "openai/gpt-4o", APIKey: "key1"}, {ModelName: "gpt-4", Model: "openai/gpt-4-turbo", APIKey: "key2"}, }, }, - wantErr: true, - errMsg: "duplicate model_name", + wantErr: false, // Changed: duplicates are allowed for load balancing }, { - name: "duplicate model_name non-adjacent", + // Load balancing: non-adjacent entries with same model_name are also allowed + name: "duplicate model_name non-adjacent for load balancing", config: &Config{ ModelList: []ModelConfig{ {ModelName: "model-a", Model: "openai/gpt-4o"}, @@ -214,8 +215,7 @@ func TestConfig_ValidateModelList(t *testing.T) { {ModelName: "model-a", Model: "openai/gpt-4-turbo"}, }, }, - wantErr: true, - errMsg: "duplicate model_name \"model-a\"", + wantErr: false, // Changed: duplicates are allowed for load balancing }, }