From ce4f43dd8dcee032691c735de2189f012a196c46 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Tue, 15 Sep 2026 04:38:54 +1000 Subject: [PATCH] fix(config): deep-copy Image.Hosted/Image.Local in Config.Clone Clone's own doc comment promises mutating the clone cannot touch memory shared with the original, but Image.Hosted/Image.Local were left as a shallow map copy -- a runtime overlay or dashboard PATCH decoding into the clone could mutate the published config's image provider maps. --- internal/config/clone_test.go | 12 ++++++++++++ internal/config/config.go | 2 ++ 2 files changed, 14 insertions(+) diff --git a/internal/config/clone_test.go b/internal/config/clone_test.go index a33561e9f..dd3f613db 100644 --- a/internal/config/clone_test.go +++ b/internal/config/clone_test.go @@ -28,6 +28,10 @@ func TestConfigCloneDeepCopiesReferenceFields(t *testing.T) { LegacyAgent: LegacyAgent{Env: []string{"HOME"}}, Extra: map[string]any{"custom": 1}, Bindings: BindingsConfig{PreviousEncryptionKeys: []SecretRef{{Engine: "env", Key: "K0"}}}, + Image: ImageConfig{ + Hosted: map[string]ImageHostedProvider{"openai": {Enabled: true}}, + Local: map[string]ImageLocalProvider{"sdxl": {Enabled: true}}, + }, } got := orig.Clone() @@ -46,6 +50,8 @@ func TestConfigCloneDeepCopiesReferenceFields(t *testing.T) { got.Extra["custom"] = 2 got.Bindings.PreviousEncryptionKeys[0] = SecretRef{Engine: "env", Key: "changed"} *got.Tools.WebFetch.Enabled = false + got.Image.Hosted["openai"] = ImageHostedProvider{Enabled: false} + got.Image.Local["sdxl"] = ImageLocalProvider{Enabled: false} if orig.Models["builder"] != "m" { t.Error("Models map is shared") @@ -83,4 +89,10 @@ func TestConfigCloneDeepCopiesReferenceFields(t *testing.T) { if !*orig.Tools.WebFetch.Enabled { t.Error("WebFetch.Enabled pointer is shared") } + if !orig.Image.Hosted["openai"].Enabled { + t.Error("Image.Hosted map is shared") + } + if !orig.Image.Local["sdxl"].Enabled { + t.Error("Image.Local map is shared") + } } diff --git a/internal/config/config.go b/internal/config/config.go index 4d5c30583..d3638604e 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -662,6 +662,8 @@ func (c Config) Clone() Config { c.Bindings.PreviousEncryptionKeys = append([]SecretRef(nil), c.Bindings.PreviousEncryptionKeys...) c.Tools.MCPServers = cloneMCPServers(c.Tools.MCPServers) c.Memory.ProviderConfig = maps.Clone(c.Memory.ProviderConfig) + c.Image.Hosted = maps.Clone(c.Image.Hosted) + c.Image.Local = maps.Clone(c.Image.Local) if c.Tools.WebFetch.Enabled != nil { v := *c.Tools.WebFetch.Enabled c.Tools.WebFetch.Enabled = &v