mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 04:50:52 +08:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user