Automation-ran looping Shortcut randomly shuts off

I have a iOS shortcut triggered from an automation. The shortcut, once run, loops itself. I have a specific shut off condition, but it occasionally stops running randomly when it shouldn’t. This sometimes happens after a few minutes, sometimes after 20, and sometimes works fine. Any idea what causes this, and how to stop it from happening? Worst case I’d take a length of time it will work fine for, and then I could restart it if that amount of time passes.

  • What exactly is the shortcut doing?
  • What is the stop condition?
  • Is there any error message?
  • How is it being triggered to run?

My first guess, given the variable length of time, is it could be running out of available memory. Without having anything specific to investigate, it is however just a stab in the dark.

If it was this then redesigning the shortcut would be the first approach to resolution I would look at.

The shortcut is triggered on opening the music app. It then loops every few seconds and if music is playing, it records the song info. Otherwise, it starts a timer and ends the shortcut if 5 minutes of inactivity have passed.
No errors, I only know it failed because it doesn’t run the commands it is supposed to before ending (like resetting global variables).

I have seen it fail while playing music the entire time the shortcut is running, I have also seen it fail when no music is played and the 5 minute inactivity timer runs uninterrupted. Neither of these fail consistently though

How is memory allocated? Would it help to have the shortcut trigger an automation to loop itself instead of using the run shortcut command?