Fix crash when cancelling an automation script