fix(registry): Fix provider change logic for new models

When a client changed its provider and registered a new model in the same `RegisterClient` call, the logic would incorrectly attempt to decrement the provider count for the new model from the old provider. This was because the loop iterated over all new model IDs without checking if they were part of the client's previous registration.

This commit adds a check to ensure that a model existed in the client's old model set before attempting to decrement the old provider's usage count. This prevents incorrect state updates in the registry during provider transitions that also introduce new models.
This commit is contained in:
hkfires
2025-09-26 17:17:43 +08:00
parent c675cf5e72
commit 63af4c551d

View File

@@ -169,6 +169,9 @@ func (r *ModelRegistry) RegisterClient(clientID, clientProvider string, models [
// Handle provider change for overlapping models before modifications.
if providerChanged && oldProvider != "" {
for _, id := range modelIDs {
if _, existed := oldSet[id]; !existed {
continue
}
if reg, ok := r.models[id]; ok && reg.Providers != nil {
if count, okProv := reg.Providers[oldProvider]; okProv {
if count <= 1 {