Line tool erases a rectangular area of an image before drawing a line

Half the time I work with the line tool, and sometimes I run into a bug where a rectangular area (a little larger than the line itself) is erased first, and only then the line is applied. At the same time, this unpleasant case cannot be simply rolled back with Ctrl + Z, it may be necessary to press this shortcut several times, or it may not help at all.

Restarting the program does not help. I encountered this problem in version 5.0.0. I tried to update to version 5.1.1, drawing in a new file, but this bug is still there.

Hardware configuration:
Intel Core i5-10300H, 2.50 GHz
16 GB of RAM
4095MB NVIDIA GeForce GTX 1650

OS: Windows 10 Pro 64-bit

Does Krita print anything to the console log when this happens? (How to get the console log: Getting Krita logs — Krita Manual 5.0.0 documentation)
I’m suspecting it to contain a safe assert in the memento manager.

Does the bug only occur randomly, or do you have some idea how to more reliably reproduce it? (Using a certain brush, etc.)