Generally, you have 3-4 weeks to get the battery replaced after you get the warning, as it detects slow battery degradation. This is fairly reliable as there is specific additional hardware used in Teslas (and Hondas) to detect this kind of battery degradation. I wouldn't worry about it. I've had this happen a few times over the years. It is not an emergency but should be dealt with within 3 weeks or so of the warning first appearing.
On very rare occasions, the battery instantly fails without warning (just like ICE car batteries). This is a different issue, usually caused by an internal short or open. There is no way to detect that this is about to happen.