openclaw - 💡(How to fix) Fix [Bug] edit tool returns success but file is not actually modified - causes infinite loop [1 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#72847Fetched 2026-04-28 06:31:30
View on GitHub
Comments
1
Participants
2
Timeline
1
Reactions
0
Timeline (top)
commented ×1

Error Message

  • Dev.to article: \The Default Timeout Behavior Silently Succeeds\ - OpenClaw marks tasks as complete if the last action didn't return an explicit error

Root Cause

  1. The \edit\ tool returns a success status code even when the replacement did not actually change the file content
  2. The agent trusts the tool's status code and does not verify the result by re-reading the file
  3. When \oldText\ matches a static/footer portion of the file that repeats, the same edit is attempted repeatedly

Fix Action

Fix / Workaround

Workaround (Current)

The community workaround is:

  1. Always
    ead\ the file before calling \edit\ to confirm current content
  2. Always
    ead\ the file immediately after \edit\ to verify changes
  3. Use \write\ for large content replacements instead of \edit\
  4. Switch strategy after 2 consecutive edit failures
RAW_BUFFERClick to expand / collapse

Bug Description

The \edit\ tool reports success when it should, but the file content is not actually modified. This causes the agent to enter an infinite loop: it keeps calling \edit\ with the same \oldText\ (which matches an outdated footer), gets a success response, but the file remains unchanged. On the next read, the content is still the old version, leading to another failed edit attempt.

Root Cause

  1. The \edit\ tool returns a success status code even when the replacement did not actually change the file content
  2. The agent trusts the tool's status code and does not verify the result by re-reading the file
  3. When \oldText\ matches a static/footer portion of the file that repeats, the same edit is attempted repeatedly

Evidence from Community

  • GitHub Issue #18575: \edit\ tool reports success but changes do not persist when reading back the file
  • GitHub Issue #45770: \edit\ tool reports 'failed' but file is actually modified (reverse problem)
  • Dev.to article: \The Default Timeout Behavior Silently Succeeds\ - OpenClaw marks tasks as complete if the last action didn't return an explicit error

Steps to Reproduce

  1. File has a repeating footer pattern (e.g., a timestamp/version line at the bottom)
  2. Agent calls \edit\ with \oldText\ matching the footer
  3. Tool returns success
  4. Agent reads file - content is unchanged
  5. Agent calls \edit\ again with the same \oldText\
  6. Loop continues indefinitely

Reproduced Case (2026-04-27)

  • User requested adding a safety protocol to AGENTS.md
  • Agent used \edit\ to append content
  • \oldText\ matched the file footer repeatedly
  • 20+ consecutive \edit\ calls, all reporting success
  • File content was corrupted/lost
  • Final resolution: used \write\ to completely rewrite the file

Expected Behavior

The \edit\ tool should:

  1. Return the number of lines changed (0 if no change was made)
  2. Or at minimum, include the actual diff in the response
  3. Or automatically verify the file after editing

Workaround (Current)

The community workaround is:

  1. Always
    ead\ the file before calling \edit\ to confirm current content
  2. Always
    ead\ the file immediately after \edit\ to verify changes
  3. Use \write\ for large content replacements instead of \edit\
  4. Switch strategy after 2 consecutive edit failures

Proposed Fixes

Priority 1 (Agent-side): The agent should always verify edit results by re-reading the file. This is a behavioral fix we can implement in AGENTS.md.

Priority 2 (Tool-side): The \edit\ tool should return a diff or change count in its response, so the agent can detect when no change was made.

Priority 3 (System-side): Add automatic retry-with-context-reset for edit failures, and a hard cap on consecutive identical tool calls.

Environment

  • OS: Windows_NT 10.0.26100 (x64)
  • Node.js: v25.8.0
  • Model: qwen/35B
  • Channel: feishu

Severity

High - This bug causes agents to hang indefinitely, wasting tokens and creating a poor user experience. Multiple users have reported this issue.

extent analysis

TL;DR

The agent should verify the edit results by re-reading the file after calling the edit tool to prevent infinite loops.

Guidance

  • Implement a behavioral fix in AGENTS.md to always verify edit results by re-reading the file after calling edit.
  • Consider using write for large content replacements instead of edit to avoid potential issues.
  • Review the edit tool's response to ensure it returns a diff or change count, allowing the agent to detect when no change was made.
  • Evaluate the need for a hard cap on consecutive identical tool calls to prevent agent hangs.

Example

No code snippet is provided as the issue does not contain specific code references.

Notes

The proposed fixes prioritize agent-side changes, which can be implemented immediately, while tool-side and system-side changes may require additional development and testing.

Recommendation

Apply the workaround by always re-reading the file before and after calling edit to verify changes, as this is a straightforward and effective solution to prevent infinite loops and ensure data integrity.

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…

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 - 💡(How to fix) Fix [Bug] edit tool returns success but file is not actually modified - causes infinite loop [1 comments, 2 participants]