First, I want to restate some of the premises of your question (which are correct):
Medicare coverage disqualifies an individual from being eligible to contribute to an HSA.
If you delay enrollment in Medicare until after age 65, when you do finally enroll your coverage is applied retroactively to 6 months before you enroll.
Yes, those six months are significant, as you will be considered a non-eligible individual for contributing to an HSA for those months. Remember, however, that the HSA contribution limits are prorated based on the number of months in the year that you are an eligible individual. Therefore, when you do finally know when you will enroll (and when you retroactively became ineligible), you can calculate your prorated contribution limit for the tax year and see if you went over or not.
If you find that you have already contributed more than your limit, you can do an excess contribution withdrawal for the extra amount, provided that you catch it before April 15 of the following year.
For example, if you are laid off in February 2020 and enroll in Medicare, you will be retroactively enrolled in Medicare since August 2019. You would be completely ineligible in 2020 to contribute, so if you had contributed already in 2020, you can do an excess contribution withdrawal to get it all back. For 2019, you will have a prorated HSA contribution limit, so you can calculate what that is and do an excess contribution withdrawal for any amount that you contributed over that, and you have until April 15, 2020 to do so and report it correctly on your 2019 tax return.
At this point, you may realize that there is a window of time where you could be stuck. Let's say that you don't get any notice, but you are laid off May 1, 2020 and enroll in Medicare at that time. Going back 6 months, you had retroactively become ineligible for HSA contributions as of November 1, 2019, but you already contributed the max in 2019 and it is too late to do an excess contribution for 2019. In this case, you will be subject to the excise tax on your excess contribution of 6% on the excess amount. This excise tax is 6% for each year that the excess amount remains in your HSA. That means that although it is too late to withdraw it for 2019, you still need to do an excess contribution withdrawal on that amount in 2020, or else you will need to pay an additional 6% excise tax.
An article on HSA Edge agrees with this assessment of the situation.
The 6% tax is only on the excess amount. So if you had contributed the maximum family coverage amount of $7,000 plus the $1,000 "over 55" bonus in 2019 and then find out too late that you were ineligible beginning on November 1, 2019, then $1,333 would be considered in excess and the penalty would be $80. That's essentially the worst-case scenario. You can avoid this risk by simply reducing the amount of your contributions. If instead of contributing the full year amount in 2019, you only contributed 5/6 of the limit, there would be no penalty due in the worst-case scenario described above.
One final thing to note: The retroactive HSA-ineligibility can also affect the testing period for the last-month rule. If you have been HSA-eligible for a while, this doesn't affect you, but if you used the last-month rule recently and are currently in the testing period, losing coverage for the end of the year can have additional negative consequences.