From cdb544d7517b1e76951d94d4af7a65e2b44c4c74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Yavercovski?= Date: Thu, 16 Oct 2025 19:12:46 -0400 Subject: [PATCH] fix(branch-planner): prevent duplicate comments by checking plan revision The branch planner was posting duplicate comments on pull requests because isNewPlan() only checked if the LastPlanAt timestamp changed, not whether the actual plan content (LastPlannedRevision) changed. This caused the informer to repeatedly detect the same plan as "new" across reconciliation loops, triggering duplicate git provider comments for the same terraform plan. Changes: - Add early return if LastPlannedRevision is empty to avoid processing incomplete status updates - Check both LastPlanAt timestamp AND LastPlannedRevision when determining if a plan is truly new - Only post comments when the plan revision actually changes, not just the timestamp This ensures comments are posted once per unique plan, preventing spam on pull requests during reconciliation loops. Signed-off-by: Loic Yavercovski --- internal/informer/branch-planner/informer.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/informer/branch-planner/informer.go b/internal/informer/branch-planner/informer.go index 5e6a182f5..213053a99 100644 --- a/internal/informer/branch-planner/informer.go +++ b/internal/informer/branch-planner/informer.go @@ -307,12 +307,18 @@ func (i *Informer) isNewPlan(old, new *infrav1.Terraform) bool { return false } + if new.Status.LastPlannedRevision == "" { + return false + } + if old.Status.LastPlanAt == nil && new.Status.LastPlanAt != nil { return true } if new.Status.LastPlanAt.After(old.Status.LastPlanAt.Time) { - return true + if old.Status.LastPlannedRevision != new.Status.LastPlannedRevision { + return true + } } return false