From b0f2ad7cfe2e568c27c535cd0f72c3249c796858 Mon Sep 17 00:00:00 2001 From: hkfires <10558748+hkfires@users.noreply.github.com> Date: Fri, 26 Sep 2025 22:04:32 +0800 Subject: [PATCH] fix(cliproxy): Clear stale compatibility model registrations Previously, if an OpenAI compatibility configuration was removed from the config file or its model list was emptied, the associated models for that auth entry were not unregistered from the global model registry. This resulted in stale registrations persisting. This change ensures that when an auth entry is identified as being for a compatibility provider, its models are explicitly unregistered if: - The corresponding configuration is found but has an empty model list. - The corresponding configuration is no longer found in the config file. --- sdk/cliproxy/service.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/sdk/cliproxy/service.go b/sdk/cliproxy/service.go index 725bc4e6..904eff4c 100644 --- a/sdk/cliproxy/service.go +++ b/sdk/cliproxy/service.go @@ -508,22 +508,35 @@ func (s *Service) registerModelsForAuth(a *coreauth.Auth) { if s.cfg != nil { providerKey := provider compatName := strings.TrimSpace(a.Provider) + isCompatAuth := false if strings.EqualFold(providerKey, "openai-compatibility") { + isCompatAuth = true if a.Attributes != nil { if v := strings.TrimSpace(a.Attributes["compat_name"]); v != "" { compatName = v } if v := strings.TrimSpace(a.Attributes["provider_key"]); v != "" { providerKey = strings.ToLower(v) + isCompatAuth = true } } if providerKey == "openai-compatibility" && compatName != "" { providerKey = strings.ToLower(compatName) } + } else if a.Attributes != nil { + if v := strings.TrimSpace(a.Attributes["compat_name"]); v != "" { + compatName = v + isCompatAuth = true + } + if v := strings.TrimSpace(a.Attributes["provider_key"]); v != "" { + providerKey = strings.ToLower(v) + isCompatAuth = true + } } for i := range s.cfg.OpenAICompatibility { compat := &s.cfg.OpenAICompatibility[i] if strings.EqualFold(compat.Name, compatName) { + isCompatAuth = true // Convert compatibility models to registry models ms := make([]*ModelInfo, 0, len(compat.Models)) for j := range compat.Models { @@ -543,10 +556,18 @@ func (s *Service) registerModelsForAuth(a *coreauth.Auth) { providerKey = "openai-compatibility" } GlobalModelRegistry().RegisterClient(a.ID, providerKey, ms) + } else { + // Ensure stale registrations are cleared when model list becomes empty. + GlobalModelRegistry().UnregisterClient(a.ID) } return } } + if isCompatAuth { + // No matching provider found or models removed entirely; drop any prior registration. + GlobalModelRegistry().UnregisterClient(a.ID) + return + } } } if len(models) > 0 {