Skip to content
Merged
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
26 changes: 26 additions & 0 deletions src/core/condense/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,32 @@ describe("summarizeConversation", () => {
const mockCallArgs = (maybeRemoveImageBlocks as Mock).mock.calls[0][0] as any[]
expect(mockCallArgs[mockCallArgs.length - 1]).toEqual(expectedFinalMessage)
})
it("should include the original first user message in summarization input", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding a complementary test where an earlier summary exists to assert the original first ask remains present in the summarization input across both manual and automatic condense flows.

const messages: ApiMessage[] = [
{ role: "user", content: "Initial ask", ts: 1 },
{ role: "assistant", content: "Ack", ts: 2 },
{ role: "user", content: "Follow-up", ts: 3 },
{ role: "assistant", content: "Response", ts: 4 },
{ role: "user", content: "More", ts: 5 },
{ role: "assistant", content: "Later", ts: 6 },
{ role: "user", content: "Newest", ts: 7 },
]

await summarizeConversation(messages, mockApiHandler, defaultSystemPrompt, taskId, DEFAULT_PREV_CONTEXT_TOKENS)

const mockCallArgs = (maybeRemoveImageBlocks as Mock).mock.calls[0][0] as any[]

// Expect the original first user message to be present in the messages sent to the summarizer
const hasInitialAsk = mockCallArgs.some(
(m) =>
m.role === "user" &&
(typeof m.content === "string"
? m.content === "Initial ask"
: Array.isArray(m.content) &&
m.content.some((b: any) => b.type === "text" && b.text === "Initial ask")),
)
expect(hasInitialAsk).toBe(true)
})

it("should calculate newContextTokens correctly with systemPrompt", async () => {
const messages: ApiMessage[] = [
Expand Down
4 changes: 2 additions & 2 deletions src/core/condense/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ export async function summarizeConversation(

// Always preserve the first message (which may contain slash command content)
const firstMessage = messages[0]
// Get messages to summarize, excluding the first message and last N messages
const messagesToSummarize = getMessagesSinceLastSummary(messages.slice(1, -N_MESSAGES_TO_KEEP))
// Get messages to summarize, including the first message and excluding the last N messages
const messagesToSummarize = getMessagesSinceLastSummary(messages.slice(0, -N_MESSAGES_TO_KEEP))

if (messagesToSummarize.length <= 1) {
const error =
Expand Down
Loading