Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Sep 18, 2025

This PR attempts to address Issue #8158. Feedback and guidance are welcome.

Problem

Intelligent context condensing was triggering too early in brand new conversations when users had low percentage thresholds configured (e.g., 5%), causing a loop of "context condensed" messages immediately after the first user message.

Solution

Added a minimum token threshold (MIN_TOKENS_FOR_PERCENTAGE_TRIGGER = 1000) that must be met before percentage-based condensing can trigger. This prevents condensing from happening on brand new conversations while maintaining the feature's effectiveness for longer conversations.

Changes

  • Added MIN_TOKENS_FOR_PERCENTAGE_TRIGGER constant (1000 tokens) in src/core/sliding-window/index.ts
  • Modified the percentage-based condensing logic to require both:
    1. Context percentage exceeding the configured threshold
    2. Total tokens exceeding the minimum threshold
  • Added comprehensive tests to verify the new behavior

Testing

  • All existing tests pass
  • Added two new test cases specifically for this fix:
    1. Verifies condensing does not trigger when below minimum token threshold
    2. Verifies condensing works correctly when above minimum token threshold

Fixes #8158


Important

Introduces a minimum token threshold to prevent premature context condensing in new conversations, addressing Issue #8158.

  • Behavior:
    • Introduces MIN_TOKENS_FOR_PERCENTAGE_TRIGGER (1000 tokens) in index.ts to prevent early context condensing in new conversations.
    • Modifies condensing logic in truncateConversationIfNeeded() to require both context percentage and token count thresholds.
  • Testing:
    • Adds tests in sliding-window.spec.ts to verify condensing does not trigger below the token threshold and works correctly above it.
  • Misc:

This description was created by Ellipsis for 395640c. You can customize this summary. It will automatically update as commits are pushed.

…ersations

- Added MIN_TOKENS_FOR_PERCENTAGE_TRIGGER constant (1000 tokens)
- Modified percentage-based condensing logic to require minimum token threshold
- Prevents condensing on brand new conversations with low percentage thresholds
- Added comprehensive tests for the new behavior

Fixes #8158
@roomote roomote bot requested review from cte, jr and mrubens as code owners September 18, 2025 17:34
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Sep 18, 2025
Copy link
Contributor Author

@roomote roomote bot left a comment

Choose a reason for hiding this comment

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

Reviewing my own code is like debugging in a mirror - everything looks backward but the bugs are still mine.

* 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
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

// 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
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

currentProfileId: "default",
})

// Verify summarizeConversation was not called even though percentage (0.9%) would exceed threshold (5%)
Copy link
Contributor Author

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%)"?

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Sep 18, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Sep 18, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Sep 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

[BUG] Roo Code intelligent context condensing triggering on brand new conversation

3 participants