A purchase agreement can technically be canceled at any time. And financial penalties for backing out (like losing your earnest money deposit) can be minimized by including contingencies in the purchase agreement.
Some home buyers end up wanting to cancel the purchase for a variety of reasons. But there’s no purchase contingency for suddenly deciding that you don’t want to own a house or for spotting a cooler house after you’ve gone under contract.
In other words, the simplest way to avoid cancellation is to be a committed buyer. Make sure that you’re all-in on homeownership and the home you’re making an offer on.