eca icon indicating copy to clipboard operation
eca copied to clipboard

[bug] Stop prompt does not change the status of the last running toolCall

Open afucher opened this issue 1 year ago • 14 comments

If ECA is running a command and I click to stop, the icon stay the loading one.

Image Image

Suggestion: Change the icon to something that indicate that it is stopped.

afucher avatar Aug 19 '25 14:08 afucher

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

ericdallo avatar Aug 19 '25 14:08 ericdallo

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 avatar Aug 22 '25 19:08 bombaywalla

@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

ericdallo avatar Aug 22 '25 19:08 ericdallo

Okay. So, you're suggesting that on getting toolCallReject, the server calls toolCallRejected whether or not toolCallRun was sent. Is that correct?

bombaywalla avatar Aug 22 '25 19:08 bombaywalla

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

ericdallo avatar Aug 22 '25 20:08 ericdallo

Ah, I missed that. I'll take a closer look at the code. Thanks.

bombaywalla avatar Aug 22 '25 20:08 bombaywalla

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:

  1. assert-chat-not-stopped! (when chat is stopped)
  2. :limit-reached handler (API limits)
  3. :finish handler (normal completion)
  4. 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 avatar Aug 23 '25 20:08 bombaywalla

@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 toolCallPrepare were produced: when LLM is preparing to do a call, where we sent only toolCallPrepare and nothing more, this is pretty common for tools like eca_edit_file or eca_write_file where the LLM needs to output a big ammount of args, so this
  • toolCallPrepare and toolCallRun were produced but tool not run yet: when a tool call is waitinig for approval (what you mentioned, your suggestion fixes this only)
  • toolCallPrepare, toolCallRun were 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 a toolCalled anyway.

Does that makes sense?

ericdallo avatar Aug 23 '25 20:08 ericdallo

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:

  1. only toolCallPrepare was produced: Produce toolCallRejected.
  2. toolCallPrepare and toolCallRun were produced but tool not run yet: Produce toolCallRejected.
  3. toolCallPrepare, toolCallRun were produced, eca is running the tool call: Wait for call to complete and produce toolCalled.

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?

bombaywalla avatar Aug 24 '25 14:08 bombaywalla

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 :tool-call in eca.db).

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

ericdallo avatar Aug 24 '25 17:08 ericdallo

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.

bombaywalla avatar Aug 24 '25 18:08 bombaywalla

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?

bombaywalla avatar Aug 24 '25 18:08 bombaywalla

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!

ericdallo avatar Aug 24 '25 18:08 ericdallo

Fixed on #104

ericdallo avatar Sep 04 '25 21:09 ericdallo