Skip to content

Conversation

@daniel-lxs
Copy link
Member

@daniel-lxs daniel-lxs commented Oct 26, 2025

Summary

This PR fixes a critical memory issue where browser screenshots were accumulating indefinitely, consuming significant memory and wasting tokens by sending all historical screenshots to the model on every request.

Changes

  • Backend: Remove old screenshots from apiConversationHistory after each browser action
  • Frontend: Simplify BrowserSessionRow to display only current state without pagination
  • UX: Screenshot updates in place, latest browser action shown below

Impact

  • Before: Screenshots accumulated indefinitely (potentially MBs of memory)
  • After: Only latest screenshot kept in memory (~100-200KB)
  • Token savings: Model only sees latest screenshot instead of entire history
  • Cleaner UX: No unnecessary pagination controls

Testing

  • ✅ All 5 backend tests passing
  • ✅ All 32 frontend tests passing
  • ✅ Type checking passed
  • ✅ Linting passed

- Remove old screenshots from apiConversationHistory after each browser action
- Simplify BrowserSessionRow to display only current state without pagination
- Remove screenshot history and pagination controls

This prevents memory issues where screenshots accumulated indefinitely,
consuming significant memory and wasting tokens by sending all historical
screenshots to the model on every request.

Now only the latest screenshot is kept in memory (~100-200KB) instead of
potentially MBs of accumulated screenshots.
@daniel-lxs daniel-lxs requested review from cte, jr and mrubens as code owners October 26, 2025 02:26
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Oct 26, 2025
@roomote
Copy link

roomote bot commented Oct 26, 2025

Review Summary

I've reviewed this PR and identified 1 issue that needs to be addressed:

  • Critical: The screenshot cleanup logic removes ALL base64 webp/png images from conversation history, potentially deleting user-provided images

The cleanup implementation doesn't distinguish between browser screenshots and user-uploaded images. If a user uploads a webp or png image during a conversation, it will be incorrectly deleted during browser actions.

Recommendation: Modify the filter to only remove images from browser_action_result messages while preserving:

  1. The latest browser screenshot
  2. All user-provided images in other message types

Follow Along on Roo Code Cloud

for (let i = messages.length - 1; i >= 0; i--) {
const message = messages[i]
if (message.say === "browser_action_result" && message.text && message.text !== "") {
const resultData = JSON.parse(message.text) as BrowserActionResult
Copy link

Choose a reason for hiding this comment

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

JSON.parse on message.text (for browser_action_result and browser_action) isn’t wrapped in try/catch. Wrapping in try/catch would prevent crashes if message.text is malformed.

This comment was generated because it violated a code review rule: irule_PTI8rjtnhwrWq6jS.

Comment on lines +151 to +175
// Clean up old browser screenshots from API conversation history to prevent memory accumulation
// Only keep the latest screenshot - old ones are no longer needed by the model
if (browserActionResult?.screenshot) {
const apiHistory = cline.apiConversationHistory
for (let i = apiHistory.length - 1; i >= 0; i--) {
const message = apiHistory[i]
if (Array.isArray(message.content)) {
// Filter out old screenshot image blocks
message.content = message.content.filter((block) => {
// Remove base64 image blocks (browser screenshots)
// Keep text blocks and other content
if (
block.type === "image" &&
"source" in block &&
block.source.type === "base64" &&
(block.source.media_type === "image/webp" || block.source.media_type === "image/png")
) {
// This is likely an old browser screenshot - remove it
return false
}
return true
})
}
}
}
Copy link

Choose a reason for hiding this comment

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

The cleanup logic removes ALL base64 webp/png images from the entire conversation history without distinguishing between browser screenshots and user-provided images. If a user uploads an image in webp or png format during the conversation, it will be incorrectly deleted during browser actions. The filter should only remove images from browser_action_result messages (by checking the message structure) and preserve the latest browser screenshot while removing only older ones. User-provided images in other message types must be preserved.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Oct 26, 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

Status: Triage

Development

Successfully merging this pull request may close these issues.

2 participants