fix(openai): retain capabilities when model listing is unavailable

This commit is contained in:
lyy0709
2026-09-05 16:24:15 +08:00
parent dee35a841d
commit 62cd63bfda
2 changed files with 13 additions and 1 deletions
+9 -1
View File
@@ -208,6 +208,7 @@ func (s *AccountTestService) FetchUpstreamSupportedModels(ctx context.Context, a
// untouched.
func (s *AccountTestService) SyncUpstreamModelCatalog(ctx context.Context, account *Account) (*UpstreamModelCatalog, error) {
models, body, err := s.fetchUpstreamModelList(ctx, account)
liveListAvailable := err == nil
if err != nil {
configuredModels := configuredUpstreamModelsForCapabilitySync(account)
if !upstreamModelListEndpointUnsupported(err) || len(configuredModels) == 0 {
@@ -264,7 +265,14 @@ func (s *AccountTestService) SyncUpstreamModelCatalog(ctx context.Context, accou
if len(completeMetadata) > 0 && account != nil && account.ID > 0 && s.accountRepo != nil {
// Retain known metadata only for models still listed or explicitly mapped.
if previous := account.GetUpstreamModelMetadataSnapshot(); previous != nil {
for _, modelID := range capabilityIDs {
retainedModels := capabilityIDs
if !liveListAvailable {
retainedModels = append([]string(nil), capabilityIDs...)
for modelID := range previous.Models {
retainedModels = append(retainedModels, modelID)
}
}
for _, modelID := range retainedModels {
old, exists := previous.Models[modelID]
if !exists {
continue
@@ -545,8 +545,12 @@ func TestSyncUpstreamModelCatalogUsesConfiguredModelsWhenListEndpointUnsupported
},
}
account.SetUpstreamModelMetadataSnapshot(UpstreamModelMetadataSnapshot{Models: map[string]UpstreamModelMetadata{
"old-live-model": {ID: "old-live-model", ContextWindow: 256000},
}})
catalog, err := svc.SyncUpstreamModelCatalog(context.Background(), account)
require.NoError(t, err)
require.Contains(t, account.GetUpstreamModelMetadataSnapshot().Models, "old-live-model", "an unavailable model-list endpoint is not evidence of removal")
require.Equal(t, []string{"glm-5.3"}, catalog.Models)
require.Empty(t, catalog.Warnings)
require.Len(t, upstream.requests, 2)