-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: prevent dump of an entire file into the context on user edit #3654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Previously, each tool file contained duplicate code for formatting file write responses and conditionally sending user_feedback_diff messages. This led to inconsistent implementations and made changes difficult to maintain. This refactoring centralizes the response formatting and messaging logic in the DiffViewProvider class, which now: - Stores results from saveChanges() in class properties - Only sends user_feedback_diff when user edits exist - Configures XMLBuilder with no indentation for cleaner output Tool files now make a single method call instead of duplicating logic. Fixes: #3647 Signed-off-by: Eric Wheeler <[email protected]>
|
Make the 'If the user's edits have addressed part of the task...' message conditional based on whether there are actual user edits. This prevents showing irrelevant guidance when no user edits were made to the file. Signed-off-by: Eric Wheeler <[email protected]>
|
given https://www.reddit.com/r/RooCode/comments/1kn6xwj/pruning_ai_turn_from_context/ : I think this should be manually tested for regression and then merged quickly. This is intended to be a simple refactor that centralizes file modification responses to the model and removes I have had the model test each tool and various scenarios along with testing user modifications and I have not found any issues with it. |
|
@samhvw8 can you set your multi-file PR to "draft" until this lands? |
|
@KJ7LNW i will put multi-write pr into draft mode, i think multi-read not related to this |
true |
|
This PR should merge as preparatory standardization for #3342, #3055, #1899, #2955 and it fixes #3647:
Thus, If we can push this out soon, then it will simplify development on other fronts. As you can see it substantially reduces the footprint of each tool that modifies files by replacing common call paths with a single function call: ]$ git diff origin/main... --stat
src/core/tools/applyDiffTool.ts | 36 ++++------------
src/core/tools/insertContentTool.ts | 35 ++++------------
src/core/tools/searchAndReplaceTool.ts | 35 ++++------------
src/core/tools/writeToFileTool.ts | 32 +++------------
src/integrations/editor/DiffViewProvider.ts | 86 ++++++++++++++++++++++++++++++++++++++-
5 files changed, 115 insertions(+), 109 deletions(-) |
daniel-lxs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @KJ7LNW, I really like this fix. I think it's crucial to add this to Roo. Everything looks pretty good, I just have a couple of questions. Looking forward to helping get this merged!
Thank you!
| * | ||
| * @param cwd Current working directory for path resolution | ||
| * @param isNewFile Whether this is a new file or an existing file being modified | ||
| * @returns Formatted message and say object for UI feedback |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have an unit test for this new method?
| operation: isNewFile ? "created" : "modified", | ||
| user_edits: this.userEdits ? this.userEdits : undefined, | ||
| problems: this.newProblemsMessage || undefined, | ||
| notice: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious about the use of an array of i tags here for the notice. Is there a specific reason for structuring it this way instead of just using the content directly within <notice> tags? Just wondering if the i tags serve a particular purpose in how the model processes this information, or if we could simplify this structure.
mrubens
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the cleanup here! This has been waiting for a while, so I think it’s ok to discuss the remaining comments as a follow up.
|
Er, a test is failing in main so I'm going to revert this to be safe. |
understood. I will rebase and see if we can figure out why |
Problem fixed by this PR
This pull request fixes the problem of dumping an entire file into the context under the following condition:
After the user clicks save,
<final_file_content>[entire file]</final_file_content>is dumped into the conversation even for a one-line change, which is a severe problem because it:Fixes: #3647
The fix
The change by the user shown in Step-3, above, is provided to the model in the existing implementation using the standard
diffformat, so it understands the change that was made. All we are doing here is omitting<final_file_content>[entire file]</final_file_content>to prevent context bloat and maintain model focus.Because this issue exists in all tools that modify files, this pull request is also a refactor to standardize the tool response for file modifications across
write_to_file,apply_diff,search_and_replace, andinsert_content:History
The
final_file_contentfeature was introduced by Saoud Rizwan and copy-pasted across all file modification tools as new tools were added.Important
Refactored to centralize response formatting and messaging in
DiffViewProvider, addingpushToolWriteResultfor XML response and user feedback, affecting multiple tool files.DiffViewProvider.pushToolWriteResultmethod toDiffViewProviderfor XML response formatting and user feedback messaging.saveChangesin class properties.applyDiffTool.ts,insertContentTool.ts,searchAndReplaceTool.ts,writeToFileTool.ts) now callpushToolWriteResultinstead of duplicating logic.user_feedback_diffonly when user edits exist.XMLBuilderwith no indentation for cleaner output.addLineNumbersimport fromapplyDiffTool.tsandwriteToFileTool.ts.This description was created by
for a119ca4. You can customize this summary. It will automatically update as commits are pushed.