Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Jan 31, 2026

Related GitHub Issue

Closes: #11137

Description

This PR attempts to address Issue #11137. Feedback and guidance are welcome.

The Problem:
When a user uses @folder to mention a directory, the system reads ALL files in that folder without any limits. Even though individual files are truncated to 2000 lines, if a folder contains many files, the total content can explode and exceed the context window, causing errors on the first conversation.

The Solution:
This PR adds two limits to prevent context window overflow when processing folder mentions:

  1. MAX_FOLDER_FILES_TO_READ (10): Limits the maximum number of files read from a folder
  2. MAX_FOLDER_CONTENT_SIZE (100,000 characters / ~100KB): Limits the total content size from a folder mention

Key implementation details:

  • Limits are checked before reading each file
  • When limits are reached, users receive informative messages explaining the truncation
  • Users are advised to use individual @file mentions instead of @folder for more control
  • Folder listing is still shown in full (only content reading is limited)

Test Procedure

  1. Unit tests were added to verify the new limits:

    • src/core/mentions/__tests__/folder-limits.spec.ts - 7 new tests
  2. All tests pass:

    cd src && pnpm vitest run core/mentions/__tests__/folder-limits.spec.ts
    
  3. Existing tests still pass:

    cd src && pnpm vitest run core/mentions/__tests__/index.spec.ts
    
  4. Manual testing: Use @folder/ mention on a directory with many files and verify that:

    • Only up to 10 files are read
    • Total content is limited to ~100KB
    • A truncation notice appears informing the user

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.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

N/A - Backend logic change, no UI impact.

Documentation Updates

  • No documentation updates are required.

Additional Notes

The constants can be adjusted if needed:

  • MAX_FOLDER_FILES_TO_READ = 10 - A conservative default that should work for most use cases
  • MAX_FOLDER_CONTENT_SIZE = 100_000 - Approximately 100KB, which should be safe for most context windows

Important

Adds limits to folder mentions to prevent context overflow by restricting files read and content size, with tests to verify behavior.

  • Behavior:
    • Adds MAX_FOLDER_FILES_TO_READ and MAX_FOLDER_CONTENT_SIZE constants in index.ts to limit files read and content size from folder mentions.
    • Updates getFileOrFolderContentWithMetadata() in index.ts to enforce these limits, skipping files and adding truncation notices when limits are reached.
  • Tests:
    • Adds folder-limits.spec.ts with 7 tests to verify file and content size limits, truncation notices, and folder listing behavior.
  • Misc:
    • Updates parseMentions() in index.ts to handle new truncation messages.

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

This change adds limits to prevent context window explosion when using @folder mentions:

- MAX_FOLDER_FILES_TO_READ (10): Limits the number of files read from a folder
- MAX_FOLDER_CONTENT_SIZE (100KB): Limits total content size from folder mentions

When limits are reached, users receive informative messages suggesting to use
individual @file mentions instead.

Fixes #11137
@roomote
Copy link
Contributor Author

roomote bot commented Jan 31, 2026

Rooviewer Clock   See task on Roo Cloud

Review complete. No issues found.

The implementation correctly adds context limits for folder mentions:

  • File limit: 10 files max
  • Size limit: ~100KB total content
  • Clear truncation messages guide users to use individual @file mentions
  • Full folder listing preserved even when content is truncated
  • Tests comprehensive and passing

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] new read_file tool bug

1 participant