-
Notifications
You must be signed in to change notification settings - Fork 2k
Agent overwrites files using write_file without reading existing content, leading to data loss. #2499
Copy link
Copy link
Open
Labels
category/toolsTool integration and executionTool integration and executiontype/bugSomething isn't working as expectedSomething isn't working as expected
Description
What happened?
Summary:
During file editing (especially for .md or large source files), the agent frequently calls write_file to
overwrite the entire file with incorrect or truncated content, skipping the necessary read_file step.
Actual Behavior:
Instead of performing surgical edits, the agent "hallucinates" the current content of a file and writes a new
version over it. This often results in the loss of existing code, documentation, or formatting that wasn't part
of the specific change request.
What did you expect to happen?
Expected Behavior:
The agent should follow a strict "Read-Plan-Act" cycle:
- Read: Must read the target file (or relevant sections) to understand the current state.
- Plan: Propose the change based on actual content.
- Act: Use granular replacement tools (like a string-replace tool) instead of full-file write_file whenever
possible.
Suggested Improvement:
- Introduce a more granular replace tool (similar to Gemini CLI's implementation) that requires matching an
old_string to ensure the agent has actually read and understood the target area. - Add a guardrail in the system prompt: "Never overwrite a file without reading its current content first."
Client information
Client Information
Run qwen to enter the interactive CLI, then run the /about command.
$ qwen /about
# paste output hereLogin information
No response
Anything else we need to know?
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
category/toolsTool integration and executionTool integration and executiontype/bugSomething isn't working as expectedSomething isn't working as expected