Optimality of Approximate Inference Algorithms on Stable Instances