Skip to content

fix: respect maxReadFileLine setting for file mentions to prevent context exhaustion #6073

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

roomote[bot]
Copy link

@roomote roomote bot commented Jul 22, 2025

Summary

This PR fixes issue #6069 where Roo Code's codebase condensing feature fails when it accidentally tries to read very large source files (>5000 lines), causing a "Failed to condense" error and wiping out the task context.

Problem

When users mention files using @filename syntax, the entire file content was being read without respecting the maxReadFileLine configuration setting. This could exhaust the context window when dealing with large files, particularly problematic in Orchestrator mode.

Solution

  • Modified extractTextFromFile to accept and respect the maxReadFileLine parameter
  • Updated parseMentions and related functions to pass maxReadFileLine through the call chain
  • Modified Task.ts to retrieve maxReadFileLine from state and pass it to processUserContentMentions
  • Files are now truncated with informative messages when they exceed the line limit

Changes

  1. src/integrations/misc/extract-text.ts

    • Added maxReadFileLine parameter to extractTextFromFile function
    • Implemented file truncation logic when files exceed the line limit
    • Added informative truncation message
  2. src/core/mentions/index.ts

    • Updated parseMentions and getFileOrFolderContent to accept and pass maxReadFileLine
    • Modified all calls to extractTextFromFile to include the parameter
  3. src/core/mentions/processUserContentMentions.ts

    • Added maxReadFileLine parameter to function signature
    • Updated all calls to parseMentions to include the parameter
  4. src/core/task/Task.ts

    • Modified to retrieve maxReadFileLine from state
    • Pass the setting to processUserContentMentions
  5. src/integrations/misc/tests/extract-text-large-files.spec.ts

    • Added comprehensive tests for large file handling
    • Tests cover various scenarios including truncation, edge cases, and error handling

Testing

  • Added 12 new unit tests covering all scenarios
  • All existing tests pass
  • Linting and type checking pass

Fixes #6069

…text exhaustion

- Modified extractTextFromFile to accept and respect maxReadFileLine parameter
- Updated parseMentions and related functions to pass maxReadFileLine through the call chain
- Modified Task.ts to retrieve maxReadFileLine from state and pass to processUserContentMentions
- Added comprehensive tests for large file handling
- Files are now truncated with informative messages when they exceed the line limit

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

Codebase condensing feature doesn't work if roo accidently tried to read a very large source file
2 participants