The Rules of Forgetfulness (Sahw) in Prayer
Man Lā Yaḥḍuruh al-Faqīh|Volume 1|Book 1|Chapter 50
وَ رُوِيَ عَنْ عَلِيِّ بْنِ أَبِي حَمْزَةَ عَنِ اَلْعَبْدِ اَلصَّالِحِ عَلَيْهِ اَلسَّلاَمُ قَالَ: سَأَلْتُهُ عَنِ اَلرَّجُلِ يَشُكُّ فَلاَ يَدْرِي أَ وَاحِدَةً صَلَّى أَوِ اِثْنَتَيْنِ أَوْ ثَلاَثاً أَوْ أَرْبَعاً تَلْتَبِسُ عَلَيْهِ صَلاَتُهُ فَقَالَ «كُلُّ ذَا» فَقُلْتُ نَعَمْ قَالَ «فَلْيَمْضِ فِي صَلاَتِهِ وَ لْيَتَعَوَّذْ بِاللَّهِ مِنَ اَلشَّيْطَانِ اَلرَّجِيمِ فَإِنَّهُ يُوشِكُ أَنْ يَذْهَبَ عَنْهُ.
It was narrated from Ali ibn Abi Hamza that he asked the Righteous Servant (Imam Musa al-Kadhim عليه السلام) about a man who doubts and does not know whether he has prayed one, two, three, or four units (rak'ahs) of prayer. His prayer becomes confusing for him. Imam said: "All of that [doubt] applies." I said: "Yes." Imam عليه السلام replied: "Then let him continue with his prayer and seek refuge in Allah سبحانه وتعالى from the accursed Satan, for it is likely that this [state of doubt] will go away."
- Ṣaḥīḥ al-Faqīh