Thank you kindly for this confirmation of my suspicions! I will do further research into how exactly global variables operate, to avoid being surprised by such events in the future.
For now, I have created a small cube where I write these session variables instead of declaring them as global, and that seems to be a good workaround for me.