SPOILERS BELOW.
Actually, I've been reading some posts and discussion on various sites, and I understand that being able to watch in one go ( most of the time I was watching 2 episodes daily with some extra binging in between), but people seem to think that Shen Tu Nan didn't turn until his sister died. This is only true to an extent. Like I said earlier, I believe it was strongly implied that he purposefully left his code book in his drawer knowing she'll find it.
He most likely started suspecting as soon as he was told all the staff were in the kitchen and he made his way to the study, slowly and waited until Jin Zhen left. He wasn't angry and simply apologized to his wife. He can't make it obvious that he is complicit and willingly leaking codes because if any question arises--it protects others to not know. That being said, I think he doesn't fully commit till Jin Zhen dies and he is told to go to Canton, which is why he sends his wife and daughter away. His wife probably realizes it too.
I also believe that it was the best course of action for him to do his last mission as an inside man. It is also what Lei Ming probably wanted from him. We are not shown that conversation between Tu Nan and Lei Ming, we only hear it by seeing STN recall it after he's escaped. We are never given the exact details on how exactly he was able to escape. I believe it is ambiguous in order for the 'surprise factor' which I don't think is that much of a surprise, and also probably because those scenes were cut either due to censorship or for runtime purposes. Even if the escape was some plan LQS hatched for his spy to carry out, STN just was easily able to escape... To me this is probably the one fault of the drama along with the fact that they just hastily showed that Tu Nan gave secret messages to Ruo Lai. No explanation of any sort of how and when this happened.
When he told LQS that Jin Zhen is a Communist first and his sister second, what else are people expecting him to say? Do they think he should tell LQS not to go after Jin Zhen and be accused of collaborating or being disloyal? Tu Nan was valuable within his position and for that he has to maintain not only his demeanor but his actions as well.
He was only slightly helping out the Communists at that point--and even though he hadn't completely made the concrete decision, that is what he is supposed to do in that position. He is still on the same assignment as he was on before his arrest to Jiangxi soviet. He cannot just leave right after he escapes imprisonment and execution from the Communist stronghold. He will be suspected, and he will be useless to the cause.
It is because he was considered valuable to KMT that he was sent to Canton, even if at least one faction wanted to dispose of him after using him. It is because he was at the helm in Guangdong that Ruo Lai was able to carry out his plans. And at this point, he decided to actively help but still within his position. He was able to guess Ruo Lai's actions and tactics but kept it to himself. He covered himself by publicly stating that Ruo Lai would take the waterway, knowing Ruo Lai would create a diversion using railroad and that LQS would jump on it and used LQS' suspicions against him.
Shen Tu Nan has witnesses and probably proof that he guessed Ruo Lai would use water for transportation and not rail. Thus he is able to get off and probably leave/retire stating he's tired and done with all these missions.