... needing to launch the whole thing as an agent.
When you hold the doc open in foreground, even after it's been saved & is still in QueryClose, the Notes editor gets involved.
The easiest way to work around that issue is to launch an agent after the document has been closed.
Your QueryClose does not have the on-disk version of the richtext item in memory, so you're catching it in midstream. And it's gonna be unpleasant whatever you try to do within the QueryClose.
If you truly, really need to do something in the QueryClose that can't be extracted from the rest ... I would say try harder, but it's also possible you can squeeze something in by loading the on-disk document from an entirely different method, like GetDocumentByUNID(). It is very dicey what you end up with though.