Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Aug 11, 2025

Align condense/truncation thresholds with reserved output tokens to avoid early condensing on large-context models. Changes:\n\n- Use a single absolute threshold: allowedTokens = contextWindow * (1 - TOKEN_BUFFER_PERCENTAGE) - reservedTokens\n- Keep percent trigger logic but ensure absolute check respects reserved output tokens\n- Fixes cases where a 400k context model condensed around ~188k due to an overly aggressive absolute threshold\n- Sliding-window unit tests pass locally (28/28)


Important

Adjusts truncateConversationIfNeeded() in index.ts to prevent premature condensing in large-context models by aligning thresholds with reserved output tokens.

  • Behavior:
    • Adjusts truncateConversationIfNeeded() in index.ts to use a single absolute threshold for allowed tokens, considering reserved output tokens.
    • Prevents premature condensing in large-context models by aligning condense/truncation thresholds with reserved output tokens.
    • Fixes issue where 400k context model condensed at ~188k tokens due to aggressive threshold.
  • Constants:
    • Introduces SAFETY_BUFFER_PERCENTAGE and MIN_SAFETY_BUFFER_TOKENS in index.ts to prevent premature condensing.
  • Tests:
    • Sliding-window unit tests pass locally (28/28).

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

@roomote roomote bot requested review from cte, jr and mrubens as code owners August 11, 2025 04:49
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. bug Something isn't working labels Aug 11, 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.

* Safety buffer applied when approaching the hard context limit.
* Keep very small so we don't trigger premature condensing on large windows.
*/
const SAFETY_BUFFER_PERCENTAGE = 0.01 // 1% of total context window
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are these constants intentional? They're defined but never used in the implementation. Were they meant to be incorporated into the threshold calculation, or are they placeholders for future enhancements?

// Calculate effective capacity available for conversation history after reserving output tokens
const allowedTokens = contextWindow * (1 - TOKEN_BUFFER_PERCENTAGE) - reservedTokens

// Note: allowedTokens already includes a dynamic buffer and reserved output tokens
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This comment mentions keeping 'a single source of truth' but doesn't clarify what that source is or how it differs from the previous approach. Could we make this more explicit? Perhaps something like: 'allowedTokens is now the single threshold for both percentage and absolute checks'?

// If no specific threshold is found for the profile, fall back to global setting

if (autoCondenseContext) {
// Base percent on effective capacity so visualization and behavior are aligned
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What does 'visualization' refer to here? Is this the UI progress bar, debug output, or something else? A bit more specificity would help future maintainers understand the alignment you're achieving.

// Calculate available tokens for conversation history
// Truncate if we're within TOKEN_BUFFER_PERCENTAGE of the context window
// Calculate effective capacity available for conversation history after reserving output tokens
const allowedTokens = contextWindow * (1 - TOKEN_BUFFER_PERCENTAGE) - reservedTokens
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consider extracting this calculation into a named function like calculateEffectiveTokenCapacity() for better readability and testability. This appears to be the core fix, so giving it a name would make the intent clearer:

Suggested change
const allowedTokens = contextWindow * (1 - TOKEN_BUFFER_PERCENTAGE) - reservedTokens
const allowedTokens = calculateEffectiveTokenCapacity(contextWindow, reservedTokens)

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Aug 11, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Aug 13, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Aug 13, 2025
@daniel-lxs daniel-lxs closed this Aug 14, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Prelim Review] to Done in Roo Code Roadmap Aug 14, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Aug 14, 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 PR - Needs Preliminary Review size:S This PR changes 10-29 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants