Separating a document swap from an in-place edit makes the failure surface completely clear. Mutating the text field in place while keeping the same document ID leaves an ID assertion totally blind, which is why taking a deep-copied MappingProxyType snapshot right at the retrieval boundary closes a hole that post-hoc ID matching cannot see.
One practical Python wrinkle with MappingProxyType is that it is shallow on nested containers: if a retrieved document carries nested metadata dicts or chunk lists, freezing those inner structures recursively (or serializing into frozen dataclasses/tuples) ensures downstream formatting helpers cannot mutate nested fields either.