This subtle and very complicated bug is now fixed via:
https://github.com/discourse/discourse/commit/63404b16bb30ab0e4f76c77a27fc2f58b16b65fd
A sequence of events was causing incorrect json to be cached, we noticed this issue elsewhere in our infrastructure regularly but never managed to pin it.