From 0d761ca6084efb1344591870ce58d96b6a9be051 Mon Sep 17 00:00:00 2001 From: yangmanqing Date: Tue, 24 Feb 2026 17:57:28 +0800 Subject: [PATCH] fix: prevent DefaultConfig template values from leaking into user model_list entries --- pkg/config/config.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/config/config.go b/pkg/config/config.go index 2595398c7b..a15a19b910 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -499,6 +499,20 @@ func LoadConfig(path string) (*Config, error) { return nil, err } + // Pre-scan the JSON to check how many model_list entries the user provided. + // Go's JSON decoder reuses existing slice backing-array elements rather than + // zero-initializing them, so fields absent from the user's JSON (e.g. api_base) + // would silently inherit values from the DefaultConfig template at the same + // index position. We only reset cfg.ModelList when the user actually provides + // entries; when count is 0 we keep DefaultConfig's built-in list as fallback. + var tmp Config + if err := json.Unmarshal(data, &tmp); err != nil { + return nil, err + } + if len(tmp.ModelList) > 0 { + cfg.ModelList = nil + } + if err := json.Unmarshal(data, cfg); err != nil { return nil, err }