These errors are quite hard to debug, as you probably already experienced. 
I assume detect_anomaly won’t help much regarding your error, since the actual error seems to point to an exception from std::vector.
Since detect_anomaly will most likely slow down your code, you might have “stabilized” the code by removing e.g. race conditions, but it’s just a wild guess.
Could you try to rerun the code without detect_anomaly, store each batch, and wait until the error is triggered again?
This could give us a reproducible code snippet, so that we could trigger this error in a single step.