i had an occurrence of this error (Xlib: sequence lost in reply type 0x2) in a program i'm maintaining (i'm not the original developer).
I'm far from being an expert in Xlib programming, and i included motif in the tag only because this program was written using that toolkit. I did some research before posting, and found out that this error is probably due to a thread (different from the UI's one) which is trying to update the UI itself. Searching in the code i found some calls to XTestFakeKeyEvent and XtIsManaged which i'm sure are used in a different thread from the UI.
My question is: could these two functions originate this error?
I would think that only functions that do update the GUI (e.g. set the text of a label) could cause problems of that sort (and these 2 functions don't seem to directly impact the gui), but i honestly don't know....
XTestFakeKeyEvent is most likely the culprit. It injects a key press/release event, which could mess up the event queue.
XtIsManaged will not cause a change, but may give the wrong result if the managed state is changed during it's execution.