robust failure handling in model objective and gradient