fix(config): ensure user model_list isn't overridden with default models if originally empty

Previously, `loadConfig` in `pkg/config/migration.go` checked `len(tmp.ModelList) > 0` to decide whether to override the default loaded `cfg.ModelList`. If the user has manually cleared out their model list, leaving it as an empty array (`[]`), the unmarshaling would fail this condition and revert their list to the long default list again whenever the configuration is saved.

This commit changes the condition to use `json.RawMessage` to accurately detect if the `model_list` key was actually present in the file, regardless of its length.

Co-authored-by: TanLuong <28281768+TanLuong@users.noreply.github.com>
This commit is contained in:
google-labs-jules[bot] 2026-03-27 03:36:50 +00:00
parent f63ddcfae2
commit 5d4d177a58
2 changed files with 25 additions and 2 deletions

View file

@ -521,11 +521,13 @@ func loadConfig(data []byte) (*Config, error) {
// 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
var tmp struct {
ModelList json.RawMessage `json:"model_list"`
}
if err := json.Unmarshal(data, &tmp); err != nil {
return nil, err
}
if len(tmp.ModelList) > 0 {
if tmp.ModelList != nil {
cfg.ModelList = nil
}

View file

@ -0,0 +1,21 @@
--- pkg/config/migration.go
+++ pkg/config/migration.go
@@ -515,11 +515,16 @@
// 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
+ var tmp struct {
+ ModelList json.RawMessage `json:"model_list"`
+ }
if err := json.Unmarshal(data, &tmp); err != nil {
return nil, err
}
- if len(tmp.ModelList) > 0 {
+ if tmp.ModelList != nil {
+ // User explicitly defined model_list, even if it's empty []
cfg.ModelList = nil
}
if err := json.Unmarshal(data, cfg); err != nil {