fix: include initial ask in condense summarization (#8293) (#8298)

* fix: include initial ask in condense summarization (#8293)

---------

Co-authored-by: Matt Rubens <mrubens@users.noreply.github.com>
This commit is contained in:
Hannes Rudolph 2025-09-24 23:14:44 -06:00 • committed by GitHub
parent d3d0967fc3
commit 2f1b94f430
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 2 deletions

View file

@ -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 () => {
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[] = [

View file

@ -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 =