This was a problem that’s been bugging me for a while: Safari quits for some reason or another (restart, upgrade, etc), and when it starts back up, all the tabs I had pop up briefly, then all but the topmost close.
I thought for a while this was some unexpected behavior in Mavericks or Yosemite, but I couldn’t find any evidence of it, and if it was, I wouldn’t have been the only person having the problem. Finally, I ran across a post which suggested selenium web driver might be at fault. A quick check, it was installed and active. Remove it, since if I need a browser for functional testing, I run it through chrome, and bam, things are great again.
So there you go, short and sweet. If Safari is taunting with all the tabs you wanted to have back, then closing all of them and giving you only the one that was active last, see if the Selenium Webdriver is active, and, if so, disable it.
As an aside, it did this per-window, so if you’re a one-tab-per-window person, you’d likely not see this whereas if you’re a multi-window, multi-tab person, like me, you’d get whichever was active last in each window. Fun times!