Skip to content

Commit 18127f1

Browse files
matt2eclaude
andauthored
fix: Allow starting a new session in a project after creating one (#8766)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3fbe01d commit 18127f1

2 files changed

Lines changed: 52 additions & 3 deletions

File tree

ui/goose2/src/features/chat/lib/newChat.test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,49 @@ describe("findExistingDraft", () => {
7676
}),
7777
).toBeUndefined();
7878
});
79+
80+
it("does not reuse the active empty draft without content", () => {
81+
const draft = makeSession("alpha-draft", {
82+
projectId: "alpha",
83+
providerId: "goose",
84+
});
85+
86+
expect(
87+
findExistingDraft({
88+
sessions: [draft],
89+
activeSessionId: "alpha-draft",
90+
draftsBySession: {},
91+
messagesBySession: {},
92+
request: {
93+
title: "New Chat",
94+
projectId: "alpha",
95+
},
96+
}),
97+
).toBeUndefined();
98+
});
99+
100+
it("does not reuse a session with local messages even if messageCount is 0", () => {
101+
const session = makeSession("alpha-session", {
102+
projectId: "alpha",
103+
providerId: "goose",
104+
messageCount: 0,
105+
});
106+
107+
expect(
108+
findExistingDraft({
109+
sessions: [session],
110+
activeSessionId: "alpha-session",
111+
draftsBySession: {},
112+
messagesBySession: {
113+
"alpha-session": [
114+
{ id: "msg-1", role: "user", content: "hello" } as any,
115+
],
116+
},
117+
request: {
118+
title: "New Chat",
119+
projectId: "alpha",
120+
},
121+
}),
122+
).toBeUndefined();
123+
});
79124
});

ui/goose2/src/features/chat/lib/newChat.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@ function isMatchingContext(
2424

2525
function isReusableDraft(
2626
session: ChatSession,
27-
_localMessages: Message[] | undefined,
27+
localMessages: Message[] | undefined,
2828
): boolean {
29-
return !session.archivedAt && session.messageCount === 0;
29+
return (
30+
!session.archivedAt &&
31+
session.messageCount === 0 &&
32+
(localMessages?.length ?? 0) === 0
33+
);
3034
}
3135

3236
export function findExistingDraft({
@@ -60,5 +64,5 @@ export function findExistingDraft({
6064
);
6165
}
6266

63-
return candidates.find((session) => session.id === activeSessionId);
67+
return undefined;
6468
}

0 commit comments

Comments
 (0)