This is a fix for ENG-10110
This is a completely new implementation of this handler so publishing this as one diff, otherwise could be confusing for reviewers.
Things that are done:
- Using Identity as a source of truth.
- Discovering local device list inconsistencies.
- Make sure logic is called only once at a time (avoid running in parallel).
- Make logic more linear, implement it as one callback, removing multiple effects.
- Improved error handling, one catch instead of multiple ones and various early exits.
- Making sure logic is re-run after dependencies are changing (this is one of the biggest issues).
- Running backup handler in an idempotent way.
- Attempt to improve overall readability.