👋 you refer to "race condition", but I think you are discussing more generally integrity here, where SpiceDB does not reflect the state of your main database? Is the problem that your application is failing to write in certain occasions to SpiceDB?
This is typically a problem that happens more often when folks do dual-writes: write to main DB + write to SpiceDB. This approach is, by definition, not atomic, so there is always a chance you end up with a situation where one of the writes succeeded and the other failed.
There are various was to address this. One is to adopt a Durable Workflow engine. A durable workflow engine makes sure that a multi-transaction business operation
eventually completes or completely rollsback. For example, we've successfully used
https://github.com/cschleiden/go-workflows in some internal projects to write to two systems of record and maintain integrity.
https://www.golem.cloud/post/the-emerging-landscape-of-durable-computing is also a good write up.
Another option folks like is transaction log tailing, where you read the WAL from your database and issue SpiceDB writes from them. There are myriads of projects to support this, a popular project here is Debezium.
Othe folks have done what you suggest, an "anti-entropy repair", which is essentially a job that goes over the origin database and repairs any inconsistencies on the application. We have customers doing this too.