Skip to content

fix: 🐛 Remove all history when a user request is cancelled #5662

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions gui/src/components/mainInput/Lump/LumpToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ export function LumpToolbar() {
<StopButton
className="text-gray-400"
onClick={() => {
if (toolCallState?.status === "calling" || toolCallState?.status === "generating") {
dispatch(cancelCurrentToolCall);
}
dispatch(cancelStream());
}}
>
Expand Down
22 changes: 14 additions & 8 deletions gui/src/redux/slices/sessionSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,21 @@ export const sessionSlice = createSlice({
if (state.history.length < 2) {
return;
}
const lastMessage = state.history[state.history.length - 1];

// Only clear in the case of an empty message
if (!lastMessage.message.content.length) {
state.mainEditorContentTrigger =
state.history[state.history.length - 2].editorState;
state.history = state.history.slice(0, -2);
// TODO is this logic correct for tool use conversations?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This TODO was on the mark. I've followed up with an implementation that follows this line of thinking and peformed extensive testing to validate it.

// Maybe slice at last index of "user" role message?
// Find the index of the last user message
let lastUserIndex = -1;
for (let i = state.history.length - 1; i >= 0; i--) {
if (state.history[i].message.role === "user") {
lastUserIndex = i;
break;
}
}

// If we find a user message, set the editor state to the last user messsage
// and slice the history to remove it and all the messages after it
if (lastUserIndex >= 0) {
state.mainEditorContentTrigger = state.history[lastUserIndex].editorState;
state.history = state.history.slice(0, lastUserIndex);
}
},
// Trigger value picked up by editor with isMainInput to set its content
Expand Down
Loading