Same thing happened to me, my primary fob stopped working and would not open the doors or close them, and I had to use the backup fob. Did not improve with a new battery, and I set up a ranger appointment at my house.
According to mobile service, apparently the fob chips do give out or stop working after a while, it is a common occurrence and they cannot reprogram them. They just replace it with a new one. The first thing they do is open up the fob and look for water damage, which is not covered under warranty. If the fob shows no damage, they replace it. The fobs talk to the car by bluetooth and it is very easy for the service Tesla laptops to talk to the new fob and reprogram for your car. They do have to pop the center console cubby to get access to the car's computer system, but it only takes a few minutes.
When I first set up the appointment, I was asked to pre-approve a $293 cost estimate for the fob, but that disappeared the day of the appointment, probably because I am still under warranty.
Model X 100D, July 2018