diff --git a/src/cleveragents/application/services/cross_plan_correction_service.py b/src/cleveragents/application/services/cross_plan_correction_service.py index e13b66975..a02499526 100644 --- a/src/cleveragents/application/services/cross_plan_correction_service.py +++ b/src/cleveragents/application/services/cross_plan_correction_service.py @@ -400,62 +400,31 @@ class CrossPlanCorrectionService: Best-effort: errors during undo are logged but do not prevent other rollbacks from being attempted. - The cancellation of child plans is idempotent -- cancelling an - already-cancelled plan is a safe no-op. The sandbox rollback - is similarly expected to be idempotent: the rollbacker - reconciles the sandbox to a known-good checkpoint regardless - of its current state. - - For each completed action, executed in reverse order: - - - ``"cancel"``: re-cancel the child plan. - - ``"cancel_and_rollback"``: cancel the child plan and roll back - its sandbox. Cancelling is always attempted, followed by the - sandbox rollback when applicable. Any failure during one step - is logged but does not prevent further attempts. + 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): - plan_id = action.child_plan_id - 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=plan_id, - action_type=action.action, + child_plan_id=action.child_plan_id, ) except Exception as rollback_exc: logger.error( "cross_plan_correction.rollback_action_failed", - child_plan_id=plan_id, + child_plan_id=action.child_plan_id, error=str(rollback_exc), ) - # Do not prevent other rollbacks from being attempted - continue - - # Idempotent: re-cancel an already-cancelled plan is safe. - try: - self._plan_canceller.cancel_child_plan(plan_id) - except Exception as cancel_exc: - logger.error( - "cross_plan_correction.rollback_cancel_failed", - child_plan_id=plan_id, - error=str(cancel_exc), - ) - - if action.sandbox_rolled_back: - try: - self._sandbox_rollbacker.rollback_child_plan_sandbox( - plan_id - ) - except Exception as rollback_exc: - logger.error( - "cross_plan_correction.rollback_sandbox_failed", - child_plan_id=plan_id, - error=str(rollback_exc), - ) __all__ = [