Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Dec 7, 2025

Adds token budget validation to simpleReadFileTool() to prevent context window overflow errors, mirroring the behavior already implemented in ReadFileTool.

Changes

  • Import validateFileTokenBudget and truncateFileContent helpers from fileTokenBudget.ts
  • Import getModelMaxOutputTokens and ANTHROPIC_DEFAULT_MAX_TOKENS for context calculation
  • Add token budget validation in the normal file read path (after maxReadFileLine checks)
  • Truncate file content if it exceeds available context budget
  • Display appropriate notice when truncation occurs

Impact

This fix addresses context overflow issues in models that use simpleReadFileTool (particularly Grok), preventing "context overflow" errors like those reported in the Sentry issues.

Related Issues


View task on Roo Code Cloud

- Import validateFileTokenBudget and truncateFileContent helpers
- Import getModelMaxOutputTokens and ANTHROPIC_DEFAULT_MAX_TOKENS
- Add token budget validation in normal file read path
- Truncate file content if it exceeds available context budget
- Display appropriate notice when truncation occurs
- Mirrors the behavior of ReadFileTool for consistency

Fixes context overflow issues in Grok and other models using simpleReadFileTool
@roomote
Copy link
Contributor Author

roomote bot commented Dec 7, 2025

Rooviewer Clock   See task on Roo Cloud

Test coverage added successfully. All 15 tests pass, covering token budget validation for files exceeding budget, within budget, preview mode, and model-specific context calculations.

  • Add test coverage for token budget validation in simpleReadFileTool (files exceeding budget, within budget, preview mode, and model-specific context calculations)
Previous reviews

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

Comment on lines +266 to +271
// Validate if file content fits within token budget
const budgetResult = await validateFileTokenBudget(
fullPath,
contextWindow - maxOutputTokens,
contextTokens || 0,
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The new token budget validation logic lacks test coverage. While the helper functions in fileTokenBudget.ts are tested, there are no tests verifying that simpleReadFileTool correctly integrates this functionality. Tests should cover: (1) files exceeding the token budget that require truncation, (2) files within budget limits, (3) large files triggering preview mode, and (4) the token budget calculation using model-specific context windows. This is particularly important given the PR addresses context overflow errors in production (Sentry issue 7079272598).

Fix it with Roo Code or mention @roomote and request a fix.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@roomote add the test coverage please

Copy link
Contributor Author

@roomote roomote bot Dec 8, 2025

Choose a reason for hiding this comment

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

Fixaroo Clock   See task on Roo Cloud

Added test coverage for simpleReadFileTool token budget validation. All local checks passed.

View commit | Revert commit

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Dec 7, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Dec 8, 2025
- Add tests for files within budget limits (no truncation)
- Add tests for files exceeding token budget (require truncation)
- Add tests for large files triggering preview mode
- Add tests for model-specific context window calculations
- Add tests for line count tracking with truncation
- Add tests for integration with existing maxReadFileLine behavior
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. lgtm This PR has been approved by a maintainer

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

4 participants