From 0d8ac40d1cf10bc841df637449c04758c77b31d1 Mon Sep 17 00:00:00 2001 From: "cortex-ai-agents[bot]" <279748396+cortex-ai-agents[bot]@users.noreply.github.com> Date: Mon, 2 Nov 2026 06:28:25 +0000 Subject: [PATCH 1/2] Fix CommittedResourceChange reconciler stubs leaving changes stuck in RollingBack/DryRunCleanup The reconcileRollingBack and reconcileDryRunCleanup methods were stubs that returned ctrl.Result{}, nil without advancing to a terminal phase. This left change objects permanently stuck in non-terminal phases with no requeue, silently dropping them. Until full rollback logic is implemented (TODO #780), advance to the terminal phase immediately: RollingBack advances to Rejected and DryRunCleanup advances to Accepted, both with warning messages that snapshot restoration/cleanup was not performed. This ensures Finished=True and Progressing=False conditions are set so the change is properly finalized. Co-Authored-By: Claude Opus 4.7 --- .../commitments/changes/reconciler.go | 12 +- .../commitments/changes/reconciler_test.go | 111 ++++++++++++++++++ 2 files changed, 121 insertions(+), 2 deletions(-) diff --git a/internal/scheduling/reservations/commitments/changes/reconciler.go b/internal/scheduling/reservations/commitments/changes/reconciler.go index 73e244a99..5ed7bd6be 100644 --- a/internal/scheduling/reservations/commitments/changes/reconciler.go +++ b/internal/scheduling/reservations/commitments/changes/reconciler.go @@ -229,14 +229,22 @@ func (r *CommittedResourceChangeReconciler) reconcileRollingBack(ctx context.Con // using SSA with fieldManager=txFieldManager. // nil snapshot entry → CR did not exist before → delete it. // Gate terminal transition on each CR confirming its spec reverted (check observedGeneration). - return ctrl.Result{}, nil + logger.Info("WARNING: snapshot restoration not yet implemented (TODO #780), advancing to Rejected without rollback", + "az", tx.Spec.AvailabilityZone, "correlationID", tx.Spec.CorrelationID) + return r.advanceTo(ctx, tx, v1alpha1.ChangePhaseRejected, func(s *v1alpha1.CommittedResourceChangeStatus) { + s.Message = "rollback not yet implemented, committed resource specs were not restored to their pre-change state" + }) } // reconcileDryRunCleanup restores pre-change state after a dry-run would-accept outcome. // Re-uses snapshot rollback logic; terminal phase is Accepted (not Rejected). func (r *CommittedResourceChangeReconciler) reconcileDryRunCleanup(ctx context.Context, logger logr.Logger, tx *v1alpha1.CommittedResourceChange) (ctrl.Result, error) { // TODO (#780): same convergence as reconcileRollingBack; terminal → advanceTo(Accepted, nil). - return ctrl.Result{}, nil + logger.Info("WARNING: dry-run cleanup not yet implemented (TODO #780), advancing to Accepted without cleanup", + "az", tx.Spec.AvailabilityZone, "correlationID", tx.Spec.CorrelationID) + return r.advanceTo(ctx, tx, v1alpha1.ChangePhaseAccepted, func(s *v1alpha1.CommittedResourceChangeStatus) { + s.Message = "dry-run cleanup not yet implemented, committed resource specs from the dry run were not cleaned up" + }) } // advanceTo updates the transaction status to the given phase. diff --git a/internal/scheduling/reservations/commitments/changes/reconciler_test.go b/internal/scheduling/reservations/commitments/changes/reconciler_test.go index cfbdcebc8..454fa01a6 100644 --- a/internal/scheduling/reservations/commitments/changes/reconciler_test.go +++ b/internal/scheduling/reservations/commitments/changes/reconciler_test.go @@ -628,6 +628,117 @@ func TestCRTReconciler_AwaitingScheduling(t *testing.T) { } } +// ============================================================================ +// TestCRTReconciler_RollingBack +// ============================================================================ + +func TestCRTReconciler_RollingBack(t *testing.T) { + const txName = "tx-rollback" + const crName = "commitment-uuid-rb" + + setup := func(t *testing.T) (client.Client, *CommittedResourceChangeReconciler) { + t.Helper() + scheme := testScheme(t) + tx := &v1alpha1.CommittedResourceChange{ + ObjectMeta: metav1.ObjectMeta{Name: txName}, + Spec: v1alpha1.CommittedResourceChangeSpec{ + AvailabilityZone: "az-1", + Source: v1alpha1.TxSourceAPI, + AllowRejection: true, + NewState: map[string]*v1alpha1.CommittedResourceSpec{"uuid-rb": minimalCRSpec("az-1")}, + }, + } + c := testClient(t, scheme, tx) + r := testReconciler(c, scheme) + driveToPhase(t, r, c, txName, v1alpha1.ChangePhaseAwaitingScheduling) + // Simulate rejection so we enter RollingBack. + setCRReady(t, c, crName, metav1.ConditionFalse, v1alpha1.CommittedResourceReasonRejected, "no capacity") + doReconcile(t, r, txName) // AwaitingScheduling → RollingBack + if got := getTx(t, c, txName).Status.Phase; got != v1alpha1.ChangePhaseRollingBack { + t.Fatalf("setup: want RollingBack, got %q", got) + } + return c, r + } + + t.Run("advances to Rejected with rollback-not-implemented message", func(t *testing.T) { + c, r := setup(t) + doReconcile(t, r, txName) // RollingBack → Rejected + tx := getTx(t, c, txName) + if tx.Status.Phase != v1alpha1.ChangePhaseRejected { + t.Errorf("phase: want Rejected, got %q", tx.Status.Phase) + } + if !strings.Contains(tx.Status.Message, "rollback not yet implemented") { + t.Errorf("message: want substring %q in %q", "rollback not yet implemented", tx.Status.Message) + } + assertCondition(t, tx.Status.Conditions, v1alpha1.ChangeConditionFinished, metav1.ConditionTrue, string(v1alpha1.ChangePhaseRejected)) + assertCondition(t, tx.Status.Conditions, v1alpha1.ChangeConditionProgressing, metav1.ConditionFalse, string(v1alpha1.ChangePhaseRejected)) + }) + + t.Run("idempotent: repeated reconciles stay Rejected", func(t *testing.T) { + c, r := setup(t) + reconcileN(t, r, txName, 3) + if got := getTx(t, c, txName).Status.Phase; got != v1alpha1.ChangePhaseRejected { + t.Errorf("phase: want Rejected, got %q", got) + } + }) +} + +// ============================================================================ +// TestCRTReconciler_DryRunCleanup +// ============================================================================ + +func TestCRTReconciler_DryRunCleanup(t *testing.T) { + const txName = "tx-dryrun" + const crName = "commitment-uuid-dr" + + setup := func(t *testing.T) (client.Client, *CommittedResourceChangeReconciler) { + t.Helper() + scheme := testScheme(t) + tx := &v1alpha1.CommittedResourceChange{ + ObjectMeta: metav1.ObjectMeta{Name: txName}, + Spec: v1alpha1.CommittedResourceChangeSpec{ + AvailabilityZone: "az-1", + Source: v1alpha1.TxSourceAPI, + AllowRejection: true, + DryRun: true, + NewState: map[string]*v1alpha1.CommittedResourceSpec{"uuid-dr": minimalCRSpec("az-1")}, + }, + } + c := testClient(t, scheme, tx) + r := testReconciler(c, scheme) + driveToPhase(t, r, c, txName, v1alpha1.ChangePhaseAwaitingScheduling) + // Simulate acceptance so we enter DryRunCleanup. + setCRReady(t, c, crName, metav1.ConditionTrue, v1alpha1.CommittedResourceReasonAccepted, "") + doReconcile(t, r, txName) // AwaitingScheduling → DryRunCleanup + if got := getTx(t, c, txName).Status.Phase; got != v1alpha1.ChangePhaseDryRunCleanup { + t.Fatalf("setup: want DryRunCleanup, got %q", got) + } + return c, r + } + + t.Run("advances to Accepted with cleanup-not-implemented message", func(t *testing.T) { + c, r := setup(t) + doReconcile(t, r, txName) // DryRunCleanup → Accepted + tx := getTx(t, c, txName) + if tx.Status.Phase != v1alpha1.ChangePhaseAccepted { + t.Errorf("phase: want Accepted, got %q", tx.Status.Phase) + } + if !strings.Contains(tx.Status.Message, "dry-run cleanup not yet implemented") { + t.Errorf("message: want substring %q in %q", "dry-run cleanup not yet implemented", tx.Status.Message) + } + assertCondition(t, tx.Status.Conditions, v1alpha1.ChangeConditionFinished, metav1.ConditionTrue, string(v1alpha1.ChangePhaseAccepted)) + assertCondition(t, tx.Status.Conditions, v1alpha1.ChangeConditionProgressing, metav1.ConditionFalse, string(v1alpha1.ChangePhaseAccepted)) + }) + + t.Run("idempotent: repeated reconciles stay Accepted", func(t *testing.T) { + c, r := setup(t) + reconcileN(t, r, txName, 3) + if got := getTx(t, c, txName).Status.Phase; got != v1alpha1.ChangePhaseAccepted { + t.Errorf("phase: want Accepted, got %q", got) + } + }) +} + // setPhase directly sets a CRT's phase via Status().Update for test setup. func setPhase(t *testing.T, c client.Client, txName string, phase v1alpha1.ChangePhase) { t.Helper() From 897e65cd603d77e7d3341d912b9fbd791f5c7f99 Mon Sep 17 00:00:00 2001 From: "cortex-ai-agents[bot]" <279748396+cortex-ai-agents[bot]@users.noreply.github.com> Date: Mon, 2 Nov 2026 07:59:09 +0000 Subject: [PATCH 2/2] Fix unparam lint warning on reconcileN helper Add nolint:unparam directive to the reconcileN test helper since its n parameter currently only receives 3 but is kept as a parameter for future callers. Co-authored-by: Philipp Matthes Co-Authored-By: Claude Opus 4.7 --- .../reservations/commitments/changes/reconciler_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/scheduling/reservations/commitments/changes/reconciler_test.go b/internal/scheduling/reservations/commitments/changes/reconciler_test.go index 454fa01a6..59958a077 100644 --- a/internal/scheduling/reservations/commitments/changes/reconciler_test.go +++ b/internal/scheduling/reservations/commitments/changes/reconciler_test.go @@ -750,7 +750,7 @@ func setPhase(t *testing.T, c client.Client, txName string, phase v1alpha1.Chang } // reconcileN calls doReconcile exactly n times without inspecting the phase between calls. -func reconcileN(t *testing.T, r *CommittedResourceChangeReconciler, name string, n int) { +func reconcileN(t *testing.T, r *CommittedResourceChangeReconciler, name string, n int) { //nolint:unparam // n is always 3 today but kept as a parameter for future callers t.Helper() for range n { doReconcile(t, r, name)