Return to firmware execution after running a script

I’m running custom firmware on an H7 wakes up from standby, checks the wakeup source, and if it’s the right wakeup source then it runs a Python script that takes a picture and stuff. Other wakeup sources will remain in firmware without running a script until going back down into standby. I have it running the script alright after the proper wakeup, but when it returns to firmware it will read whacky values from the RTC, and it won’t configure the next wakeup sources correctly. I suspect that running a script is messing with things. The script does not call the RTC.
I have a crude patch by calling an H7 software reset (NVIC_SystemReset) when it returns from a script. That clears everything back to normal with proper RTC and wakeup configs. But it feels ugly and slow having to do that. Is there a clean way to return to firmware after running a script? Does the stack get boinked when jumping from script back to firmware?

Moving answer to private channels.