Skip to content

fix: prevent context exhaustion when reading large files #6072

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 3 commits 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 the codebase condensing feature fails when Roo Code accidentally tries to read very large source files (>5000 lines), causing the context window to be exhausted.

Changes

  • Added file size check (10MB limit) to reject extremely large files before reading
  • Added configurable largeFileLineThreshold setting (default: 5000 lines)
  • When maxReadFileLine is -1 (no limit) and a file exceeds the threshold, it's automatically truncated to the first 1000 lines
  • Added the new configuration to the global settings schema with proper TypeScript types
  • Added comprehensive tests for the new functionality

How it works

  1. Before reading any file, the tool now checks if it exceeds 10MB and rejects it with a clear error message
  2. When maxReadFileLine is set to -1 (unlimited), the tool checks if the file exceeds largeFileLineThreshold
  3. If it does, the file is automatically truncated to 1000 lines to prevent context exhaustion
  4. This prevents the "Failed to condense" errors and task memory loss reported in the issue

Testing

  • Added unit tests for file size rejection
  • Added tests for large file threshold behavior
  • All existing tests pass

Fixes #6069


Important

Adds file size and line threshold checks to prevent context exhaustion when reading large files, with new settings and tests.

  • Behavior:
    • Adds file size check (10MB limit) in readFileTool.ts to reject large files before reading.
    • Introduces largeFileLineThreshold setting (default: 5000 lines) in global-settings.ts.
    • Truncates files to 1000 lines if maxReadFileLine is -1 and file exceeds threshold.
  • Configuration:
    • Adds largeFileLineThreshold to global settings schema in global-settings.ts.
    • Updates webviewMessageHandler.ts to handle largeFileLineThreshold messages.
  • Testing:
    • Adds unit tests in readFileTool.spec.ts for file size rejection and line threshold behavior.
    • Ensures all existing tests pass.

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

- Add file size check to reject files larger than 10MB
- Add largeFileLineThreshold setting (default 5000 lines)
- When maxReadFileLine is -1 and file exceeds threshold, automatically truncate to first 1000 lines
- Add configuration options for the threshold
- Add tests for the new functionality

This prevents the 'Failed to condense' error when Roo Code accidentally tries to read very large files, which was causing context window exhaustion and loss of task memory.

Fixes #6069
@roomote roomote bot requested review from mrubens, cte and jr as code owners July 22, 2025 17:49
@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