They trading licks here & the bassplayer is following the keys player.
These 'piano runs', i suppose, after hearing what note they are started on, seem to follow a predictable pattern for these guys, to flawlessy pull them off.
if the flat 5th is there it just means he's playing a blues scale which is just a modified minor pentatonic, so that's still in one key. many jazz players (bass and otherwise) often improvise using "off-key" like a flat 5th in their solos. there was one jazz bassist who was famous for playing chromatic solos no matter what the key.