The algo I wrote and implemented works so far.
I tested it on an Integrator file in which I had introduced a loop: $44 -> $70 -> $44 and here’s the result:
child panel: $44 (68) ancestor list node count: 2 ancestors: $44 (68) $70 (112) FATAL: panel was found in its ancestors!
Of course I will have to go through a proper test plan, but I think that the algo addresses multiple level references as that’s what I had in mind while writing it. We shall see 🙂