Automated Responses to Flags not Generating Notification

AI-generated summary

Users on WTDWTF reported that automated notifications are not generated when staff members agree, disagree, or defer custom flags, requiring users to manually check their Messages page anon25879736. While manual staff replies trigger notifications correctly, codinghorror clarified that the inability to generate an automated post when a staff member creates the first post is expected behavior, not a bug. tgxworld identified the root cause as a race condition within the Jobs::PostAlert job, where the system queries for the automated post before it is fully available in the database. By introducing a delay, the query succeeds, confirming the timing issue. tgxworld noted this as their first encounter with such a race condition and linked to a proposed fix in pull request #3854.

On WTDWTF, we’ve been getting reports that users are not being notified when a staff members agrees, disagrees, or defers their custom flags. The automated post is being added to the message that’s attached to the flag, but the user isn’t being notified of this. They don’t find out about the new post unless they visit the Messages page in their profile.

If a staff member manually replies in the message attached to the flag, the notification does get properly generated.

Because of another bug that causes the automatic post to not generate if the flag was created by a staff member, this bug requires a non-staff account to reproduce.

5 Likes

This part is not a bug, any response in the topic by a staff member, including creation of the first post, prevents automated reply.

2 Likes

I narrowed this down to a timing issue in Jobs::PostAlert. If I throw a sleep in there and query for the automated response post, it works fine. Otherwise, the first query fails to find the post.

Jobs are working fine for other posts that are enqueued though.

3 Likes

my first encounter of a race condition… :bomb:

https://github.com/discourse/discourse/pull/3854

2 Likes

PR merged :smile: Please flag if the patch didn’t fix it for you