openclaw - ✅(Solved) Fix [Bug]: Edit tool returns false positive "failed" error when edit actually succeeds [1 pull requests, 2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#49363Fetched 2026-04-08 00:55:59
View on GitHub
Comments
2
Participants
2
Timeline
18
Reactions
0
Author
Timeline (top)
referenced ×8commented ×2cross-referenced ×2labeled ×2

Edit tool reports "failed" error but the file was actually edited successfully - causes user confusion

Error Message

Edit tool reports "failed" error but the file was actually edited successfully - causes user confusion 3. Tool returns error: "Edit failed" with message about no changes Edit tool should return success when file is actually modified, or provide accurate error messages Edit tool returns "⚠️ Edit: in ~/.openclaw/workspace/memory/index.md (282 chars) failed" but file was actually modified successfully - false positive error

Root Cause

Edit tool reports "failed" error but the file was actually edited successfully - causes user confusion

Fix Action

Fixed

PR fix notes

PR #49386: fix: normalize line endings in edit tool recovery to prevent false-positive failures

Description (problem / solution / changelog)

Summary

Fixes #49363 — Edit tool returns false positive "failed" even when the edit actually succeeds.

Root Cause

wrapHostEditToolWithPostWriteRecovery in pi-tools.host-edit.ts checks content.includes(newText) to verify the edit was applied. When the file has CRLF line endings but tool params use LF (common on cross-platform setups), the raw includes() check fails and the tool incorrectly reports failure.

Fix

Added normalizeToLF() helper that converts \r\n and \r to \n before comparing file content with tool params. Both content, newText, and oldText are normalized before the .includes() checks.

Testing

Added reproduction test: CRLF file + LF newText → fails before fix, passes after. All existing recovery tests continue to pass.

AI Disclosure

  • Mark as AI-assisted in the PR title or description
  • Note the degree of testing: fully tested — bug reproduced, fix verified, all tests pass
  • Confirm I understand what the code does
  • Resolve or reply to bot review conversations after addressing them

This PR was authored with AI assistance (Claude/OpenClaw agent). The fix was code-reviewed, tested against the old behavior (confirmed regression), and verified with passing CI.

Changed files

  • .devcontainer/devcontainer.json (added, +10/-0)
  • src/agents/pi-tools.host-edit.ts (modified, +12/-2)
  • src/agents/pi-tools.read.host-edit-recovery.test.ts (modified, +33/-0)
RAW_BUFFERClick to expand / collapse

Bug type

Regression (worked before, now fails)

Summary

Edit tool reports "failed" error but the file was actually edited successfully - causes user confusion

Steps to reproduce

  1. Use edit tool to modify a file
  2. The edit tool actually succeeds (file is modified)
  3. Tool returns error: "Edit failed" with message about no changes
  4. User is confused - file shows edit worked but tool reports failure

Expected behavior

Edit tool should return success when file is actually modified, or provide accurate error messages

Actual behavior

Edit tool returns "⚠️ Edit: in ~/.openclaw/workspace/memory/index.md (282 chars) failed" but file was actually modified successfully - false positive error

OpenClaw version

2026.3.13 (61d171a)

Operating system

macOS 13.7 (Darwin 22.6.0)

Install method

No response

Model

minimax/MiniMax-M2.5

Provider / routing chain

openclaw gateway -> minimax

Config file / key location

No response

Additional provider/model setup details

No response

Logs, screenshots, and evidence

Impact and severity

No response

Additional information

No response

extent analysis

Fix Plan

The fix involves modifying the edit tool's success criteria to accurately reflect file modifications.

  • Update the edit tool to check for actual file changes after modification attempts.
  • Modify the error handling to provide accurate messages based on the outcome of the file modification.

Example Code

def edit_file(file_path, new_content):
    # Attempt to modify the file
    try:
        with open(file_path, 'w') as file:
            file.write(new_content)
        # Check if the file was actually modified
        with open(file_path, 'r') as file:
            modified_content = file.read()
        if modified_content == new_content:
            return True, "Edit successful"
        else:
            return False, "No changes detected"
    except Exception as e:
        return False, f"Edit failed: {str(e)}"

# Example usage:
file_path = "~/.openclaw/workspace/memory/index.md"
new_content = "Example new content"
success, message = edit_file(file_path, new_content)
if success:
    print("Edit tool:", "✅ Edit: in", file_path, "succeeded")
else:
    print("Edit tool:", "⚠️ Edit: in", file_path, "failed", "(", message, ")")

Verification

To verify the fix, use the edit tool to modify a file and check the returned message. If the file is modified successfully, the tool should return a success message. If the file is not modified, the tool should return an accurate error message.

Extra Tips

  • Ensure the edit tool has the necessary permissions to modify files.
  • Consider adding additional logging to track file modifications and errors for debugging purposes.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

Edit tool should return success when file is actually modified, or provide accurate error messages

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix [Bug]: Edit tool returns false positive "failed" error when edit actually succeeds [1 pull requests, 2 comments, 2 participants]