You have to set `h_id_start` and `h_id_step` for all servers in the replication group so the generated ids do not overlap:
* https://www.kamailio.org/docs/modules/stable/modules/dialog.html#dialog.p.h_...
Likely the issue was caused by matching a dialog with same `h_id`, which was generated by a different server and not in the state that was the corresponding dialog for the processed sip message.
Eventually you can also set `dlg_match_mode=2`.
I will also add checks for the socket str, in case of replication might be safer.