It would be really cool if there was pkg_admin fsck, that more or less recalcuated all the state that should be stored and output the diff from what is to what should be, and then fix, sort of like filesystem fsck. That would be use in its own right and help find bugs.