Glitching/xrun audio when app is not visible on macOS Catalina

I’m now experiencing a thing I’ve not seen on OS X before, where a standalone audio app that uses input and output starts glitching audibly after being offscreen or completely covered by another app’s window on the same desktop after about 30 seconds. The moment you switch back to the desktop it is on or reveal any part of its window, all is normal again. I recently updated to Catalina, it’s the only change I can think of.

Has anyone else seen this? Could be an overly aggressive broken Catalina optimization that can be configured somewhere in the OS? It happens to pretty much all other audio apps as well, including Apple’s own Quicktime Player, so this isn’t a JUCE-specific issue, but I figured you folks may have the answer anyway. WTF!?

Turns out this is the OS X feature AppNap rearing its ugly head. Seem like a bug that the OS would allow a process to go into this state when it has an active high priority audio session.