From 46ae92b5c11fade552c7cc94f9bc29c50eddb8cb Mon Sep 17 00:00:00 2001 From: Oskar Kapala Date: Wed, 27 May 2026 15:19:13 +0200 Subject: [PATCH] supervisor: also cancel pending actions for services removed from desired state Previously _cancel_resolved_pending_actions() only cancelled actions where the service became healthy. This left orphaned actions when a service was removed from services.yaml or marked monitor:false. Add Case 1: if the action's svc_key is no longer in desired_state (either removed entirely or skipped due to monitor:false), cancel with reason service_removed_from_desired_state. Co-Authored-By: Claude Sonnet 4.6 --- services/control-plane/src/supervisor.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/services/control-plane/src/supervisor.py b/services/control-plane/src/supervisor.py index c403dee..5076e69 100644 --- a/services/control-plane/src/supervisor.py +++ b/services/control-plane/src/supervisor.py @@ -414,20 +414,30 @@ class Supervisor: continue svc_key = f"{node}/{service}" - actual_info = self.actual_state["services"].get(svc_key) - if actual_info and actual_info.get("status") == "healthy": - # Drift resolved — move to cancelled/ + + cancel_reason = None + + # Case 1: service is no longer in desired state (removed from services.yaml + # or marked monitor:false). The action was generated under old config. + if svc_key not in self.desired_state["services"]: + cancel_reason = "service_removed_from_desired_state" + + # Case 2: drift resolved — service is now healthy in actual state. + elif self.actual_state["services"].get(svc_key, {}).get("status") == "healthy": + cancel_reason = "drift_resolved_auto" + + if cancel_reason: dest = cancelled_dir / action_file.name try: action["status"] = "cancelled" - action["cancelled_reason"] = "drift_resolved_auto" + action["cancelled_reason"] = cancel_reason action["cancelled_at"] = time.time() with open(dest, "w") as f: json.dump(action, f, indent=2) action_file.unlink() logger.info( f"Auto-cancelled {action_file.name}: " - f"{svc_key} is now healthy" + f"{svc_key} — {cancel_reason}" ) except Exception as e: logger.error(f"Failed to cancel action {action_file.name}: {e}")