mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-30 03:00:41 -04:00
fix(frontend/builder): clear stale messages in retrySession so new session starts clean
This commit is contained in:
@@ -885,6 +885,29 @@ describe("useBuilderChatPanel – retrySession", () => {
|
||||
expect(result.current.sessionId).toBe("sess-retry-seed");
|
||||
expect(mockSendMessage).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it("clears stale messages when retrySession is called (setMessages reset)", async () => {
|
||||
// Simulate stale messages from a previous session
|
||||
mockChatMessages = [
|
||||
{
|
||||
id: "stale-1",
|
||||
role: "assistant",
|
||||
parts: [{ type: "text", text: "Old message from failed session" }],
|
||||
},
|
||||
];
|
||||
|
||||
const { result } = renderHook(() => useBuilderChatPanel());
|
||||
|
||||
// Messages should be present before retry (from mock)
|
||||
expect(result.current.messages).toHaveLength(1);
|
||||
|
||||
act(() => {
|
||||
result.current.retrySession();
|
||||
});
|
||||
|
||||
// setMessages([]) clears the internal useChat message list
|
||||
expect(mockSetMessages).toHaveBeenCalledWith([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("useBuilderChatPanel – handleSend", () => {
|
||||
|
||||
@@ -346,12 +346,15 @@ export function useBuilderChatPanel({
|
||||
// hasSentSeedMessageRef is reset so the seed message is re-sent to the
|
||||
// new session (it may have been set to true by a previous successful session
|
||||
// that was later invalidated without a flowID change).
|
||||
// Messages are cleared so stale messages from the previous session are not
|
||||
// shown alongside content from the new session.
|
||||
function retrySession() {
|
||||
if (flowID) graphSessionCache.delete(flowID);
|
||||
setSessionId(null);
|
||||
setSessionError(false);
|
||||
isCreatingSessionRef.current = false;
|
||||
hasSentSeedMessageRef.current = false;
|
||||
setMessages([]);
|
||||
}
|
||||
|
||||
function handleSend() {
|
||||
|
||||
Reference in New Issue
Block a user