-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: include initial ask in condense summarization (#8293) #8298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+28
−2
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4372d1b
fix: include initial ask in condense summarization (#8293)
hannesrudolph ff709f8
fix: include initial user ask in condense summarization
hannesrudolph e5353cf
fix: refine summary structure by removing redundancy in previous conv…
hannesrudolph ac00eef
Update src/core/condense/index.ts
hannesrudolph 100cdad
Update src/core/condense/index.ts
hannesrudolph File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| <!-- | ||
| Thank you for contributing to Roo Code! | ||
| --> | ||
|
|
||
| ### Related GitHub Issue | ||
|
|
||
| Closes: #8293 | ||
|
|
||
| ### Roo Code Task Context (Optional) | ||
|
|
||
| _No Roo Code task context for this PR_ | ||
|
|
||
| ### Description | ||
|
|
||
| Condense currently preserves the initial user message visually but excludes it from the LLM's summarization input, causing summaries to omit the original ask. This leads to resume re-answering the initial ask instead of continuing the current work. This PR ensures the initial ask is included in the condense summarization input and hardens the prompt to always capture it. | ||
|
|
||
| ### Changes Made | ||
|
|
||
| - Include the original first user message in LLM summarization input by changing the slice from messages.slice(1, -N_MESSAGES_TO_KEEP) to messages.slice(0, -N_MESSAGES_TO_KEEP) in [src/core/condense/index.ts](src/core/condense/index.ts). | ||
| - Harden SUMMARY_PROMPT to explicitly require the initial user ask be included, in [src/core/condense/index.ts](src/core/condense/index.ts). | ||
| - Add a unit test to assert the initial ask is present in the summarization input when no prior summary exists: [src/core/condense/**tests**/index.spec.ts](src/core/condense/__tests__/index.spec.ts). | ||
|
|
||
| ### Test Procedure | ||
|
|
||
| - Run focused tests: | ||
|
|
||
| ```bash | ||
| cd src | ||
| npx vitest run core/condense/__tests__/index.spec.ts core/condense/__tests__/condense.spec.ts | ||
| ``` | ||
|
|
||
| - Run full test suite: | ||
|
|
||
| ```bash | ||
| cd src | ||
| npx vitest run | ||
| ``` | ||
|
|
||
| All tests pass locally. | ||
|
|
||
| ### Verification of Acceptance Criteria | ||
|
|
||
| - [x] Summaries include the initial user ask so task resume maintains correct context. | ||
| - [x] Applies to manual condense flow (Task -> summarizeConversation) and automatic condense flow (sliding window -> summarizeConversation when thresholds trigger). | ||
| - [x] Guard ensures new context tokens do not exceed previous, preserving safety. | ||
|
|
||
| ### Pre-Submission Checklist | ||
|
|
||
| - [x] Issue Linked | ||
| - [x] Scope focused on linked issue | ||
| - [x] Self-review completed | ||
| - [x] Tests added/updated and passing | ||
| - [x] Documentation impact considered | ||
| - [x] No breaking changes | ||
|
|
||
| ### Screenshots / Videos | ||
|
|
||
| _No UI changes in this PR_ | ||
|
|
||
| ### Documentation Updates | ||
|
|
||
| - [x] No documentation updates are required. | ||
|
|
||
| ### Additional Notes | ||
|
|
||
| - Minimal, targeted change; fallback behavior and token safety rails unchanged. | ||
| - Potential slight increase in summarization input length is bounded and protected by existing safeguards. | ||
|
|
||
| ### Get in Touch | ||
|
|
||
| @roomote | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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[] = [ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.