Hi Alan, Other backends send an unlikely string literal to the interpreter as the last command, which will be echoed back verbatim. The code detects the presence of this string in the output stream, and thus knows that the interaction has finished. Check out the ‘org-babel-comint-with-output’ macro for the implementation.
(This is the usual function of the org-babel-coq-eoe variable that your last patch deleted. It was probably cargo-culted in from another backend and never properly implemented.) Hope this is helpful, -- Aaron Ecay