My employer provides my health insurance as part of my compensation and benefits package. It is a qualifying HDHP and as such every year I generally max out my HSA, either through payroll deductions or direct contributions by bank transfer.
I have an expensive surgery scheduled early next year (February) and so want to contribute my full HSA allowance to my HSA in the first couple of months of the year, which would allow me to pay for the surgery in full from my HSA. My employer allows this and it would be a convenient way to pay for the surgery - I do not expect any other medical expenses for the rest of the year as the surgery will max my plan out of pocket.
However my concern is that if I do this and end up losing my job, either for unrelated reasons or because they are unwilling to retain me while recovering from the surgery (2-3 months of recovery) I will be in a tough situation, I will have to get new insurance which may not be an HDHP which would mean my contribution was too high. I do not think it is likely this will happen but I want to prepare for this situation if it does.
If this does indeed happen, what will my tax position be? Can I retroactively pay tax on the HSA deposits which turned out to be ineligible or will I end up with some huge penalty for having contributed when not allowed? Ultimately I want to know what the worst consequences of this situation would be and what I would be able to do to mitigate them as much as possible?