From 63af4c551d19e088bc7a05ea8f8b0f3e93ebe41e Mon Sep 17 00:00:00 2001 From: hkfires <10558748+hkfires@users.noreply.github.com> Date: Fri, 26 Sep 2025 17:17:43 +0800 Subject: [PATCH] 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. --- internal/registry/model_registry.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/registry/model_registry.go b/internal/registry/model_registry.go index 0a941916..a2de4831 100644 --- a/internal/registry/model_registry.go +++ b/internal/registry/model_registry.go @@ -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 {