-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
Problem
Roo unexpectedly dumps an entire file into the context under the following condition:
- auto approve is turned off for writes
- the model proposes a file modification
- the user modifies the file before clicking save
- user clicks save
After the user clicks save, <final_file_content>[entire file]</final_file_content> is dumped into the conversation even for a single letter change, which is a severe problem because it:
- distracts the model from the focus (especially with large files)
- bloats context
- increases costs
Background
Others have noticed this problem as well in other contexts:
Llm fall pretty quickly into local minimum when they get fed their own responses in a multiturn generation, such as those of coding agents [from here]
Thus, final_file_content must go because it impedes model progress.
History
The final_file_content feature was introduced by Saoud Rizwan and copy-pasted across all file modification tools as new tools were added.
- write_to_file: Commit cbf942e (Oct 18, 2024) by Saoud Rizwan
- apply_diff: Commit c0b070e, PR Improvements to apply_diffย #52 (Dec 8, 2024) by @mrubens
- search_and_replace and insert_content: Commit 2c97b59 (Jan 21, 2025) by @mrubens
Other related implementation problems
The current implementation of final_file_content has several issues:
-
Context Waste: It displays the entire file content even when only a small change was made, which wastes valuable context space. This is particularly problematic for large files with minimal changes.
-
Duplicate Code: The implementation is duplicated across multiple tool files:
- src/core/tools/applyDiffTool.ts:195
- src/core/tools/insertContentTool.ts:161
- src/core/tools/searchAndReplaceTool.ts:242
- src/core/tools/writeToFileTool.ts:233
-
Model Confusion: Showing the entire file content tends to make the model think it should read the file again, which is counterproductive to the feature's purpose.
-
Inconsistent Formatting: Some implementations use line numbers (apply_diff, write_to_file) while others don't (search_and_replace, insert_content).
Proposed Solution
- Create a unified function to format tool response messages
- Show only the differences rather than the entire file content
- Include structured messages that explicitly tell the model not to read the file again
- Standardize the format across all file modification tools
This would save context, keep the model focused, and reduce code duplication while maintaining the benefits of the feature.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status