I've seen this kind of thing a lot. For example :-
Build queue:
Mineral Miner I
Mineral Miner I
Mineral Miner I
Mineral Miner I
Mineral Miner I
A couple of turns later, after researching Mineral Miner IIs and hitting the upgrade-all-facilities button, the queue looks like this:
Mineral Miner II
Mineral Miner II
Mineral Miner II
Upgrade Mineral Miner II x5
Then again after researching Mineral Miner IIIs a couple of turns later:
Mineral Miner III
Upgrade Mineral Miner II x5
Upgrade Mineral Miner III x7
I get round this by researching both extra levels in quick succession and only then hitting upgrade. Or by going through all the planets removing the first upgrade from the build queue

.
Would be great if the upgrade-all button could upgrade the upgrade... but I can see that could be a headache to program, as you'd have to scan the queue as well as the facilities list.