Robust safety and stability of learning-based optimal controllers