[Machine] Whoever finds rice or urine in their stomach should cover their nose with their clothing, then move away and perform ablution. They should not speak to anyone, and if they do speak, they should start over. In all of this, if it is correct, it indicates that it is permissible to leave with the rice before the invalidation of prayer, and then the building on what has passed from the prayer. It was also narrated something similar to this from Salman al-Farsi.
مَنْ وَجَدَ فِي بَطْنِهِ رِزًّا أَوْ كَانَ فِي بَطْنِهِ بَوْلٌ فَلْيَجْعَلْ ثَوْبَهُ عَلَى أَنْفِهِ ثُمَّ لِيَنْتَقِلْ وَلْيَتَوَضَّأْ وَلَا يُكَلِّمْ أَحَدًا فَإِنْ تَكَلَّمَ اسْتَأْنَفَ وَفِي كُلِّ هَذَا إِنْ صَحَّ دَلَالَةٌ عَلَى جَوَازِالِانْصِرَافِ بِالرِّزِّ قَبْلَ خُرُوجِ الْحَدَثِ ثُمَّ الْبِنَاءُ عَلَى مَا مَضَى مِنَ الصَّلَاةِ وَرُوِيَ مِثْلُ ذَلِكَ أَيْضًا عَنْ سَلْمَانَ الْفَارِسِيِّ ؓ