Skip to content

Roo dumps entire file into the context when a user edits during apply_diff before clicking saveย #3647

@KJ7LNW

Description

@KJ7LNW

Problem

Roo unexpectedly dumps an entire file into the context under the following condition:

  1. auto approve is turned off for writes
  2. the model proposes a file modification
  3. the user modifies the file before clicking save
  4. 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:

  1. distracts the model from the focus (especially with large files)
  2. bloats context
  3. 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.

  1. write_to_file: Commit cbf942e (Oct 18, 2024) by Saoud Rizwan
  2. apply_diff: Commit c0b070e, PR Improvements to apply_diffย #52 (Dec 8, 2024) by @mrubens
  3. 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:

  1. 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.

  2. 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
  3. 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.

  4. Inconsistent Formatting: Some implementations use line numbers (apply_diff, write_to_file) while others don't (search_and_replace, insert_content).

Proposed Solution

  1. Create a unified function to format tool response messages
  2. Show only the differences rather than the entire file content
  3. Include structured messages that explicitly tell the model not to read the file again
  4. 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

No one assigned

    Labels

    Issue - Needs ApprovalReady to move forward, but waiting on maintainer or team sign-off.

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions