literally just tackled this issue, really glad to have confirmation that i’m not out of my mind 
you’re running at 48 PPQN, right? and you’re tracking these pulses for the microtiming?
basically, what i’ve found is that these external clocking hiccups manifest as either double-pulses in the space a single pulse or dropping a pulse entirely. that slides everything either 1/48th beat ahead or 1/48th beat behind, which compounds as the script continues.
i managed to compensate for this by checking in on the beat count at every reset (eg. where my micro-step counter is equal to 1) and making sure that i’m on on a whole beat rather than a whole beat +/- 1/48th. if i’m not, then it compensates by 1/48th each reset until i’m on.
big glitches might take a few rounds to compensate, but it definitely will get back on track – it might also be easy to account for these cases with some simple maths (eg. if the distance is greater than +/- 1/48th, then compensate by however many 1/48ths will help get back to the beat).
some version of this in your script should help gently course-correct in all cases (external derivation or CPU overloading): synced-test-better.lua (1.9 KB) (this is best version, as of 3:52p CST).
might need to adjust the remember forgiveness, if it gets too aggressive 