Skip to content

Conversation

@hannesrudolph
Copy link
Collaborator

@hannesrudolph hannesrudolph commented Jul 31, 2025

Fixes #6513

Summary

This PR implements incremental message updates to significantly improve UI performance, especially for tasks with many messages.

Problem

Previously, the entire application state (including all messages) was sent to the webview on every message creation or update. This caused performance issues with large message histories, as the UI had to re-render all messages each time.

Solution

  • Modified the message handling to send only new or updated messages instead of the entire state
  • Added new message event types: messageCreated and messageUpdated
  • Enhanced the webview handler to process incremental updates
  • Extended the feature to handle existing tasks loaded from history

Changes

  1. Task.ts: Modified addToClineMessages and updateClineMessage to send only the affected message
  2. ExtensionMessage.ts: Added new message types for incremental updates
  3. ExtensionStateContext.tsx: Updated webview handler to process incremental messages
  4. ClineProvider.ts: Enhanced postStateToWebview to handle existing tasks with incremental loading

Benefits

  • Reduced data transfer between extension and webview
  • Minimized UI re-renders
  • Improved responsiveness, especially for long-running tasks
  • Consistent experience for both new messages and historical messages

Testing

  • Verified that new messages are sent incrementally
  • Confirmed that message updates work correctly
  • Tested loading existing tasks from history with incremental message loading
  • All linting and type checks pass

This change provides a significant performance improvement for the UI without changing the user experience.


Important

Implement incremental message updates in Task.ts for improved UI performance by reducing data transfer and minimizing re-renders.

  • Behavior:
    • Incremental message updates implemented in Task.ts to send only new or updated messages to the webview.
    • New message event types messageCreated and messageUpdated added in ExtensionMessage.ts.
    • ExtensionStateContext.tsx updated to handle incremental message updates.
  • Performance:
    • Reduces data transfer and minimizes UI re-renders, improving responsiveness for tasks with many messages.
  • Testing:
    • Verified incremental sending of new messages and correct handling of message updates.
    • Tested loading existing tasks from history with incremental message loading.

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

Copilot AI review requested due to automatic review settings July 31, 2025 22:20
@hannesrudolph hannesrudolph requested review from cte, jr and mrubens as code owners July 31, 2025 22:20
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. UI/UX UI/UX related or focused labels Jul 31, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements incremental message updates to improve UI performance by sending only new or updated messages to the webview instead of the entire application state. The solution reduces data transfer and minimizes UI re-renders, especially beneficial for tasks with large message histories.

Key changes include:

  • Modified message handling to send individual messages instead of full state updates
  • Added new message event types (messageCreated and messageUpdated) for granular updates
  • Enhanced webview state management to process incremental updates
  • Implemented special handling for loading existing tasks with gradual message rendering

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
ExtensionStateContext.tsx Added handler for messageCreated events to append new messages to state
ExtensionMessage.ts Added messageCreated message type to support incremental updates
ClineProvider.ts Enhanced postStateToWebview to send messages incrementally for existing tasks
Task.ts Modified message methods to send individual message updates instead of full state


await abortStream(cancelReason, streamingFailedMessage)

const provider = this.providerRef.deref()
Copy link

Copilot AI Jul 31, 2025

Choose a reason for hiding this comment

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

The provider is retrieved multiple times in this method (lines 1655, 1666). Consider extracting it once at the beginning of the method to avoid duplication.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

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

Thank you for your contribution! I've reviewed the changes and found some issues that need attention. The implementation successfully reduces data transfer and improves UI performance, but there are a few areas that could be improved for robustness and maintainability.

Review Findings:

Critical Issues:

  1. Magic number in delay (ClineProvider.ts:1349) - The hardcoded 10ms delay should be extracted to a named constant with documentation
  2. Duplicate provider retrieval (Task.ts:1655,1666) - The provider is retrieved twice in the same method

Important Suggestions:
3. Performance concern - The 10ms delay per message could cause noticeable delays for tasks with many messages (100 messages = 1 second)
4. Missing error handling - The postStateToWebview method doesn't handle potential errors when sending messages incrementally
5. Type safety issue - The clineMessage property in ExtensionMessage is optional but used without null checks

Minor Improvements:
6. Code duplication - Similar logic for sending individual messages is repeated in multiple places in Task.ts
7. Missing tests - No unit tests mentioned for the new incremental loading functionality

Note: One of Copilot's comments about a missing delay import is incorrect - the import exists on line 7 of ClineProvider.ts.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jul 31, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Jul 31, 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 Jul 31, 2025
Copy link
Collaborator Author

@hannesrudolph hannesrudolph left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution! I've reviewed the changes and found that the implementation successfully improves UI performance through incremental message updates. The critical issues from the previous review have been addressed.

Summary

This PR effectively reduces data transfer and minimizes UI re-renders by sending only new or updated messages instead of the entire state. The implementation is solid with proper error handling.

Resolved Issues from Previous Review

✅ Magic number in delay - now uses constant
✅ Type safety issue - code now uses non-null assertions appropriately
✅ Missing error handling - now has try-catch with logging

I've left some suggestions inline for further improvements, primarily around performance optimization for very large message histories and code organization.

// Send only the updated API request message instead of the entire state
if (provider && lastApiReqIndex >= 0) {
try {
await provider.postMessageToWebview({
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This pattern of updating and sending messages is repeated in multiple places. Could we extract it into a helper method to reduce duplication?

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.

LGTM

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Aug 1, 2025
@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Needs Review] in Roo Code Roadmap Aug 1, 2025
@daniel-lxs
Copy link
Member

@roomote-agent Use switch_mode to switch to pr-fixer mode and solve the issues on this PR. Do not create a new one.

@daniel-lxs daniel-lxs moved this from PR [Needs Review] to PR [Changes Requested] in Roo Code Roadmap Aug 18, 2025
@roomote
Copy link
Contributor

roomote bot commented Aug 18, 2025

Hi @daniel-lxs! I see your request and I'm now working on fixing the issues with this PR.

I've identified that the PR has merge conflicts that need to be resolved. I'll resolve these conflicts and ensure all tests pass before pushing the changes.

I'll update you once the fixes are complete.

hannesrudolph and others added 3 commits August 18, 2025 17:10
- Modified Task.ts to send only new messages instead of entire state
- Added messageCreated and messageUpdated event types to ExtensionMessage
- Updated webview handler to process incremental message updates
- Enhanced postStateToWebview to handle existing tasks with incremental loading
- Improved performance by reducing data transfer and UI re-renders

This change significantly improves UI responsiveness, especially for tasks with many messages.
…ic 10ms with INCREMENTAL_SEND_DELAY_MS; guard Task message send calls with non-fatal errors
@roomote
Copy link
Contributor

roomote bot commented Aug 18, 2025

@daniel-lxs PR #6522 has been successfully fixed!

Summary of fixes applied:

Merge Conflicts Resolved

The PR had merge conflicts in src/core/task/Task.ts that have been successfully resolved by:

  • Combining the incremental message update feature with error handling improvements
  • Adding try-catch blocks around postMessageToWebview calls for robust error handling
  • Using RooCodeEventName.Message constant instead of string literals for event names
  • Preserving both the performance optimization (incremental updates) and stability improvements (error handling)

CI Status

All CI checks are now passing:

  • ✅ Unit tests (Ubuntu & Windows)
  • ✅ Integration tests
  • ✅ Code analysis & linting
  • ✅ Compilation
  • ✅ Translation checks

The PR is now ready for merge with all conflicts resolved and tests passing.

@daniel-lxs daniel-lxs moved this from PR [Changes Requested] to PR [Needs Review] in Roo Code Roadmap Aug 18, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Sep 22, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Sep 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer PR - Needs Review size:M This PR changes 30-99 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.

UI becomes unresponsive during long tasks due to inefficient state updates

3 participants