-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an option to set the process filter #50
Conversation
I think I found the issue I was talking about. Let me add another test for this and a fix. |
The plz-get-json-slow-process-filter demonstrates the issue that raises this error:
In the LLM library user code gets called and the process finishes while the process filter is still active. So I think we need a way to tell The reason why this only happens sometimes when using the LLM library is probably, because in rare cases, the process finished while my process filter was still active. And In the test above there the process filter does not narrow. But the process finishes and the process filter hasn't even finished writing to the buffer because of the sit-for. Does that make sense? Any ideas how to solve this? Maybe using accept-process-output or a :watermark on the process that is initialized to 0, incremented by 1 when the process filter enters, and decremented when it exits. |
c09794f
to
e4cc262
Compare
@alphapapa Ok, I think I got it working. I deadlocked myself by trying to use |
I tested this now with Ellama and the llm library and haven't noticed any issues so far. |
That could indicate a design flaw in the filter function. AFAIK the filter should be as simple as possible. If any work needs to be done, being dispatched from the filter, it should probably be done outside of the filter's call stack, so that the filter can return quickly.
AFAIK there is never any guarantee about whether a process will still be running when a filter or sentinel is called. So if a filter or sentinel changes state that could affect other computations (like narrowing or widening a buffer), it should generally restore that state before returning (and should use
Using
AFAIK trying to control how the sentinel behaves from within the filter, or vice versa, is generally a Bad Idea, likely to lead to weird problems like the ones you've described. I've already dealt with trying to dispatch work from within the sentinel causing problems, which is why an immediately run timer is now used instead. So I would generally decline to add something like the "filter mark" property as a kind of mutex between them. I think it would be a tangled web to weave. Speaking generally, you probably need to design the filter carefully, ensuring that it does the least work possible, and that it restores any global state that could affect other computation. It should have no expectations about when it will be called relative to other functions, what any global state will be, etc. IME this is a "hairy" area of Emacs. So at the Lisp level, some degree of trial-and-error is sometimes needed, as well as very careful study of the Elisp manual, and sometimes reference to existing, related code. It's not a fast process: getting So while I'm happy for you to build on For setting the process filter, I'm happy to simply add an option to pass through the argument to Does this make sense? Thanks. |
The process filter is an optional function to be used as the process filter for the curl process. It can be used to handle HTTP responses in a streaming way. The function must accept 2 arguments, the process object running curl, and a string which is output received from the process. The default process filter inserts the output of the process into the process buffer. The provided function should at least insert output up to the HTTP body into the process buffer.
7ada41e
to
caa0398
Compare
Hi, yes, makes sense. I agree this process filter stuff is tricky. Even my "solution" took me a while. I will try to see how I get it fixed in plz-media-type. I updated the PR to now only include setting the filter options. And my paperwork with the FSF is also complete since yesterday, I received back the signed documents from the FSF. |
Sounds good.
Ok, would you ask the FSF secretary to send confirmation to me, please? I've been told by the Emacs maintainers that I should confirm these signings from the FSF rather than taking the word of the contributor. :) Thanks. |
Ok, I will ask him. |
@alphapapa Did Craig from the FSF reach out to you? I contacted him, and he mentioned I should be able to contribute since the 1st of February (I think he meant 1st of April though), and that he is going to contact you. He also mentioned that there might be a misunderstanding in the process. |
@alphapapa Can we please somehow move forward with this? An alternative way to get the green light would be to ask on emacs-devel? Eli got a copy of my assignment already 3 weeks ago and the ELPA maintainers as well. |
Hi Roman, I received your emails to Craig that you cc'ed me on, but I didn't receive an email from Craig about you. I have received confirmation emails from Craig about another contributor to another project. But I see the PDF of your confirmation that you attached to the email that you cc'ed me on, so I think that should serve as confirmation. |
@r0man Merged. Thanks for your work on this, and for your patience. |
Hi @alphapapa, alright, thanks for merging this. Would you be able to cut a release with this in the near future, so we can depend on that version? |
@r0man Ok, I just released v0.8 with this commit. |
Thanks @alphapapa, much appreciated! |
The process filter is an optional function to be used as the process filter for the curl process. It can be used to handle HTTP responses in a streaming way. The function must accept 2 arguments, the process object running curl, and a string which is output received from the process. The default process filter inserts the output of the process into the process buffer. The provided function should at least insert output up to the HTTP body into the process buffer.