Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Jul 29, 2025

Fixes the AWS Bedrock "too many images" error when using Browser tool continuously.

Problem

When using the Browser tool continuously in AWS Bedrock, conversations accumulate more than 20 images, causing the API to return: "too many images and documents: 21 + 0 > 20"

Solution

  • Added automatic image limiting to keep only the most recent 20 images
  • Oldest images are replaced with text placeholders when limit exceeded
  • Enhanced error handling with specific "TOO_MANY_IMAGES" error type
  • Comprehensive test coverage with 23 test cases

Impact

  • No more conversation-breaking errors when using Browser tool extensively
  • Seamless continuation of chat sessions with automatic image management
  • Preserved context with most recent 20 images maintained

Closes #6348


Important

This PR adds automatic image limiting to AWS Bedrock conversations, ensuring no more than 20 images are retained, with comprehensive test coverage.

  • Behavior:
    • Automatically limits images in conversations to 20, replacing oldest with text placeholders when exceeded in AwsBedrockHandler.
    • Logs "TOO_MANY_IMAGES" error type when image limit is exceeded in bedrock.ts.
  • Functions:
    • Adds countImagesInConversation(), limitImagesInConversation(), and hasExceededImageLimit() in image-limiting.ts.
  • Tests:
    • Adds bedrock-image-limiting.spec.ts and image-limiting.spec.ts with 23 test cases to cover image limiting functionality.
  • Constants:
    • Defines AWS_BEDROCK_MAX_IMAGES_PER_CONVERSATION as 20 in image-limiting.ts.

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

- Add image limiting functionality to prevent "too many images" errors
- Automatically remove oldest images when conversation exceeds 20 images
- Preserve most recent 20 images for Browser tool continuity
- Add comprehensive error handling for image limit errors
- Include extensive test coverage for image limiting logic

Fixes #6348
@roomote roomote bot requested review from cte, jr and mrubens as code owners July 29, 2025 12:03
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. bug Something isn't working labels Jul 29, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jul 29, 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.

Code Review Summary

This PR effectively addresses the AWS Bedrock 20-image conversation limit issue with a well-structured solution. The implementation is solid with excellent test coverage and proper integration.

Important Suggestions (Should Consider)

1. Deep copy implementation could be more robust
Location: https://github.com/RooCodeInc/Roo-Code/blob/fix/aws-bedrock-image-limit-6348/src/api/transform/image-limiting.ts#L53-L56

The current shallow copy approach may not handle nested objects properly if the Anthropic SDK types evolve to include more complex nested structures. Consider using a deep cloning utility or JSON.parse(JSON.stringify()) for more robust copying.

2. Missing JSDoc parameter documentation
Location: https://github.com/RooCodeInc/Roo-Code/blob/fix/aws-bedrock-image-limit-6348/src/api/transform/image-limiting.ts#L28-L36

While the function has good documentation, adding @param tags would improve IDE support and developer experience:

3. Error handling enhancement opportunity
Location: https://github.com/RooCodeInc/Roo-Code/blob/fix/aws-bedrock-image-limit-6348/src/api/providers/bedrock.ts#L710-L720

Could we add more specific logging when image limiting is applied, such as the original vs final image count? This would help with debugging and monitoring.

Minor Improvements (Nice to Have)

4. Test file path comment correction
Location: https://github.com/RooCodeInc/Roo-Code/blob/fix/aws-bedrock-image-limit-6348/src/api/providers/__tests__/bedrock-image-limiting.spec.ts#L1

The vitest run command path doesn't match the actual file location. Should be:

5. Placeholder text specificity
Location: https://github.com/RooCodeInc/Roo-Code/blob/fix/aws-bedrock-image-limit-6348/src/api/transform/image-limiting.ts#L70

The placeholder text assumes 'Browser tool screenshot' but images could come from other sources. Consider a more generic message like '[Image removed due to conversation limit]'.

Positive Observations

  • Excellent test coverage with 23 comprehensive test cases
  • Clean separation of concerns with dedicated image-limiting module
  • Proper integration into existing Bedrock handler
  • Maintains backward compatibility
  • Handles edge cases well (exactly 20 images, mixed content types, etc.)
  • Good error handling with specific 'TOO_MANY_IMAGES' error type
  • Addresses the reported issue effectively

Overall, this is a high-quality implementation that solves the problem elegantly. The suggestions above are minor improvements that would enhance robustness and maintainability.

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.

Code Review Summary

This PR effectively addresses the AWS Bedrock 20-image conversation limit issue with a well-structured solution. The implementation is solid with excellent test coverage and proper integration.

Important Suggestions (Should Consider)

1. Deep copy implementation could be more robust
Location: https://github.com/RooCodeInc/Roo-Code/blob/fix/aws-bedrock-image-limit-6348/src/api/transform/image-limiting.ts#L53-L56

The current shallow copy approach may not handle nested objects properly if the Anthropic SDK types evolve to include more complex nested structures. Consider using a deep cloning utility or JSON.parse(JSON.stringify()) for more robust copying.

2. Missing JSDoc parameter documentation
Location: https://github.com/RooCodeInc/Roo-Code/blob/fix/aws-bedrock-image-limit-6348/src/api/transform/image-limiting.ts#L28-L36

While the function has good documentation, adding @param tags would improve IDE support and developer experience.

3. Error handling enhancement opportunity
Location: https://github.com/RooCodeInc/Roo-Code/blob/fix/aws-bedrock-image-limit-6348/src/api/providers/bedrock.ts#L710-L720

Could we add more specific logging when image limiting is applied, such as the original vs final image count? This would help with debugging and monitoring.

Minor Improvements (Nice to Have)

4. Test file path comment correction
Location: https://github.com/RooCodeInc/Roo-Code/blob/fix/aws-bedrock-image-limit-6348/src/api/providers/__tests__/bedrock-image-limiting.spec.ts#L1

The vitest run command path does not match the actual file location.

5. Placeholder text specificity
Location: https://github.com/RooCodeInc/Roo-Code/blob/fix/aws-bedrock-image-limit-6348/src/api/transform/image-limiting.ts#L70

The placeholder text assumes Browser tool screenshot but images could come from other sources. Consider a more generic message.

Positive Observations

  • Excellent test coverage with 23 comprehensive test cases
  • Clean separation of concerns with dedicated image-limiting module
  • Proper integration into existing Bedrock handler
  • Maintains backward compatibility
  • Handles edge cases well (exactly 20 images, mixed content types, etc.)
  • Good error handling with specific TOO_MANY_IMAGES error type
  • Addresses the reported issue effectively

Overall, this is a high-quality implementation that solves the problem elegantly. The suggestions above are minor improvements that would enhance robustness and maintainability.

@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Jul 30, 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 30, 2025
@daniel-lxs
Copy link
Member

I feel like this should be handled in a simpler way, I don't see why we should send all the previous images when using the browser tool, maybe we should limit it to 10 images

@daniel-lxs daniel-lxs closed this Jul 30, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Prelim Review] to Done in Roo Code Roadmap Jul 30, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jul 30, 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:XL This PR changes 500-999 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Unhandled "too many images" error from AWS Bedrock when using browser tool

4 participants