Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Jul 26, 2025

Related GitHub Issue

Closes: #6247

Roo Code Task Context (Optional)

Description

This PR fixes a critical issue where the write_to_file tool 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:

  • Added detection for files >7000 lines when line_count parameter is missing
  • Added validation to compare actual vs predicted line count with 10% tolerance
  • Provides clear error messages when truncation is detected, suggesting alternatives like apply_diff or chunking
  • Added comprehensive test coverage for large file scenarios

The fix ensures that users are properly notified when file content might be truncated, preventing silent data loss.

Test Procedure

How I tested:

  1. Added unit tests in src/core/tools/__tests__/writeToFileTool.spec.ts covering:
    • Detection of large files (>7000 lines) without line_count
    • Line count mismatch detection with 10% tolerance
    • Proper error messages and suggestions
  2. Ran all existing tests to ensure no regression: cd src && npx vitest run
  3. All tests pass successfully

How reviewers can verify:

  1. Run the test suite: cd src && npx vitest run core/tools/__tests__/writeToFileTool.spec.ts
  2. Review the new test cases that simulate large file scenarios
  3. Check the error handling logic in writeToFileTool.ts

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

Not applicable - this is a backend fix for tool behavior.

Documentation Updates

  • No documentation updates are required.

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_file tool for large files by adding detection and validation mechanisms.

  • Behavior:
    • Detects files >7000 lines in writeToFileTool.ts and checks for truncation if line_count is missing.
    • Validates line count with 10% tolerance and provides error messages for mismatches.
    • Suggests alternatives like apply_diff or chunking when truncation is detected.
  • Tests:
    • Added tests in writeToFileTool.spec.ts for large file detection, line count mismatch, and error messaging.
    • Tests cover scenarios with exact line count matches and small differences within tolerance.
  • Misc:
    • No changes to existing functionality outside of truncation handling.

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

…iles

- Add detection for files >7000 lines when line_count is missing
- Add validation to compare actual vs predicted line count with 10% tolerance
- Provide clear error messages when truncation is detected
- Add comprehensive tests for large file handling

Fixes #6247
@roomote roomote bot requested review from cte, jr and mrubens as code owners July 26, 2025 14:08
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Jul 26, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jul 26, 2025
@daniel-lxs
Copy link
Member

Closing as the issue is not properly scoped

@daniel-lxs daniel-lxs closed this Jul 29, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jul 29, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Jul 29, 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

Archived in project

Development

Successfully merging this pull request may close these issues.

write or replace file does not work sometimes.

4 participants