post.php AJAX request not being called when publishing post

It turns out that the calls to /wp-admin/post.php are due to there being custom meta boxes on the post compose page. The initial XHR request is to the WP API to save the post, but then additional XHR calls are made to process the meta boxes. This then re-saves the post, and calls the transition_post_status hook again.

When the API first saves the post, the status is going from draft to publish, and on the secondary calls, if they run, it is going from publish to publish – that in itself makes sense.

My specific problem was that I was calling some code that required $post to be globalised, which was only the case in the second XHR call, leading to inconsistent behaviour when the hook which called that code was being run twice – one when $post was globalised and one when it was not.