In the case of the race between parted/sfdisk, I think Loïc managed to reproduce it reliably so there seems to be an inherent race there, but maybe there's a way to have the changes done by parted flushed before we run sfdisk? If not, I'd expect a very short sleep to be enough.
The other case involves udisks, so I think we either need to do all disk operations using udev (if we don't do that we'll probably end up with a race somewhere else) or wait (somehow) until udev is notified about the disk changes.
In the case of the race between parted/sfdisk, I think Loïc managed to reproduce it reliably so there seems to be an inherent race there, but maybe there's a way to have the changes done by parted flushed before we run sfdisk? If not, I'd expect a very short sleep to be enough.
The other case involves udisks, so I think we either need to do all disk operations using udev (if we don't do that we'll probably end up with a race somewhere else) or wait (somehow) until udev is notified about the disk changes.