Hey @seanlaff, thanks for reaching out.
When you flush a DB, all the keys which are at or below discardTs can be discarded from the LSM tree (see here). When badger is run in unmanaged mode, this discardTs is governed by read timestamp (readTs). Each transaction calls txn.Discard() and hence update the read marker, so that any key-value that can be discarded(deleted or expired) and is below the read marker can be removed from LSM tree.
In your case, the entry for i=9 sets the discardTs to 9, and the corresponding key with version 10 does not get counted here (as it is higher than discardTs(9)).
Simply adding this before closing DB should help to get the correct number of entries.
txn := db.NewTransaction(true)
txn.Discard()