diff --git a/src/cleveragents/application/services/cross_plan_correction_service.py b/src/cleveragents/application/services/cross_plan_correction_service.py index c9a90ebf2..a02499526 100644 --- a/src/cleveragents/application/services/cross_plan_correction_service.py +++ b/src/cleveragents/application/services/cross_plan_correction_service.py @@ -400,11 +400,21 @@ class CrossPlanCorrectionService: Best-effort: errors during undo are logged but do not prevent other rollbacks from being attempted. + When a cascade action fails partway through, this method is called + in reverse order to clean up any state already modified by + previously completed actions. For actions that rolled back a + sandbox, the sandbox is re-rolled-back (idempotent) to ensure it + is left in a clean state; otherwise a log entry is produced. + Args: completed_actions: Actions that were successfully executed. """ for action in reversed(completed_actions): try: + if action.sandbox_rolled_back: + self._sandbox_rollbacker.rollback_child_plan_sandbox( + action.child_plan_id + ) logger.info( "cross_plan_correction.rollback_action", child_plan_id=action.child_plan_id,