Midi Notes disappear from looped recording

I’m not sure if this is a bug or a feature that I have inadvertently enabled, but when I try to loop record on a MIDI track, initially everything looks good, and I can see the new notes appear in the regions as I record.
However, as soon as I press stop, all of the notes disappear. The newly created layered regions all appear correctly, but they are all empty.
If I stop recording before reaching the end loop marker for the first time, then the notes do not disappear and they playback correctly.

Audio appears to record correctly, although the last layer always plays back as silence even though a waveform has been generated.

I’m using Ardour 6.5 in Ubuntu Studio

So I found the cause/workaround if anyone else experiences this:

The problem (notes disappear after recording is stopped in loop mode) only happens when the MIDI interface is selected directly with the Input button in the channel strip.
So, in my case, if I left-click the Input button, and choose ‘Q49 MIDI In’, then the notes disappear when recording stops. However if I right-click on the track name, then choose ‘Inputs…’, and then connect the ‘Q49 MIDI In’ to the track in under the hardware tab, it records as expected in loop mode.

When you use the dropdown, you exclusively assign a given input.
When using the matrix, you can add other inputs in addition to the existing one(s).

Can you check if there is more than input connected? Does the input connector show *2*?

When there is more than one input connected, ardour takes the worst-case latency of all connected ports, and at rec-stop moves the region (or notes) back in time to align them.

but there’s more to this…

MIDI notes at region-boundaries are sometimes lost due to time/position rounding errors. This is a well known issue (search the forum or bug-tracker).