You may have encountered a graphnode (invisible in editor) these are added by playcanvas sometimes. Check if the node you are trying to access is in fact a pc.Entity.
I’m not entirely convinced that this is a true bug because I don’t think the engine makes any claims about expected order of the children array on a pc.Entity. However, it’s fairly easy to change pc.Entity#clone to ensure the cloned hierarchy’s children arrays have the same order:
But just to emphasize, I don’t think you should write code that depends on an entity being at a given index in the children array. Instead, pc.Entity#findByName (or entity script attributes) is probably safer.