Isn't this the effect of that you adapt to your own echoed notes and play earlier?
Midi is not delaying a full audio buffer size on input - only output latency.
But daw may be compensating placing clips roundtrip latency earlier - making it to early.
Any plugins that introduce latency may also be involved - most common.
Also external midi gear will have a response time, not seldom hundreds of samples.
A few ways to deal with it:
a) use the Time+ setting for midi to make audio line up
b) try the PDC button on control bar when recording to create vip lane for audio not delayed by loaded plugins latency for record armed track.
c) if external gear - listen locally on what is played, not midi echo through Sonar and then trig external gear.
d) there is also a setting in daws whether to use system time or midi time generated by midi interface.
In Sonar variable IgnoreMidiInTimeStamps in TTSSEQ.INI set this. It's not midi clock, but if arriving midi events are timestamped according to system time in computer, or according to what midi interface provide. Search help and read up on what it does.
just a bunch of ideas....