It does a check before running that is calculated by pkg and it will not proceed if it sees that it would consume too much. Problem is that isn't always 100% accurate for various reasons though it's usually close enough that it gets it right. That's the only real source of data it has on how much more space the upgrade will take, so it's the most accurate method we have.
Usually it would still come back up but maybe not have upgraded all the component packages, but not always (As you are seeing).
It's also one of many reasons we suggest removing all packages before doing an upgrade, as that will also increase the available disk space as well as reduce the amount of things changed on disk during the upgrade.