-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: prevent context condensing from triggering too early in new conversations #8159
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,12 @@ import { ANTHROPIC_DEFAULT_MAX_TOKENS } from "@roo-code/types" | |
| */ | ||
| export const TOKEN_BUFFER_PERCENTAGE = 0.1 | ||
|
|
||
| /** | ||
| * Minimum number of tokens required before percentage-based condensing can trigger. | ||
| * This prevents condensing from happening too early in new conversations. | ||
| */ | ||
| export const MIN_TOKENS_FOR_PERCENTAGE_TRIGGER = 1000 | ||
|
Contributor
Author
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. Could we consider making this threshold configurable in the future? While 1000 tokens works well as a default, some users might benefit from being able to adjust this based on their specific use cases. |
||
|
|
||
| /** | ||
| * Counts tokens for user content using the provider's token counting implementation. | ||
| * | ||
|
|
@@ -144,7 +150,12 @@ export async function truncateConversationIfNeeded({ | |
|
|
||
| if (autoCondenseContext) { | ||
| const contextPercent = (100 * prevContextTokens) / contextWindow | ||
| if (contextPercent >= effectiveThreshold || prevContextTokens > allowedTokens) { | ||
| // Only trigger percentage-based condensing if we have enough context | ||
| // This prevents condensing from happening on brand new conversations | ||
| const shouldCondenseByPercentage = | ||
| contextPercent >= effectiveThreshold && prevContextTokens >= MIN_TOKENS_FOR_PERCENTAGE_TRIGGER | ||
|
Contributor
Author
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. Would it be helpful to add a debug log here when condensing is skipped due to the minimum threshold? Something like: This could help with debugging and understanding why condensing isn't triggering in certain scenarios. |
||
|
|
||
| if (shouldCondenseByPercentage || prevContextTokens > allowedTokens) { | ||
| // Attempt to intelligently condense the context | ||
| const result = await summarizeConversation( | ||
| messages, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nit: For consistency with other test comments, could this be "(0.9% of context window)" instead of just "(0.9%)"?