fix FindModel: prioritize canonical providers to prevent reseller limit overrides
CI / Lint (push) Has been cancelled
CI / Test (push) Has been cancelled
CI / Build (push) Has been cancelled

FindModel iterates providers in random map order, so when deepseek-v4-pro
exists in both 'deepseek' (output=384000) and 'ollama-cloud' (output=1048576),
it sometimes returned the wrong metadata. The proxy then injected
max_tokens=1048576 into DeepSeek's API, which rejected it with 400
(valid range is [1, 393216]).

Fix: define CanonicalProviders list (deepseek, openai, google, xai, etc.)
and search them in priority order before falling back to all providers.
Each of the four lookup strategies (exact key, metadata ID, reverse fuzzy,
forward fuzzy) checks canonical providers first.
This commit is contained in:
2026-05-07 14:47:17 -04:00
parent b7df3108fa
commit d2b9da89d9
3 changed files with 1102 additions and 22 deletions
+29
View File
@@ -59,6 +59,35 @@ func TestModelRegistry_FindModel_NotFound(t *testing.T) {
}
}
func TestModelRegistry_FindModel_CanonicalPriority(t *testing.T) {
// Same model name in canonical (deepseek) and reseller (ollama-cloud).
// Canonical must win so the proxy uses authoritative limits.
r := &ModelRegistry{
Providers: map[string]ProviderInfo{
"ollama-cloud": {
Models: map[string]ModelMetadata{
"deepseek-v4-pro": {ID: "deepseek-v4-pro", Name: "DSv4 Pro (Ollama Cloud)", Limit: &ModelLimit{Context: 1048576, Output: 1048576}},
},
},
"deepseek": {
Models: map[string]ModelMetadata{
"deepseek-v4-pro": {ID: "deepseek-v4-pro", Name: "DeepSeek v4 Pro", Limit: &ModelLimit{Context: 1000000, Output: 384000}},
},
},
},
}
m := r.FindModel("deepseek-v4-pro")
if m == nil {
t.Fatal("expected to find deepseek-v4-pro")
}
if m.Name != "DeepSeek v4 Pro" {
t.Fatalf("expected DeepSeek v4 Pro (canonical), got %s", m.Name)
}
if m.Limit.Output != 384000 {
t.Fatalf("expected output limit 384000 (canonical), got %d", m.Limit.Output)
}
}
func TestModelRegistry_FindModel_ReverseFuzzy(t *testing.T) {
r := &ModelRegistry{
Providers: map[string]ProviderInfo{