Avoid unnecessary upgrade mode (v1.20)

This is rehashed backport of various changes from trunk which ensure the machine agent doesn't enter upgrade mode unless it actually needs to. 

The consequences of entered upgrade mode aren't as severe in 1.20 as in 1.21 (API isn't restricted for users) but it's still worth making these changes.