Skip to content

Conversation

canrobins13
Copy link

@canrobins13 canrobins13 commented May 20, 2025

Related GitHub Issue

Closes: #3673

Description

This PR has a few visible changes:

  • Adds a new UI element in the task when a condense operation is run, showing how much the context was condensed
  • Users can expand this UI element to view the summary message
  • Changes how cost and context tokens are computed, so that they are in sync with the condense operations

Point #2 above will be necessary for unlocking #3671. Without the changes in this PR, the context progress bar would not update after a manual condense operation until the next API request is made, which would be confusing to the user. After this PR, the context progress bar is correct after a condense operation even without an additional API request.

Test Procedure

  • Reduced the threshold for running condense operations and used the extension
  • Ensured the UI in the left looked correct and was consistent with the progress bar
  • Logged the API messages and Cline Messages to sanity check

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

Collapsed view

Screenshot 2025-05-19 at 6 39 26 PM

Expanded view

Screenshot 2025-05-19 at 8 48 54 PM

Important

This PR adds UI and backend support for tracking and displaying context condensing metrics, ensuring synchronization with context operations.

  • UI Changes:
    • Adds a UI element in ChatRow.tsx to display context condensing metrics.
    • Users can expand this element to view a summary message.
  • Functionality:
    • Updates summarizeConversation() in index.ts to return a SummarizeResponse with context metrics.
    • Modifies truncateConversationIfNeeded() in sliding-window/index.ts to handle context condensing.
    • Implements contextCondenseSchema in schemas/index.ts for context condensing data.
  • Testing:
    • Adds tests in index.test.ts and sliding-window.test.ts to verify context condensing behavior.
  • Miscellaneous:
    • Updates getApiMetrics() in getApiMetrics.ts to include context condensing metrics.
    • Adds translations for context condensing in various language files.

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

Copy link

changeset-bot bot commented May 20, 2025

🦋 Changeset detected

Latest commit: 7df703f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
roo-cline Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@canrobins13 canrobins13 changed the title [Condense Context] Track metrics around context condensing and show i… [Condense Context] Track metrics around context condensing and show in UI May 20, 2025
Comment on lines +73 to +76
// Check if there's a recent summary in the messages we're keeping
const recentSummaryExists = keepMessages.some((message) => message.isSummary)
if (recentSummaryExists) {
return response // We recently summarized these messages; it's too soon to summarize again.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hey @canrobins13,

Just a question about the truncateConversationIfNeeded function in sliding-window:

When autoCondenseContext is true and the token limit is hit, it tries to summarize. But if summarizeConversation decides not to create a summary (maybe because there aren't many new messages or there was a recent summary), it looks like truncateConversationIfNeeded still goes ahead and does the simple truncation.

I am aware this behavior was present before your changes, but would it make more sense to use the previous summary considering it might still be fresh rather than using the simple truncation?

Copy link
Author

Choose a reason for hiding this comment

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

When making an API request we only send messages starting from the latest summary if one exists, so the recent summary message would be "used" in the case you highlighted (when making API requests and when calculating the context window usage).
This case should be pretty hard to hit through the existing implementation, but will be more relevant because we're about to add a button for manually triggering context summarization through the UI.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Makes sense, if the condense feature becomes manual and the user clicks summarize multiple times, would this trigger the simple truncation? Or is it only triggered when the context is already bigger than the window?

Copy link
Author

Choose a reason for hiding this comment

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

It's not implemented yet, but we wouldn't trigger simple truncation or dropping of messages from the user button, that would only hit the new condense code

Comment on lines 28 to 31
<div className="mt-2 ml-6 p-3 bg-vscode-editor-background rounded text-vscode-foreground text-sm">
<h3 className="font-bold mb-2">{t("chat:contextCondense.conversationSummary")}</h3>
{summary}
</div>
Copy link
Collaborator

@daniel-lxs daniel-lxs May 20, 2025

Choose a reason for hiding this comment

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

Hey again,

Would rendering the summary with webview-ui/src/components/chat/Markdown.tsx create too much visual clutter?

It might make the summary easier to read specially since the models love to output markdown.

Copy link
Author

Choose a reason for hiding this comment

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

Let me try it that out!

Copy link
Author

@canrobins13 canrobins13 May 20, 2025

Choose a reason for hiding this comment

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

I like it, updated the code :)
The only downside it that things like tags are omitted... it's a better UI but maybe slightly worse for analysis/debugging.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, are you talking about the tags? Does the summary prompt encourage the model to use other XML tags?

If that's the case it would be interesting to see if we can improve the Markdown.tsx component to show the tags, of course in a different PR.

Copy link
Author

Choose a reason for hiding this comment

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

No, it doesn't encourage it to use any other tags

@daniel-lxs
Copy link
Collaborator

Great work! Now we won't have so many people asking about when this feature is triggered and what it does.

I'm honestly really excited to be able to trigger this behavior manually as well.

@canrobins13 canrobins13 marked this pull request as ready for review May 20, 2025 03:22
@canrobins13 canrobins13 requested review from mrubens and cte as code owners May 20, 2025 03:22
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. enhancement New feature or request labels May 20, 2025
// If the previous API request's total token usage is close to the
// context window, truncate the conversation history to free up space
// for the new request.
if (previousApiReqIndex >= 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there anything different about this previousApiReqIndex version and the new code (which seems simpler)? It seems like they are different but it's hard for me to tell if the new version is also correct.

Copy link
Author

Choose a reason for hiding this comment

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

I had the same question but I couldn't find any reason that it wasn't using getApiMetrics before... agree it feels weird

Copy link
Collaborator

@cte cte left a comment

Choose a reason for hiding this comment

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

Looks great to me; left a few nits (feel free to ignore) and one question.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label May 20, 2025
@canrobins13 canrobins13 force-pushed the canyon/condense-metrics branch from d2bdd98 to a1a8654 Compare May 20, 2025 04:32
@canrobins13 canrobins13 merged commit aff94e1 into main May 20, 2025
12 checks passed
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap May 20, 2025
@canrobins13 canrobins13 deleted the canyon/condense-metrics branch May 20, 2025 04:45
@hannesrudolph hannesrudolph moved this from New to Done in Roo Code Roadmap May 20, 2025
SmartManoj pushed a commit to SmartManoj/Raa-Code that referenced this pull request Jun 13, 2025
* add protos files (RooCodeInc#3736)

Co-authored-by: Elephant Lumps <[email protected]>

* change package script

---------

Co-authored-by: Elephant Lumps <[email protected]>
SmartManoj pushed a commit to SmartManoj/Raa-Code that referenced this pull request Jun 13, 2025
* add protos files (RooCodeInc#3736)

Co-authored-by: Elephant Lumps <[email protected]>

* change package script

* rest of updates for vertex / bedrock

---------

Co-authored-by: Elephant Lumps <[email protected]>
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 size:XXL This PR changes 1000+ lines, ignoring generated files.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Add a UI element for context condense operations
3 participants