openclaw - 💡(How to fix) Fix Compaction flush rewrites entire file, breaking concurrent Edit tool operations [1 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#53712Fetched 2026-04-08 01:24:29
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Author
Participants

When the memory flush fires (pre-compaction), it rewrites workspace files (e.g., NOW.md) in their entirety — even sections that did not change. This causes the Edit tool's exact-match requirement to fail on unchanged sections, triggering visible ⚠️ Edit failed notifications to the user.

The bot recovers by re-reading the file and retrying, but the user-facing error notification is alarming and creates unnecessary concern, especially for non-technical users.

Error Message

The bot recovers by re-reading the file and retrying, but the user-facing error notification is alarming and creates unnecessary concern, especially for non-technical users.

  • User-facing: Alarming error notifications for what is actually a benign retry situation

Root Cause

  1. Bot reads NOW.md and prepares an Edit targeting a specific section
  2. Compaction memory flush fires between the read and the edit
  3. Flush rewrites the entire file — even unchanged sections may have different whitespace (trailing spaces, newline differences, markdown re-serialization)
  4. Edit exact-match fails because the byte-level content shifted
  5. User sees ⚠️ Edit failed notification

Fix Action

Fix / Workaround

Option A: Patch-based flush (preferred)

Flush reads the existing file, diffs its changes, and patches only modified sections — preserving byte-for-byte content of unchanged regions.

RAW_BUFFERClick to expand / collapse

Summary

When the memory flush fires (pre-compaction), it rewrites workspace files (e.g., NOW.md) in their entirety — even sections that did not change. This causes the Edit tool's exact-match requirement to fail on unchanged sections, triggering visible ⚠️ Edit failed notifications to the user.

The bot recovers by re-reading the file and retrying, but the user-facing error notification is alarming and creates unnecessary concern, especially for non-technical users.

Reproduction

  1. Bot reads NOW.md and prepares an Edit targeting a specific section
  2. Compaction memory flush fires between the read and the edit
  3. Flush rewrites the entire file — even unchanged sections may have different whitespace (trailing spaces, newline differences, markdown re-serialization)
  4. Edit exact-match fails because the byte-level content shifted
  5. User sees ⚠️ Edit failed notification

This happens multiple times per session for bots that actively maintain NOW.md or similar workspace files.

Impact

  • User-facing: Alarming error notifications for what is actually a benign retry situation
  • Bot DX: Wasted tool calls on failures that require re-read + retry
  • Frequency: Multiple times per session, especially in long conversations approaching compaction threshold

Suggested fixes

Option A: Patch-based flush (preferred)

Flush reads the existing file, diffs its changes, and patches only modified sections — preserving byte-for-byte content of unchanged regions.

Option B: Section-aware flush

Flush identifies markdown sections (by headers) and only rewrites sections it actually modified.

Option C: Suppress user notification on retryable failures

If the Edit tool fails but the bot retries successfully, don't surface the initial failure to the user. This is a presentation-layer fix that doesn't address the root cause but eliminates the UX problem.

Environment

  • OpenClaw 2026.3.23-2 (7ffe7e4)
  • macOS / Linux fleet
  • Observed on multiple bots (Sam, Vesper, fleet-wide)

extent analysis

Fix Plan

To address the issue, we will implement Option A: Patch-based flush. This approach involves modifying the flush mechanism to read the existing file, diff its changes, and patch only modified sections.

Step-by-Step Solution

  1. Read the existing file: Before flushing, read the current state of the file (NOW.md) to determine the original content.
  2. Diff changes: Compare the original content with the new content to identify the modified sections.
  3. Patch modified sections: Update only the modified sections in the file, preserving the byte-for-byte content of unchanged regions.

Example Code (Python)

import difflib

def patch_based_flush(original_file, new_content):
    # Read the original file content
    with open(original_file, 'r') as file:
        original_content = file.read()

    # Diff the changes
    diff = difflib.Differ()
    differences = diff.compare(original_content.splitlines(), new_content.splitlines())

    # Patch the modified sections
    patched_content = []
    for line in differences:
        if line.startswith('+ '):
            patched_content.append(line[2:])
        elif line.startswith('? '):
            continue
        else:
            patched_content.append(line)

    # Write the patched content to the file
    with open(original_file, 'w') as file:
        file.write('\n'.join(patched_content))

# Example usage
original_file = 'NOW.md'
new_content = 'New content for the file'
patch_based_flush(original_file, new_content)

Verification

To verify the fix, test the following scenarios:

  • Edit a section in NOW.md and trigger a memory flush.
  • Verify that only the modified section is updated in the file.
  • Check that the Edit tool's exact-match requirement passes, and no ⚠️ Edit failed notification is displayed.

Extra Tips

  • Ensure that the diffing algorithm used is efficient and accurate to minimize performance overhead.
  • Consider implementing a retry mechanism for cases where the patch-based flush fails to update the file correctly.

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 Compaction flush rewrites entire file, breaking concurrent Edit tool operations [1 participants]