Thanks for looking into this so quickly!
An RPP is attached.
In this example, the first note ends in a Note-On, but the second note gets extended to the end of the item when MIDI_Sort is run. (The difference seems to be due to the first note being selected. Selected and unselected notes seem to be handled separately.)
To test the notes, I use exactly the same 3-line script as you do.
Strangely, the MIDI editor and the arrange view display the extended note differently: the MIDI editor extends the second note to the end of the item, whereas the inline arrange view shows the *first* note as extended.