I developed a plugin for canceling orders which remain pending for more than an hour. The plugin also clears the basket after an hour. The plugin is working fine most of the time. However, on a couple of random cases, the order got canceled after the payment was authorized. I have checked the history for those orders and have attached screenshots below. After the payment was captured and authorized the payment status in those cases changed to pending payment. I am not sure why it's happening for some random orders.
Please help to fix this.