Recently we had an on going case of what started out as a MacBook Air randomly going to sleep. Two repairs later by us and another two at an Apple retail store and Apple replaced the customers MacBook Air with a shiny new MacBook Pro Retina. Guess what? The original problem was still there.
The customer came to see us about this and I could not believe that they were still experiencing the problem. Each time we took the Mac in for testing we were unable to replicate the fault whilst we had it but could never keep it for more than a day or so as the customer was desperate to use it.
For about the tenth time I watched as the customer demonstrated the problem to me (he couldn't always get it to do it when he brought it in), he moved the MacBook slightly and the screen dimmed and the unit went to sleep. After he left the Mac with us I had a good think, it must be something external to the Mac, it had to be.
Then it clicked, he was resting it on top of the leather slip case that he always carried it in, the case had two strong magnets to keep the flap closed. As the Mac was moved over these magnets it would trigger the sleep switch in the top case and send a signal to the notebook that its lid had been closed, only it wasn't!
I confirmed the problem and sure enough, this is exactly what it was. I called the customer straight back and he was of course delighted we had finally got to the bottom of it.
Below is a short video we took to demonstrate this strange sleep problem.