I'll want to exclude the note A and B out of the scale analysis - don't consider them as "must haves" in the scale but treat them as "melodic embellishments". Generally, a semitone moving up to a scale tone is a valid move and almost always sounds great (for example: playing B D# to C E over a C chord; another example, F# A to G Bb over Gm7). But a semitone downwards sounds weird if it starts on a non-scale tone. However in this case, I think the music really wants to develop this wobbling feel.
I think it as a borrowed blues b5 - a characteristic bad ass vibe