Skip to content

Conversation

@SannidhyaSah
Copy link
Collaborator

@SannidhyaSah SannidhyaSah commented Jun 8, 2025

Related GitHub Issue

Related to: #4342 and Closes #4118

Description

This PR implements profile-specific context condensing thresholds, addressing one of the context management improvements outlined in issue #4342 (It also closes #4118) . This feature allows users to configure different automatic threshold percentages for intelligent context condensing based on their API configuration profiles. Previously, there was only a single global threshold that applied to all profiles, which was inefficient since different LLM models have varying context window sizes.

Key implementation details:

  • Added new settings profileSpecificThresholdsEnabled and profileThresholds to the global settings schema
  • Extended the sliding window algorithm to check for profile-specific thresholds before falling back to the global threshold
  • Created a new UI component ProfileThresholdManager for managing profile-specific configurations
  • Implemented support for -1 threshold values to indicate using the default global threshold
  • Added comprehensive state management and persistence for the new settings

What reviewers should focus on:

  • The logic in src/core/sliding-window/index.ts for threshold resolution
  • The new UI component integration in the settings panel
  • State synchronization between frontend and backend via vscode.postMessage

Test Procedure

Manual Testing:

  1. Open VSCode with the extension installed
  2. Navigate to Settings → Context Management
  3. Enable "Profile-Specific Thresholds" checkbox
  4. Select a profile from the dropdown and set a custom threshold (e.g., 75)
  5. Save the configuration and verify it appears in the list
  6. Test with -1 value to ensure it falls back to global threshold
  7. Start a conversation and verify the correct threshold is applied based on the active profile

Automated Testing:

  • Run pnpm test to execute all test suites
  • New tests cover both backend logic and frontend UI components
  • Tests verify threshold resolution logic, UI state management, and edge cases

Type of Change

  • 🐛 Bug Fix: Non-breaking change that fixes an issue.
  • New Feature: Non-breaking change that adds functionality.
  • 💥 Breaking Change: Fix or feature that would cause existing functionality to not work as expected.
  • ♻️ Refactor: Code change that neither fixes a bug nor adds a feature.
  • 💅 Style: Changes that do not affect the meaning of the code (white-space, formatting, etc.).
  • 📚 Documentation: Updates to documentation files.
  • ⚙️ Build/CI: Changes to the build process or CI configuration.
  • 🧹 Chore: Other changes that don't modify src or test files.

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Code Quality:
    • My code adheres to the project's style guidelines.
    • There are no new linting errors or warnings (npm run lint).
    • All debug code (e.g., console.log) has been removed.
  • Testing:
    • New and/or updated tests have been added to cover my changes.
    • All tests pass locally (npm test).
    • The application builds successfully with my changes.
  • Branch Hygiene: My branch is up-to-date (rebased) with the main branch.
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Changeset: A changeset has been created using npm run changeset if this PR includes user-facing changes or dependency updates.
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

Before: Only global threshold setting available

image

After: New profile-specific threshold management UI with:

  • Checkbox to enable/disable profile-specific thresholds
  • Dropdown to select API configuration profiles
  • Input field for threshold percentage (supports -1 for default)
  • Save/Remove buttons for managing configurations
  • List display of configured profile thresholds

image

Documentation Updates

  • No documentation updates are required.
  • Yes, documentation updates are required. The settings documentation should be updated to explain the new profile-specific threshold feature and how to configure it.

Additional Notes

This feature significantly improves the user experience for users working with multiple LLM models that have different context window sizes. The implementation maintains backward compatibility - existing users will continue to use the global threshold until they explicitly enable profile-specific thresholds.

The UI design follows the existing patterns in the settings panel and includes proper internationalization support with translation keys added to the English locale file.

This PR addresses one aspect of the context management improvements discussed in issue #4342. Additional PRs may be needed to fully address all the concerns raised in that issue.

Get in Touch

Discord: Lews


Important

Adds profile-specific context condensing thresholds, enhancing context management flexibility and efficiency with new settings, UI components, and comprehensive testing.

  • Behavior:
    • Introduces profile-specific context condensing thresholds in sliding-window/index.ts, allowing different thresholds per profile.
    • Adds profileSpecificThresholdsEnabled and profileThresholds to settings schema in global-settings.ts.
    • Supports -1 as a threshold value to use the global default.
  • UI:
    • New ProfileThresholdManager component in ContextManagementSettings.tsx for managing profile-specific thresholds.
    • Updates settings panel to include profile selection and threshold configuration.
  • Testing:
    • Extensive tests in sliding-window.test.ts for threshold logic and edge cases.
    • UI tests in ContextManagementSettings.test.tsx to verify new component behavior.
  • Misc:
    • Updates to ClineProvider.ts and Task.ts for state management and threshold application.
    • Adds i18n support for new UI elements in multiple language files.

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

@samhvw8
Copy link
Contributor

samhvw8 commented Jun 8, 2025

this is cool, since each model has difference context window and effective context window, this will be crucial pr feature :D

@mrubens
Copy link
Collaborator

mrubens commented Jun 8, 2025

What do you think of something like this where we just migrate them to all be profile-specific: #2655? Not sure we need a checkbox for this.

@SannidhyaSah
Copy link
Collaborator Author

What do you think of something like this where we just migrate them to all be profile-specific: #2655? Not sure we need a checkbox for this.

I initially considered that placement. However, I've positioned this setting alongside the other auto-condensing options for a couple of reasons: it's directly related to that function, and it becomes irrelevant if auto-condensing is disabled.
Regarding the checkbox, you're right. It's unnecessary, and I'll remove it.
Please advise on the placement decision so I can proceed. I am currently implementing the rest of the settings page anyways .

@mrubens
Copy link
Collaborator

mrubens commented Jun 8, 2025

Hmm, I deleted an earlier comment. I'm having trouble wrapping my head around the right user experience for this section that lets you both choose a specific profile or just use the current one, and now to also make the threshold a per-profile configuration. 🤔

Screenshot 2025-06-08 at 7 55 52 AM

@mrubens
Copy link
Collaborator

mrubens commented Jun 8, 2025

I actually think the best approach might be to put a profile selector dropdown above the threshold slider in my screenshot, the same as what we have in the section below. So you're configuring "Default" by default, but can choose another.

@SannidhyaSah
Copy link
Collaborator Author

SannidhyaSah commented Jun 8, 2025

Hmm, I deleted an earlier comment. I'm having trouble wrapping my head around the right user experience for this section that lets you both choose a specific profile or just use the current one, and now to also make the threshold a per-profile configuration. 🤔

Screenshot 2025-06-08 at 7 55 52 AM

The API configuration for context condensing needs to be accessible even when automatic triggering is off, as it's also used for the manual trigger .
To fix this, I suggest we make the API and prompt settings always visible in the 'Context' tab. We can then group the settings that are only for automatic triggering into a separate section that expands when the user enables it

@mrubens
Copy link
Collaborator

mrubens commented Jun 8, 2025

The API configuration for context condensing needs to be accessible even when automatic triggering is off, as it's also used for the manual trigger . To fix this, I suggest we make the API and prompt settings always visible in the 'Context' tab. We can then group the settings that are only for automatic triggering into a separate section that expands when the user enables it

Good call

@SannidhyaSah
Copy link
Collaborator Author

image
@mrubens is this better ?

@SannidhyaSah SannidhyaSah marked this pull request as ready for review June 10, 2025 09:06
@SannidhyaSah SannidhyaSah requested review from cte, jr and mrubens as code owners June 10, 2025 09:06
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. enhancement New feature or request labels Jun 10, 2025
@daniel-lxs daniel-lxs moved this from PR [Draft / In Progress] to PR [Needs Prelim Review] in Roo Code Roadmap Jun 11, 2025
@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Draft / In Progress] in Roo Code Roadmap Jun 13, 2025
@daniel-lxs daniel-lxs marked this pull request as draft June 13, 2025 21:58
@daniel-lxs
Copy link
Member

Hey @SannidhyaSah, Can you take a look at the conflicts?

@daniel-lxs daniel-lxs force-pushed the feat/profile-specific-thresholds branch from 2b03d0d to b4cdd84 Compare June 18, 2025 00:55
Copy link
Member

@daniel-lxs daniel-lxs left a comment

Choose a reason for hiding this comment

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

Took a while but the conflicts are solved

@mrubens
Copy link
Collaborator

mrubens commented Jun 20, 2025

Is the test failure legit?

@daniel-lxs daniel-lxs force-pushed the feat/profile-specific-thresholds branch from 59d504d to c82d9d5 Compare June 20, 2025 20:25
SannidhyaSah and others added 15 commits June 20, 2025 15:41
- Remove emoji from info text and use codicon instead
- Restructure layout to vertical stack for better spacing
- Position Save button on far right using justify-between
- Apply consistent styling with other settings sections
- Update tests to match hardcoded info text
- Simplified context management settings by removing ProfileThresholdManager
- Updated global settings types and core sliding window logic
- Modified webview message handlers and extension state context
- Updated all locale files for settings translations
- Removed ProfileThresholdManager component and related tests
- Updated ContextManagementSettings and SettingsView components
- Add profileThresholds to ExtensionState type definition
- Add profileThresholds prop to ContextManagementSettings component
- Add profileThresholds message type to WebviewMessage
- Remove invalid useEffect dependency on undefined currentProfileId
- Pass profileThresholds prop from SettingsView to ContextManagementSettings
- Add default empty object for profileThresholds to ensure it's never undefined
- This resolves the TypeScript error where optional profileThresholds from ExtensionState
  was incompatible with required profileThresholds in ExtensionStateContextType
- Fixed failing test that incorrectly expected condensing-related UI elements to be present when autoCondenseContext is false
- Updated test to properly assert that condensing API configuration and custom prompt elements are not in the document when auto condense is disabled
- This aligns the test with the actual component behavior which correctly hides these elements when autoCondenseContext is false
@daniel-lxs daniel-lxs force-pushed the feat/profile-specific-thresholds branch from c82d9d5 to 0c3b3b4 Compare June 20, 2025 20:42
@daniel-lxs
Copy link
Member

@mrubens
The test failure was legit, just needed to update the data-testid.
It looks good now.

@mrubens mrubens merged commit 7392f14 into RooCodeInc:main Jun 21, 2025
9 checks passed
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jun 21, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Jun 21, 2025
@SannidhyaSah SannidhyaSah deleted the feat/profile-specific-thresholds branch June 23, 2025 11:45
cte pushed a commit that referenced this pull request Jun 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request lgtm This PR has been approved by a maintainer PR - Needs Review size:XL This PR changes 500-999 lines, ignoring generated files. UI/UX UI/UX related or focused

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Context Condensing - Suggestion to Improve

5 participants