From 604354bf59d46fc341c4f512ed114b02aaa0bb3a Mon Sep 17 00:00:00 2001 From: ayattara Date: Sun, 30 Aug 2026 11:34:31 +0000 Subject: [PATCH] fix: preserve legacy plugin agent config on settings save --- apps/backend/internal/plugins/config_test.go | 24 +++++++++++++++++++ .../internal/plugins/service_config.go | 18 ++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/apps/backend/internal/plugins/config_test.go b/apps/backend/internal/plugins/config_test.go index bb4b7b98de..4f9d8ed13c 100644 --- a/apps/backend/internal/plugins/config_test.go +++ b/apps/backend/internal/plugins/config_test.go @@ -143,6 +143,30 @@ func TestMergeMaskedSecretsDropsMaskWithNoStoredValue(t *testing.T) { } } +func TestUpdateConfigPreservesLegacyUtilityAgentForDirectProfileSchema(t *testing.T) { + schema := map[string]any{ + "properties": map[string]any{ + agentProfileConfigKey: map[string]any{"type": "string", "format": "agent-profile"}, + }, + } + merged := mergeMaskedSecrets(map[string]any{agentProfileConfigKey: "profile-1"}, map[string]any{ + utilityAgentConfigKey: "utility-agent-1", + }, schema) + if _, submitted := merged[utilityAgentConfigKey]; submitted { + t.Fatal("precondition: legacy selector should be absent from the replacement payload") + } + + if agentID, ok := merged[utilityAgentConfigKey].(string); ok && agentID != "" { + t.Fatalf("legacy selector unexpectedly present before preservation: %q", agentID) + } + merged = preserveLegacyUtilityAgentConfig(merged, map[string]any{ + utilityAgentConfigKey: "utility-agent-1", + }, schema) + if merged[utilityAgentConfigKey] != "utility-agent-1" { + t.Fatalf("legacy selector = %v, want utility-agent-1", merged[utilityAgentConfigKey]) + } +} + func TestValidateConfigSchema(t *testing.T) { schema := testConfigSchema() cases := []struct { diff --git a/apps/backend/internal/plugins/service_config.go b/apps/backend/internal/plugins/service_config.go index 2b94e870cc..24adb45c59 100644 --- a/apps/backend/internal/plugins/service_config.go +++ b/apps/backend/internal/plugins/service_config.go @@ -36,6 +36,11 @@ func (s *Service) UpdateConfig(ctx context.Context, id string, config map[string return err } merged := mergeMaskedSecrets(config, existing, rec.ConfigSchema) + // Direct-profile plugins can be upgraded from the legacy utility-agent + // selector. Keep that selector across the full-replacement settings write + // when the new form does not submit it, so host-side compatibility remains + // durable after the operator saves the new settings. + merged = preserveLegacyUtilityAgentConfig(merged, existing, rec.ConfigSchema) if err := validateConfigSchema(rec.ID, merged, rec.ConfigSchema); err != nil { return err } @@ -64,6 +69,19 @@ func (s *Service) UpdateConfig(ctx context.Context, id string, config map[string return s.restartForConfigChange(rec) } +func preserveLegacyUtilityAgentConfig(config, existing, schema map[string]any) map[string]any { + if !hasAgentProfileConfig(schema) { + return config + } + if _, submitted := config[utilityAgentConfigKey]; submitted { + return config + } + if agentID, ok := existing[utilityAgentConfigKey].(string); ok && agentID != "" { + config[utilityAgentConfigKey] = agentID + } + return config +} + // errSecretVaultRequired is returned by storeConfigSecrets when a plugin // declares secret config fields but no vault is wired. It fails closed // rather than silently persisting the secret in cleartext — production