I want to add something to the RPC test to catch what caused the issue in #7690 but this should fix it.
I also want to think about whether this is exactly what we want. It's a slightly different behavior in the calculation of unconfirmed balances with regard to transactions which aren't final. I think an argument could be made that it was meant to count in unconfirmed balances non-final transactions which aren't in your mempool. Does anyone know if that was the case? If so it'll be hard to figure out how to distinguish those which are just not yet confirmed, and those which are permanently conflicted.
Edit:
Unfortunately this still is a work in progress. Both getbalance and GetAccountBalance in rpcwallet.cpp do their own summation of balances and also need to be fixed.
Can we please get rid of accounts?