The only way I can keep my MBP retina happy when using it with an external Thunderbolt display is:
1) before plugging into display, open lid and wait for login screen to appear
2) before unplugging display, open lid and wait for laptop screen to turn on (normally I keep my laptop closed when connected to the display)
If I deviate from this the laptop crashes or goes into some odd state.