Edit:
I managed to pare down to a 291-line example that pinpoints the error reproducibly and with no need for large data inputs. In brief, the values of variables instantiated by one function called from two different places are getting mixed up, so that the values of variables instantiated by call #1 are being assigned to variables instantiated by call #2 and vice versa. I made a github issue here which explains the problem and provides the code needed to reproduce. Since it’s an involved explanation I will led readers check out that post.
Thank you.