When VdbMetadataDelta.applyDelta() processes an "add" event, another package instance from the same slot (that was replaced) can remain in the cache. Then IndexedVardb.match returns both instances, and search.getInstallationStatus() can randomly show the wrong instance installed.
There's a patch in the following branch: https://github.com/zmedico/portage/tree/bug_547532 I've posted it for review here: https://archives.gentoo.org/gentoo-portage-dev/message/f50ed3f2727f93926e770d3d09b3864e
This is in the master branch: https://gitweb.gentoo.org/proj/portage.git/commit/?id=89a48c206f007d4b1e323c089842cd6475c1eea2
The "add" event handling was fixed by 89a48c206f007d4b1e323c089842cd6475c1eea2, but "remove" events need similar handling. There's a new patch in my branch: https://github.com/zmedico/portage/tree/bug_547532 I've posted it for review here: https://archives.gentoo.org/gentoo-portage-dev/message/ec5962dd5b97280331739025d834f2dd
This is in the master branch: https://gitweb.gentoo.org/proj/portage.git/commit/?id=8207c1ea97456f71fc32e2c264be27b348677853
Released in portage-2.2.19