Incorrect enharmonic choice when creating a chord symbol

Using Shift+Q, Dorico correctly identifies the first chord in the screenshot below, but for a reason I can’t quite figure out, it chooses G♯ as the root rather than A♭in the second measure. Why might that be?

The key signature is F major, which explains the accidentals, but it’s not uncommon in musical theatre scores for the key to change rapidly without the key signature being updated. I wondered whether that might be influencing Dorico’s chord recognition.

If the routine is MIDI-number based, perhaps that affects the outcome.