It’s caused by several abnormal cases.
A user of FSRS shared two affected cards with me. I checked their initial state in the database:
I found that the first card’s due is 13, which is very small. I checked its card’s info;
The last due is definitely less than 0. It caused the subsequent bug.
I created a filtered deck, and checked the database:
It seems normal. The due has been storage in odue. Then I rescheduled the deck with FSRS Helper add-on, which will modify the odue when the card is in a filtered deck:
The ivl was shortened by FSRS. So the odue decreases, to a negative integer (-44). Then I emptied the deck, and checked the database:
The bug appeared. Its due was not replaced with odue. I don’t know why. I read the source code of Anki:
In L106, it will check whether original due is greater than 0 before recover the due. It caused the bug in this case. Is it designed on purpose? @dae