How to avoid filling bad data in ChangeSetItem that prevents future publishing?

Silverstripe Version:4

Question: I am running into an issue with versioned objects where occasionally bad data will be inserted into the ChangeSetItem database. How can I debug this further / avoid this issue?

Hello,
A couple of times so far, a user has made a change to content in the CMS, and after that change there has been a row in the ChangeSetItem database with ChangeSetId and ObjectId 0. Later, some other action causes another row with an Identical ChangeSetId and ObjectId of 0 to be created. From that point on, we are unable to publish anything in the CMS. Everytime we attempt a publish, there is an error saying that the unique key constraint of the database is being violated. Error text:

ERROR: Uncaught Exception SilverStripe\ORM\Connect\DatabaseException: "Couldn't run query:  INSERT INTO "ChangeSetItem"  ("Created")  VALUES  ($1)  ERROR:  duplicate key value violates unique constraint "ix_8bd382eca8ff13584ccdbd0fec975f5f" DETAIL:  Key ("ObjectID", "ObjectClass", "ChangeSetID")=(0, Thumbtack\CMS\Core\SelectionCriterion, 0) already exists." at /var/www/html/vendor/silverstripe/framework/src/ORM/Connect/DBConnector.php line 64 {"exception":"[object] (SilverStripe\\ORM\\Connect\\DatabaseException(code: 0): Couldn't run query:\n\nINSERT INTO \"ChangeSetItem\"\n (\"Created\")\n VALUES\n ($1)\n\nERROR:  duplicate key value violates unique constraint \"ix_8bd382eca8ff13584ccdbd0fec975f5f\"\nDETAIL:  Key (\"ObjectID\", \"ObjectClass\", \"ChangeSetID\")=(0, Thumbtack\\CMS\\Core\\SelectionCriterion, 0) already exists. at /var/www/html/vendor/silverstripe/framework/src/ORM/Connect/DBConnector.php:64)"} []

The construction around this is that we have QuestionAndAnswers that implement DataObjects, and extend Versioned. They have owns and has_many relationships with SelectionCriterion. SelectionCriterion itself does not extend Versioned.

I have been able to temporarily fix the issue by running

delete  from "ChangeSetItem" where "ObjectID"=0 AND  "ObjectClass" = 'Thumbtack\CMS\Core\SelectionCriterion' AND "ChangeSetID"=0;

/dev/build?flush=1 did nothing.