-
-
Notifications
You must be signed in to change notification settings - Fork 69.5k
Agent edit tool fails with duplicate text error #44804
Copy link
Copy link
Open
Description
Bug Description
Agent system code encounters errors when attempting to edit files using the edit tool:
- Duplicate text error: When the text to be replaced appears multiple times in a file
- Missing parameter error: oldText parameter becomes empty/null after the first error
Error Messages
edit failed: Found 2 occurrences of the text in /root/.openclaw/workspace/.learnings/ERRORS.md.
The text must be unique. Please provide more context to make it unique.
edit failed: Missing required parameter: oldText (oldText or old_string).
Steps to Reproduce
- Agent attempts to automatically fix or edit a file
- The oldText used for matching exists multiple times in the file (e.g., multiple
---separators) - edit tool rejects due to non-unique match
- Subsequent retry fails with missing oldText parameter
Expected Behavior
Agent code should:
- Use more specific context to uniquely identify text for replacement
- Or fall back to write tool to overwrite entire file
- Ensure oldText parameter is always provided
Environment
- OpenClaw version: 2026.3.11 (29dc654)
- OS: Armbian 26.2.0 (Debian Trixie)
- Architecture: ARM64
Additional Context
This appears to be in the agent system code that handles automatic fixes and file edits, not in user-controlled skills.
Possible Solutions
- Use larger context blocks (more lines) to ensure uniqueness
- Add line number hints to edit tool
- Fallback to write tool when edit fails
- Validate oldText parameter before calling edit
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Fields
Give feedbackNo fields configured for issues without a type.