Ok, so that seems to confirm what I suspected and made me run into
other sorts of weirdness during logical ino calls (returning
unexpected results).
I haven't hit the BUG_ON() as you do, but if this is indeed caused by
allowing to reuse unwritten extent buffers in the same transaction,
it's no wonder that BUG_ON() and many other weird issues happen.
Can you now try the following version?
https://pastebin.com/raw/5VHjzdn6
Leave it for at least as many days as you tested the previous patch,
hell, even a week or more if you can.