@pandhm, it did not occur to me until the bug fix of version 19.1.18 was announced: Mishandling payments against customer starting credit balances - #9 by Brucanna. The bug report was specifically about starting credit balances. But that problem might also be responsible for what you were seeing.
Try updating your software and re-entering the transactions as you originally had them. See if the problem is resolved. If so, you were right about it being a bug. This one took a very long time to fix.