Hi I think these changes would be good to have in use before notmuch compact is in wider usage. All tests pass. I plan to test all of these code paths manually tomorrow. If anyone comes up with good plan how to add automatic tests I'll add those too (I also think myself, haven't got any good ones yet).