Lock task repo and ensure task consistency when syncing tasks.

Bug: 1012783
Change-Id: I147e312e872fc3395b10524ae4b612f4af2c4566