Fix: Handle truncated write_to_file responses for large files (>7k lines) #6248
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related GitHub Issue
Closes: #6247
Roo Code Task Context (Optional)
Description
This PR fixes a critical issue where the
write_to_filetool silently truncates content when writing large files (>7000 lines). The AI assistant would report success despite the file being incomplete due to hitting output token limits (~8000-8192 tokens).Key implementation details:
line_countparameter is missingapply_diffor chunkingThe fix ensures that users are properly notified when file content might be truncated, preventing silent data loss.
Test Procedure
How I tested:
src/core/tools/__tests__/writeToFileTool.spec.tscovering:cd src && npx vitest runHow reviewers can verify:
cd src && npx vitest run core/tools/__tests__/writeToFileTool.spec.tswriteToFileTool.tsPre-Submission Checklist
Screenshots / Videos
Not applicable - this is a backend fix for tool behavior.
Documentation Updates
The error messages themselves provide clear guidance to users when truncation is detected.
Additional Notes
This fix addresses a critical data loss issue that affects users working with large files. The 7000-line threshold was chosen based on typical token limits and file size patterns observed in the issue report.
Get in Touch
Important
Fixes truncation issue in
write_to_filetool for large files by adding detection and validation mechanisms.writeToFileTool.tsand checks for truncation ifline_countis missing.apply_diffor chunking when truncation is detected.writeToFileTool.spec.tsfor large file detection, line count mismatch, and error messaging.This description was created by
for 9601be0. You can customize this summary. It will automatically update as commits are pushed.