The database is set to utf8mb4. The charset in generic.php is set to utf8. The only time this problem occurs is when I run the rebuild scripts.
Just because you've converted your database storage engine to UTF-8 doesnt mean that the newly added data within it is being stored as UTF-8, or the previous data in it was converted to UTF-8 before you've changed to the collation.
What does this mean? If the database storage engine is set to utf8, why would newly added data within it be stored in some other charset?
Everything works and looks fine UNTIL I run rebuild. And it's easily fixed with a query. After it's fixed, it remains fixed until I run rebuild again. Do you really think rebuild is not the problem?