Re-check inactivity inside the transaction so a device that syncs in the meantime keeps its ids, and scope the id deletion by user so another user's device with the same id is left alone.