From b6d5ce2d4dcb253696e9a95aa3f32f05cba82755 Mon Sep 17 00:00:00 2001 From: hkfires <10558748+hkfires@users.noreply.github.com> Date: Fri, 26 Sep 2025 20:05:43 +0800 Subject: [PATCH] fix(access): Force rebuild of aliased provider configurations The provider reconciliation logic did not correctly handle aliased provider configurations (e.g., using YAML anchors). When a provider config was aliased, the check for configuration equality would pass, causing the system to reuse the existing provider instance without rebuilding it, even if the underlying configuration had changed. This change introduces a check to detect if the old and new provider configurations point to the same object in memory. If they are aliased, the provider is now always rebuilt to ensure it reflects the latest configuration. The optimization to reuse an existing provider based on deep equality is now only applied to non-aliased providers. --- sdk/access/reconcile.go | 43 +++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/sdk/access/reconcile.go b/sdk/access/reconcile.go index 32e4072a..d4eda6c8 100644 --- a/sdk/access/reconcile.go +++ b/sdk/access/reconcile.go @@ -37,11 +37,14 @@ func ReconcileProviders(oldCfg, newCfg *config.Config, existing []Provider) (res continue } - if oldCfgProvider, ok := oldCfgMap[key]; ok && providerConfigEqual(oldCfgProvider, providerCfg) { - if existingProvider, ok := existingMap[key]; ok { - result = append(result, existingProvider) - finalIDs[key] = struct{}{} - continue + if oldCfgProvider, ok := oldCfgMap[key]; ok { + isAliased := oldCfgProvider == providerCfg + if !isAliased && providerConfigEqual(oldCfgProvider, providerCfg) { + if existingProvider, okExisting := existingMap[key]; okExisting { + result = append(result, existingProvider) + finalIDs[key] = struct{}{} + continue + } } } @@ -67,9 +70,23 @@ func ReconcileProviders(oldCfg, newCfg *config.Config, existing []Provider) (res if providerCfg := newCfg.ConfigAPIKeyProvider(); providerCfg != nil { key := providerIdentifier(providerCfg) if key != "" { - if oldCfgProvider, ok := oldCfgMap[key]; ok && providerConfigEqual(oldCfgProvider, providerCfg) { - if existingProvider, ok := existingMap[key]; ok { - result = append(result, existingProvider) + if oldCfgProvider, ok := oldCfgMap[key]; ok { + isAliased := oldCfgProvider == providerCfg + if !isAliased && providerConfigEqual(oldCfgProvider, providerCfg) { + if existingProvider, okExisting := existingMap[key]; okExisting { + result = append(result, existingProvider) + } else { + provider, buildErr := buildProvider(providerCfg, newCfg) + if buildErr != nil { + return nil, nil, nil, nil, buildErr + } + if _, existed := existingMap[key]; existed { + updated = append(updated, key) + } else { + added = append(added, key) + } + result = append(result, provider) + } } else { provider, buildErr := buildProvider(providerCfg, newCfg) if buildErr != nil { @@ -87,15 +104,7 @@ func ReconcileProviders(oldCfg, newCfg *config.Config, existing []Provider) (res if buildErr != nil { return nil, nil, nil, nil, buildErr } - if _, ok := oldCfgMap[key]; ok { - if _, existed := existingMap[key]; existed { - updated = append(updated, key) - } else { - added = append(added, key) - } - } else { - added = append(added, key) - } + added = append(added, key) result = append(result, provider) } finalIDs[key] = struct{}{}