The patch you provided does indeed seem to fix the issue, or at least
it hasn't happened for the time I tested it (I can verify various
processes were running and outputting things to the async buffer).
I do not have any idea as to why did those markers get swapped
around. Is there any specific place that deals with them that I could
check? Could this be a bug with comint mode, maybe clashing with
another package?
Try reproducing the issue after evaluating the code below, perhaps
*trace-output* will have some useful clues.
(load-library "comint.el") ;; Can only trace set-marker from
Lisp source.
(defun bug-40323-get-comint-output-marker ()
(list :comint-pmark
(and (markerp comint-last-output-start)
(eq (marker-buffer comint-last-output-start)
(current-buffer))
(process-mark (get-buffer-process
(current-buffer))))))
(dolist (fun '(set-marker
comint-send-input
comint-output-filter
comint-adjust-window-point
comint-adjust-point
ansi-color-process-output))
(trace-function fun nil #'bug-40323-get-comint-output-marker))