openclaw - 💡(How to fix) Fix [Bug]: Distillation pipeline edit race condition causing offset mismatch errors [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#63152Fetched 2026-04-09 07:57:45
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0

Memory distillation pipeline (l1-to-l2 / l2-to-l3) experiences race conditions when concurrently writing session files, causing multiple edit operations to fail with offset mismatch errors.

Error Message

ERROR: [tools] read failed: Offset 105 is beyond end of file (97 lines total) ERROR: edit failed (offset/cursor mismatch)

Root Cause

Additional information

Root cause: Distillation skill uses edit tool for incremental updates. When multiple distillation tasks operate on the same file simultaneously, cursor position does not match actual file content.

Code Example

ERROR: [tools] read failed: Offset 105 is beyond end of file (97 lines total)
ERROR: edit failed (offset/cursor mismatch)

---

[2026-04-08T0X:07:36.016+08:00] ERROR: [tools] read failed: Offset 105 is beyond end of file (97 lines total)
[2026-04-08T0X:07:36.016+08:00] ERROR: edit failed (offset/cursor mismatch)
RAW_BUFFERClick to expand / collapse

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

Memory distillation pipeline (l1-to-l2 / l2-to-l3) experiences race conditions when concurrently writing session files, causing multiple edit operations to fail with offset mismatch errors.

Steps to reproduce

  1. Run multiple distillation tasks concurrently (e.g., via heartbeat-triggered sessions)
  2. Observe errors when multiple tasks operate on the same session file simultaneously

Expected behavior

Concurrent writes should be atomic and should not produce "read offset beyond end" errors.

Actual behavior

ERROR: [tools] read failed: Offset 105 is beyond end of file (97 lines total)
ERROR: edit failed (offset/cursor mismatch)

OpenClaw version

2026.4.5

Operating system

macOS (Gateway Local mode)

Install method

NOT_ENOUGH_INFO

Model

NOT_ENOUGH_INFO

Provider / routing chain

NOT_ENOUGH_INFO

Additional provider/model setup details

Gateway Local mode with Feishu WebSocket channel × 5 accounts

Logs, screenshots, and evidence

[2026-04-08T0X:07:36.016+08:00] ERROR: [tools] read failed: Offset 105 is beyond end of file (97 lines total)
[2026-04-08T0X:07:36.016+08:00] ERROR: edit failed (offset/cursor mismatch)

Impact and severity

Affected: Users with concurrent distillation tasks Severity: Low-Medium (distillation updates may fail silently) Frequency: Occurs when multiple distillation tasks target same file simultaneously Consequence: Distillation pipeline may skip updates or produce inconsistent state

Additional information

Root cause: Distillation skill uses edit tool for incremental updates. When multiple distillation tasks operate on the same file simultaneously, cursor position does not match actual file content.

Suggested fix: Use atomic writes (write) instead of incremental edits (edit) for file updates in distillation pipeline.

extent analysis

TL;DR

Switching to atomic writes instead of incremental edits may resolve the offset mismatch errors caused by concurrent writes in the memory distillation pipeline.

Guidance

  • Identify all instances where the edit tool is used for incremental updates in the distillation pipeline and consider replacing it with atomic writes (write) to prevent cursor position mismatches.
  • Verify that the distillation tasks are properly synchronized to avoid concurrent access to the same session file, which could still cause issues even with atomic writes.
  • Review the error logs to ensure that the offset mismatch errors are the primary cause of the distillation updates failing silently, and that addressing this issue will mitigate the problem.
  • Consider implementing additional logging or monitoring to detect and report any instances where distillation updates fail due to concurrent access, to ensure the fix is effective.

Example

No specific code example can be provided without more context on the implementation details of the distillation pipeline and the edit tool. However, the general approach would involve replacing calls to an edit function with a write function that overwrites the entire file, ensuring that each write operation is atomic.

Notes

The effectiveness of this fix assumes that the primary issue is indeed the non-atomic nature of the edit operations. If other factors contribute to the offset mismatch errors, additional fixes may be necessary. Furthermore, the impact of switching to atomic writes on performance and data consistency should be evaluated.

Recommendation

Apply workaround: Switch to atomic writes for file updates in the distillation pipeline, as this directly addresses the identified root cause of the issue (non-atomic edits leading to cursor position mismatches) and is likely to mitigate the problem of distillation updates failing silently due to concurrent access.

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

Concurrent writes should be atomic and should not produce "read offset beyond end" errors.

Still need to ship something?

×6

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

Back to top recommendations

TRENDING