diff --git a/ui/goose2/src/features/chat/lib/newChat.test.ts b/ui/goose2/src/features/chat/lib/newChat.test.ts index c0fa7bcc..202b44e7 100644 --- a/ui/goose2/src/features/chat/lib/newChat.test.ts +++ b/ui/goose2/src/features/chat/lib/newChat.test.ts @@ -76,4 +76,49 @@ describe("findExistingDraft", () => { }), ).toBeUndefined(); }); + + it("does not reuse the active empty draft without content", () => { + const draft = makeSession("alpha-draft", { + projectId: "alpha", + providerId: "goose", + }); + + expect( + findExistingDraft({ + sessions: [draft], + activeSessionId: "alpha-draft", + draftsBySession: {}, + messagesBySession: {}, + request: { + title: "New Chat", + projectId: "alpha", + }, + }), + ).toBeUndefined(); + }); + + it("does not reuse a session with local messages even if messageCount is 0", () => { + const session = makeSession("alpha-session", { + projectId: "alpha", + providerId: "goose", + messageCount: 0, + }); + + expect( + findExistingDraft({ + sessions: [session], + activeSessionId: "alpha-session", + draftsBySession: {}, + messagesBySession: { + "alpha-session": [ + { id: "msg-1", role: "user", content: "hello" } as any, + ], + }, + request: { + title: "New Chat", + projectId: "alpha", + }, + }), + ).toBeUndefined(); + }); }); diff --git a/ui/goose2/src/features/chat/lib/newChat.ts b/ui/goose2/src/features/chat/lib/newChat.ts index 25cf47d9..6a630b01 100644 --- a/ui/goose2/src/features/chat/lib/newChat.ts +++ b/ui/goose2/src/features/chat/lib/newChat.ts @@ -24,9 +24,13 @@ function isMatchingContext( function isReusableDraft( session: ChatSession, - _localMessages: Message[] | undefined, + localMessages: Message[] | undefined, ): boolean { - return !session.archivedAt && session.messageCount === 0; + return ( + !session.archivedAt && + session.messageCount === 0 && + (localMessages?.length ?? 0) === 0 + ); } export function findExistingDraft({ @@ -60,5 +64,5 @@ export function findExistingDraft({ ); } - return candidates.find((session) => session.id === activeSessionId); + return undefined; }