Hm. Looks like several people fell afoul of the issue I was chatting w @Licat on discord about, i.e. transactional access to vault file modifications. This is partly a documentation issue, but it would probably help a lot to have an API like vault.modify(file, old, new), where the only way to rewrite an existing file is to pass in the contents you expect it to have on disk. This would be a built-in check against stale or empty cache values, not to mention a lot of race conditions. Then the existing vault.write could be deprecated and phased out.
Optionally, such an API could work by opening the file on disk, locking it, then reading its contents to check, before modifying the contents. (And performance could potentially be improved by only writing from the changed portion… which for the majority of writes – i.e. while someone’s typing – would be at the end of the file.)