diff --git a/internal/config/clone_test.go b/internal/config/clone_test.go index dd3f613db..8240b4995 100644 --- a/internal/config/clone_test.go +++ b/internal/config/clone_test.go @@ -32,6 +32,9 @@ func TestConfigCloneDeepCopiesReferenceFields(t *testing.T) { Hosted: map[string]ImageHostedProvider{"openai": {Enabled: true}}, Local: map[string]ImageLocalProvider{"sdxl": {Enabled: true}}, }, + Services: Services{ + ServiceNameState: {Target: "127.0.0.1:9090", TargetToken: "secret"}, + }, } got := orig.Clone() @@ -52,6 +55,7 @@ func TestConfigCloneDeepCopiesReferenceFields(t *testing.T) { *got.Tools.WebFetch.Enabled = false got.Image.Hosted["openai"] = ImageHostedProvider{Enabled: false} got.Image.Local["sdxl"] = ImageLocalProvider{Enabled: false} + got.Services[ServiceNameState] = ServiceConnection{Target: "changed"} if orig.Models["builder"] != "m" { t.Error("Models map is shared") @@ -95,4 +99,7 @@ func TestConfigCloneDeepCopiesReferenceFields(t *testing.T) { if !orig.Image.Local["sdxl"].Enabled { t.Error("Image.Local map is shared") } + if orig.Services[ServiceNameState].TargetToken != "secret" { + t.Error("Services map is shared") + } } diff --git a/internal/config/config.go b/internal/config/config.go index 7f169ecab..2627b3665 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -665,6 +665,11 @@ func (c Config) Clone() Config { c.Memory.ProviderConfig = maps.Clone(c.Memory.ProviderConfig) c.Image.Hosted = maps.Clone(c.Image.Hosted) c.Image.Local = maps.Clone(c.Image.Local) + // Services is a map of structs, so the header is shared by the value copy + // above and yaml.Unmarshal writes keys into whatever map it is handed. Without + // this line an overlay -- or a dashboard PATCH -- rewrites the PUBLISHED + // snapshot in place, which is the mutation Clone exists to prevent. + c.Services = maps.Clone(c.Services) if c.Tools.WebFetch.Enabled != nil { v := *c.Tools.WebFetch.Enabled c.Tools.WebFetch.Enabled = &v