So I haven't run into circular issues with xmlbuilder with this implementation. However, I have run into this many times with Contentful. The most common foot gun when working in Contentful is having a Content type that also contains a reference to itself. This is typically something that happens if you want to say have a blog post with a list of recommended blog posts that also contain their own blog post recommendations. What I think you have to do for the site map is set the include level to one so it doesn't fetch deeply nested references. In general I try to avoid doing that type of referencing with Contentful now and rather use an additional query for a use case like recommended articles and recommended products etc.
I hope that helps a bit but I know circular references can be very frustrating.
Thanks for the reply Mike!
I found that the xmlbuilder library has some circular dependency issues, but they have been fixed in xmlbuilder2! We've handled our Contentful related issues with some safe stringifiying, and definitely learned that includes query param lesson the hard way :)
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.