Sanitize history to prevent chat errors#284
Conversation
|
After this other PR is merged, we can improve this by making it so when a user "Stops streaming" during a command, the UI responds automatically and the |
| newHistory.push(msg); | ||
| } else { | ||
| // Message has unmatched tool calls drop it and everything after it | ||
| break; |
There was a problem hiding this comment.
Thanks @Yahiewi for working on this.
I think that we can be more specific here, to avoid removing the whole history.
After some tests, I found out 2 main reasons that corrupts the history:
- a tool call initiated but without result. This seems to happen when stopping the streaming while there is pending approval.
- a tool response just after a user message. This is probably hard to reproduce, but probably when a user send a message during a tool call.
|
I linted the PR. It is already a good fix, and avoid blocking the model in some situation. |
This PR fixes the second issue mentioned in #271 where clicking on
Stop Streamingwhile a command is being executed would block the chat withError generating response: No output generated. Check the stream for errors.The solution is to use a
_sanitizeHistoryfunction that drops assistant messages whose tool call ids don't have matching results.This function uses two new functions
_getToolCallIdsand_matchesAllToolCallswhich are used to get tool call ids for assistant messages, and check if these ids have a result.Screencast.from.2026-03-06.09-44-38.mp4
As you can see in this screencast, the chat no longer throws an error. However it does immediately retry running the command I asked it to in the first prompt and this is because of how history works and because our agent isn't aware of what it started to generate in its last interrupted response.
I think this is something that we could improve in our history, I plan to open an issue and PR for this.