The following is a puzzling gemora regarding Yom Kippur and determining personal righteousness. I have added Rashi, Mishna Berura and Magen Avraham - and I still find it difficult. There is also a Levush on this gemora which I am working on. This gemora is clearly meant to be understood and clarify important issues of Yom Kippur, righteous and sexuality. It parallels BM 83b where R' Eliezer ben R' Shimon cut out fat from his body to determine if whether he made the right decision to become police chief for the Romans [which is the source that secular mandated reporting law must be obeyed.]
Yoma (88a): A tanna recited befor R' Nachman, "One who experiences a seminal emission [inadvertently – Rashi] on the day of Yom Kippur, all his sins will be forgiven." But is that true since a braissa states, "All his sins are arranged before him?" What does this expression "arranged before him mean?" [It doesn't mean in order that he will be punished] but rather so that he will be forgiven. In the School of R' Yishmael it was taught, One who experiences a seminal emission on the day of Yom Kippur should worry the entire year [that he will be punished]. However if he survives the year, he is assured that he is deserving of the World to Come. R' Nachman bar Yitzchok explained [why it is a sign of blessing]. The entire world is being deprived and yet he experiences satiation. When R' Dimi came he said, he will have a long live, thrive and have many children.(Yoma 88a): If he has a seminal emission – inadvertently. All his sins are forgiven - it is a favorable sign that indicates he will have many children and long life. He should worry the entire year - that the emission is a sign that his fast is not accepted since he is experiencing satiation. This is like a servant who pours a cup for his master who throws it in his face. However if he survives the year and doesn't die – then he possesses good deeds that are protecting him and thus he is deserving of the World to Come. Because you should know that the entire world is deprived of sexual relations while he is sexually satisfied and is not sexual deprived though not through his intent. Nevertheless if he survives the year that shows that he is completely righteous (tzadik gamur). His life is magnified – the one who has the emission on Yom Kippur is deserving of long life. He will multiply and become many – he will have children and grandchildren. As is alluded to in Yeshaya (53:10), you will see seed (seminal emission or children) and long life.
Mishna Berura(651.3): If he has a seminal emission he should worry the whole year [for punishment]. Because perhaps his fasting was not accepted because G‑d is showing him that He doesn't desire his sexual abstention. Look at the Achronim who write that concern for punishment is only if the seminal emission was not because of excessive eating or drinking or sexual fantasy etc. However if it is known that it resulted from sexual fantasy or other causes – even though this is a great sin – nevertheless he does not have to worry that he might be be punished with death. That is because he himself has caused the seminal emission to happen and the fact that he survived the year doesn't carry the assurance that he will get the World to Come. It is mentioned in seforim that the principle way to atone for failing to stop seminal emission is that he should strengthen himself - from that point on for the rest of his life – in Torah study. The merit of Torah will protect him. This is mentioned in Tanchuma. "If a man sinned and he deserves death at the hand of heaven – what should he do so that he continue living? If he typically learned one chapter, he should now learn two chapters. If he typically learned one page of gemora he should learn two pages. [ The medrash says that if he doesn't know how to learn he should at least give charity and do kindness – and this will allow him to live.... ] The basic reason for Torah study is in order to know what to do. Therefore our Sages say that f a person learns and he doesn't fulfill his halachic obligations then it is better that he was never created. In addition his failure to observe the mitzvos means that the Torah study will not be able to protect him from punishment - chas v'shalom
Mishna Berura(615:4): If he survives the whole he is assured that he will get the World to Come – Because surely he has many merits that protect him from harm and he will have long life as it says in Yeshaya (53:10)... It is therefore appropriate for him to give praise and thanks that he has been given life from Heaven [Korban Nesanel 77. See also what he says in the name of the Arizal.]
Magen Avraham(6:15:3): If he survives the whole years he is assured that he will get the World to Come. His survival for a year after a seminal emission on Yom Kippur indicates that he apparently is a tzadik and therefore did not need to afflict himself on Yom Kippur.