Edit of rebaked post doesn't show in HTML; only in raw

AI-generated summary

A bug was reported by dandv where edits made to a post did not reflect in the rendered HTML, although the raw markdown and diffs correctly displayed the changes. The issue appeared to stem from a post created by a rebake task. zogstrip and codinghorror discussed potential causes, noting that the “cooked post processor” often creates timing conflicts during edits. sam provided a detailed technical explanation: the cooked post processor runs asynchronously in Sidekiq to handle images and oneboxes. If an edit occurs while this process is running, the processor may finish and overwrite the new “cooked” HTML generated by the edit with the older version, effectively discarding the changes. The proposed solution is to ensure the cooked post processor always rebakes the markdown to prevent this race condition. codinghorror welcomed the fix, and zogstrip confirmed that a fix has been implemented via a specific commit in the Discourse repository.

I’ve just run into a very odd issue. I’ve edited this post as an admin, and after saving, none of my changes show up in the HTML!

The HTML diff doesn’t show any difference. The markdown/raw diff correctly shows the changes (as does the raw post), but they aren’t rendered in the post itself. Needless to say, I’ve reloaded the page a bunch of times, but Discourse still shows the previous revision (#2) of the post, which was created by the rebake task - maybe this is the culprit?

This is very odd indeed. Are there anything in /logs regarding this post? Does it fix it when you “Rebuild the html”?

I still kind of feel cooked post processor should rebake raw, there are weird timing issues with edit

1 Like

Yup, I agree. I have it on today’s TODO list to test and make sure it doesn’t break anything.

Yeah we’ve definitely seen weird issues here with editing and having to rebake. If you can nail down a consistent repro that’d be awesome.

I know exactly how this happens:

“cooked post processor” is our process that downloads images from posts, runs slow oneboxes and so on. It only looks at “cooked HTML”

  1. In one process… cooked post processor is running (in sidekiq) this takes a while to run
  2. In another process an edit happens, this produces new “cooked”
  3. The process (1) finishes and overwrites “cooked” produced in (2)
  4. Edit process kicks off “cooked post processor” it uses “cooked” produced by step (3)

End result is that edit happens but cooked is not updated.

The correct solution here is to make sure that cooked post processor always rebakes markdown.

7 Likes

Awesome, this weird little bug has been a thorn in our side for a while. Love to see it fixed!

Here’s the fix :tada:

https://github.com/discourse/discourse/commit/54d6d24cbfe4254407415b48fad1b3660208b48a

4 Likes