Occasionally, and with no apparent correlation with what is going on on other devices where I have Messages enabled, I get a negative count for my unread messages in Messages on OS X:

What could be causing this, and how can I prevent from happening in the future?