The simple way to solve that is the same way human drivers are taught to solve this: by following at a safe distance. I was taught to follow at my own stopping distance, so that if the leading car were to hit a brick wall and stop immediately, I would still have time to stop myself.