There's some complicated logic, so an assert at the end is always handy
to make sure it works correctly. This can't be easily unit tested.
This is to complement D368. The purpose is to have the sanity check in a single place, instead of checking it at every task that uses that method.