[bug] Stop prompt does not change the status of the last running toolCall
If ECA is running a command and I click to stop, the icon stay the loading one.
Suggestion: Change the icon to something that indicate that it is stopped.
Yeah, Good catch, I think we should fix this in server to provide a toolCallRejected when stop is pressed, this would fix for all editors too
From what I understand, when the user presses the stop button, the editor sends a toolCallReject to the server.
What you're suggesting is that on receiving a toolCallReject, the server then sends a toolCallRejected to the editor.
And then the editor can change the icon as required.
Assuming my understanding is correct, then in features/chat.clj it appears to me that the code is already implementing that desire.
Is that correct? Or am I missing something?
@bombaywalla, you are absolutely correct on how it works, the problem is when user stop while no toolCallRun was emmited, so we stay in a loading state
Okay. So, you're suggesting that on getting toolCallReject, the server calls toolCallRejected whether or not toolCallRun was sent. Is that correct?
No the problem is not with toolCallReject, but with the chat/promptStop message that client sends when clicking on stop, when we receive that we should send a toolCallRejected if a toolCall is in progress
The stop OP mentions is not stop the tool call, but stop the chat prompt entirely
Ah, I missed that. I'll take a closer look at the code. Thanks.
My understanding, from looking at features/chat.clj, is that when a tool call is requested, an entry is created in the db* with the moral equivalent of (assoc-in @db* [:chats chat-id :tool-calls id :approved?*] (promise)). Then a future is created to run the call when approve?* realizes to true, otherwise a toolCallRejected message is sent.
So, for the purposes of this issue, it suffices to find all the tool calls where the approved?* promise is unrealized and then deliver a false to those promises.
Am I correct in this approach?
I looked at prompt-stop and it seems to call finish-chat-prompt!, which itself is called from:
assert-chat-not-stopped!(when chat is stopped):limit-reachedhandler (API limits):finishhandler (normal completion)prompt-stop(user-initiated stop)
So, I was wondering whether we need to send a toolCallRejected for the pending tool calls in these other situations as well?
@bombaywalla yeah, that sounds like a good approach, you are correct, but I believe this is not the only case we need to handle:
- only
toolCallPreparewere produced: when LLM is preparing to do a call, where we sent onlytoolCallPrepareand nothing more, this is pretty common for tools likeeca_edit_fileoreca_write_filewhere the LLM needs to output a big ammount of args, so this toolCallPrepareandtoolCallRunwere produced but tool not run yet: when a tool call is waitinig for approval (what you mentioned, your suggestion fixes this only)toolCallPrepare,toolCallRunwere produced, eca is running the tool call: Like in OP's image, like a bash command that can take seconds to finish, I believe this one we should wait for it and send atoolCalledanyway.
Does that makes sense?
Thanks. I went through the code again to better understand the flow as it exists.
What I understand that you are suggesting, from your previous comment:
If the server receives a promptStop, then if:
- only
toolCallPreparewas produced: ProducetoolCallRejected. toolCallPrepareandtoolCallRunwere produced but tool not run yet: ProducetoolCallRejected.toolCallPrepare,toolCallRunwere produced, eca is running the tool call: Wait for call to complete and producetoolCalled.
Is my understanding correct?
Does the ECA protocol deal with any kind of timeout?
For example, what should happen if we get a content_block_start from the LLM and thus produce a toolCallPrepare, but then don't get any subsequent content_block_deltas or message_delta with tool_call? Say, because of a network issue. What is the server supposed to do under that situation?
Does the ECA protocol have a way for the user to interrupt a long-running tool call?
Is my understanding correct?
Exactly.
Does the ECA protocol deal with any kind of timeout?
There is no global timeout, only the eca_shell_command has a timeout but should not be relevant.
Say, because of a network issue. What is the server supposed to do under that situation?
Currently we don't handle that and it's pretty rare to happen, but we should clean any tool call state (:chats
Does the ECA protocol have a way for the user to interrupt a long-running tool call?
No, but it's something we should support but fixing stop I think is enough for now, as we keep the conversation thistory and user can say continue or something like that
Thanks. What I meant by timeout is that the ECA protocol seems to assume that all the events will happen as they are supposed to. What if some expected event never happens (say, because of some network issue)? The protocol specification should say something about that if we want to have the ECA protocol to be interoperable between different implementations.
As you mention, that might be better served as a different issue.
Now that my understanding matches yours, I'll take a crack at implementing.
My guess is that I'll need to add to the tool-call state that is stored under [:chats chat-id :tool-calls tool-call-id].
Currently there is only :approved?*.
I will add other state there.
Is that okay?
Hum, I like the thoughts on that but not sure it's really a problem that affects the protocol itself, but would love to discuss more in a issue with a real problem.
sounds good @bombaywalla!
Fixed on #104