Skip to content

Agent edit tool fails with duplicate text error #44804

@1173365477

Description

@1173365477

Bug Description

Agent system code encounters errors when attempting to edit files using the edit tool:

  1. Duplicate text error: When the text to be replaced appears multiple times in a file
  2. 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

  1. Agent attempts to automatically fix or edit a file
  2. The oldText used for matching exists multiple times in the file (e.g., multiple --- separators)
  3. edit tool rejects due to non-unique match
  4. Subsequent retry fails with missing oldText parameter

Expected Behavior

Agent code should:

  1. Use more specific context to uniquely identify text for replacement
  2. Or fall back to write tool to overwrite entire file
  3. 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

  1. Use larger context blocks (more lines) to ensure uniqueness
  2. Add line number hints to edit tool
  3. Fallback to write tool when edit fails
  4. Validate oldText parameter before calling edit

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions