fix(phase-2): add thread-safety to ModelRegistry and Router reload operations

This commit is contained in:
newkirk
2026-07-21 13:20:29 -04:00
parent 42b70621a1
commit 4027ed4351
3 changed files with 29 additions and 4 deletions
+11 -1
View File
@@ -1,6 +1,9 @@
package models
import "strings"
import (
"strings"
"sync"
)
// CanonicalProviders lists the original model creators in priority order.
// When a model name exists in multiple providers (e.g. deepseek-v4-pro in
@@ -22,6 +25,7 @@ var CanonicalProviders = []string{
}
type ModelRegistry struct {
mu sync.RWMutex
Providers map[string]ProviderInfo `json:"-"`
}
@@ -173,6 +177,12 @@ func (r *ModelRegistry) findAllForwardFuzzy(modelID string) (*ModelMetadata, boo
// etc.) from overriding the original provider's authoritative pricing and
// limits.
func (r *ModelRegistry) FindModel(modelID string) *ModelMetadata {
if r == nil {
return nil
}
r.mu.RLock()
defer r.mu.RUnlock()
// 1. Exact key match — canonical first, then all
if m, ok := r.findInCanonical(modelID); ok {
return m