Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.

feat: improve context budget truncation notice with total lines and continuation example - #10249

Closed
ghost wants to merge 2 commits into
mainfrom
feature/improve-context-budget-truncation-notice
Closed

feat: improve context budget truncation notice with total lines and continuation example#10249
ghost wants to merge 2 commits into
mainfrom
feature/improve-context-budget-truncation-notice

Conversation

@ghost

@ghost ghost commented Dec 21, 2025

Copy link
Copy Markdown

This PR attempts to address Issue #10239 (specifically the comment about semantic truncation notifications).

Problem

When files are truncated due to context budget limits, the current truncation notice says:

File truncated: showing X lines (Y tokens) due to context budget. Use line_range to read specific sections.

This notice does not include:

  1. The total number of lines in the file
  2. The next line number to continue from
  3. A concrete example of the syntax to use

This can cause models to be confused about why they received fewer lines than expected, leading to re-read attempts.

Solution

Improved the truncation notice to include all relevant information:

Before:

File truncated: showing 300 lines (1500 tokens) due to context budget. Use line_range to read specific sections.

After:

File truncated at line 300 of 2000 total lines due to context budget (1500 tokens used). To continue reading, use the read_file tool again with line_range starting at line 301 (e.g., <line_range>301-800</line_range>)

Changes

  • src/core/tools/ReadFileTool.ts - Updated the context budget truncation notice to include:
    • Total lines in the file
    • The next line number to continue from
    • A concrete example of the line_range syntax

Testing

  • All 44 existing read_file tests pass
  • TypeScript compilation passes
  • ESLint passes

Feedback and guidance are welcome!

…ontinuation example

When files are truncated due to context budget limits, the truncation notice now includes:
- Total number of lines in the file
- The next line number to continue from
- A concrete example of the line_range syntax

This helps models understand why they received fewer lines than expected and how to continue reading.

Addresses Issue #10239
@ghost

ghost commented Dec 21, 2025

Copy link
Copy Markdown
Author

Rooviewer Clock   See task on Roo Cloud

Reviewed the latest commit addressing @pwilkin's feedback. No issues found.

The new commit correctly updates both truncation notices with concrete line_range syntax examples:

  • maxReadFileLine === 0 case: Now shows "Showing code definitions only" with example starting from line 1
  • maxReadFileLine > 0 case: Adds nextLine calculation for continuation example
  • Tests updated to match new notice formats
Previous reviews

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

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Dec 21, 2025
@pwilkin

pwilkin commented Dec 21, 2025

Copy link
Copy Markdown
Contributor

@roomote You missed the fragment in ReadFileTool:

					if (maxReadFileLine === 0) {
						try {
							const defResult = await parseSourceCodeDefinitionsForFile(
								fullPath,
								task.rooIgnoreController,
							)
							if (defResult) {
								const notice = `Showing only ${maxReadFileLine} of ${totalLines} total lines. Use line_range if you need to read more lines`
								updateFileResult(relPath, {
									xmlContent: `<file><path>${relPath}</path>\n<list_code_definition_names>${defResult}</list_code_definition_names>\n<notice>${notice}</notice>\n</file>`,
									nativeContent: `File: ${relPath}\nCode Definitions:\n${defResult}\n\nNote: ${notice}`,
								})
							}
						} catch (error) {
							if (error instanceof Error && error.message.startsWith("Unsupported language:")) {
								console.warn(`[read_file] Warning: ${error.message}`)
							} else {
								console.error(
									`[read_file] Unhandled error: ${error instanceof Error ? error.message : String(error)}`,
								)
							}
						}
						continue
					}

that truncates due to end of definition.

@ghost

ghost commented Dec 21, 2025

Copy link
Copy Markdown
Author

Fixaroo Clock   See task on Roo Cloud

Fixed the reported issues. All local checks passed.

View commit | Revert commit

@github-project-automation github-project-automation Bot moved this from New to Done in Roo Code Roadmap Jan 7, 2026
@github-project-automation github-project-automation Bot moved this from Triage to Done in Roo Code Roadmap Jan 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels.

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants