Umbraco 17 pages randomly becoming unpublished / returning 404

Hi all, we’ve tracked this down: it looks like the same bug as #23565, fixed in 17.8.0 and 18.3.0. I’ve written up the cause, a workaround until then, and how to repair pages that are already affected in this post, to keep it in one place.