openclaw - 💡(How to fix) Fix [Bug] EPERM fsync on Windows — image_generate + Feishu picture receive both broken in 2026.5.2 [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#77016Fetched 2026-05-04 04:59:24
View on GitHub
Comments
1
Participants
2
Timeline
2
Reactions
2
Timeline (top)
closed ×1commented ×1

Two distinct features fail with the same root cause on Windows after upgrading to 2026.5.2:

  1. image_generate tool — generated images cannot be saved, throwing EPERM: operation not permitted, fsync
  2. Feishu picture receive — inbound images via Feishu channel are not downloaded, also throwing EPERM: operation not permitted, fsync

Both trace back to writeSavedMediaBuffer in the media store opening the temp file with read-only mode "r" before calling handle.sync(), which Windows rejects with EPERM.

Error Message

Error: EPERM: operation not permitted, fsync
  at async fsync (node:internal/fs/promises:842)
  at async fsCall (node:internal/fs/promises:468)
  at async writeSavedMediaBuffer (store-*.js:236)

Root Cause

In src/media/store.ts, writeSavedMediaBuffer opens the staged temp file with read-only mode "r" before calling handle.sync():

// current code (line ~351)
const handle = await fs.open(tempDest, "r");  // read-only fails sync on Windows
try {
    await handle.sync();
} finally {
    await handle.close();
}

On Windows, calling fsync() on a read-only file handle returns EPERM (operation not permitted). Linux/macOS allow this, so the bug is Windows-specific and hidden in dev/testing.

Fix Action

Fix

Change the open mode from "r" to "r+" (read-write):

// fixed code
const handle = await fs.open(tempDest, "r+");  // read-write allows sync
try {
    await handle.sync();
} finally {
    await handle.close();
}

This matches the fix proposed in PR #76593 (fix(media): use r+ instead of r for fs.open to fix EPERM on fsync on Windows).

Code Example

Error: EPERM: operation not permitted, fsync
  at async fsync (node:internal/fs/promises:842)
  at async fsCall (node:internal/fs/promises:468)
  at async writeSavedMediaBuffer (store-*.js:236)

---

// current code (line ~351)
const handle = await fs.open(tempDest, "r");  // read-only fails sync on Windows
try {
    await handle.sync();
} finally {
    await handle.close();
}

---

// fixed code
const handle = await fs.open(tempDest, "r+");  // read-write allows sync
try {
    await handle.sync();
} finally {
    await handle.close();
}
RAW_BUFFERClick to expand / collapse

Bug type

Regression (worked before 2026.5.2, now fails on Windows)

Beta release blocker

Yes — affects core media functionality

Summary

Two distinct features fail with the same root cause on Windows after upgrading to 2026.5.2:

  1. image_generate tool — generated images cannot be saved, throwing EPERM: operation not permitted, fsync
  2. Feishu picture receive — inbound images via Feishu channel are not downloaded, also throwing EPERM: operation not permitted, fsync

Both trace back to writeSavedMediaBuffer in the media store opening the temp file with read-only mode "r" before calling handle.sync(), which Windows rejects with EPERM.

Error Message

Error: EPERM: operation not permitted, fsync
  at async fsync (node:internal/fs/promises:842)
  at async fsCall (node:internal/fs/promises:468)
  at async writeSavedMediaBuffer (store-*.js:236)

Environment

  • OS: Windows 11 (Windows_NT 10.0.19045 x64)
  • OpenClaw version: 2026.5.2 (8b2a6e5)
  • Node.js: v24.15.0
  • Gateway mode: local

Steps to reproduce

image_generate:

  1. Run image_generate prompt="test" on Windows
  2. Image generation request succeeds but saving to disk fails with EPERM

Feishu picture receive:

  1. Send a picture via Feishu direct message
  2. Message received as <media:image> placeholder, media/inbound stays empty
  3. Gateway log shows EPERM during media offload

Expected behavior

  • Generated images saved successfully to media/tool-image-generation/
  • Feishu inbound pictures saved to media/inbound/ and parseable by AI

Actual behavior

Both fail with EPERM: operation not permitted, fsync

Root Cause

In src/media/store.ts, writeSavedMediaBuffer opens the staged temp file with read-only mode "r" before calling handle.sync():

// current code (line ~351)
const handle = await fs.open(tempDest, "r");  // read-only fails sync on Windows
try {
    await handle.sync();
} finally {
    await handle.close();
}

On Windows, calling fsync() on a read-only file handle returns EPERM (operation not permitted). Linux/macOS allow this, so the bug is Windows-specific and hidden in dev/testing.

Fix

Change the open mode from "r" to "r+" (read-write):

// fixed code
const handle = await fs.open(tempDest, "r+");  // read-write allows sync
try {
    await handle.sync();
} finally {
    await handle.close();
}

This matches the fix proposed in PR #76593 (fix(media): use r+ instead of r for fs.open to fix EPERM on fsync on Windows).

Related Issues

  • #76844 — Windows: EPERM fsync error when uploading .docx files via WebChat (same root cause)
  • #76977 — MediaOffloadError: EPERM operation not permitted, fsync (closed as duplicate of #76844)

Impact and Severity

  • Affected: All Windows users (all OpenClaw versions 2026.5.x)
  • Severity: High — blocks image generation and inbound media parsing, two core features
  • Workaround: None for image_generate; manual file placement for Feishu inbound
  • Fix diff: one character ("r" to "r+") — minimal risk

extent analysis

TL;DR

Change the file open mode from "r" to "r+" in writeSavedMediaBuffer to fix the EPERM error on Windows.

Guidance

  • Verify the issue is resolved by checking if generated images are saved successfully and Feishu inbound pictures are downloaded and parsed correctly after applying the fix.
  • Review related issues #76844 and #76977 to ensure the root cause is fully addressed.
  • Test the fix on different Windows versions and Node.js environments to ensure compatibility.
  • Consider backporting the fix to earlier OpenClaw versions to prevent similar issues.

Example

The fixed code should look like this:

const handle = await fs.open(tempDest, "r+");  // read-write allows sync
try {
    await handle.sync();
} finally {
    await handle.close();
}

Notes

This fix is specific to Windows and may not affect Linux or macOS environments. The change is minimal and has low risk, but thorough testing is still recommended.

Recommendation

Apply the workaround by changing the file open mode to "r+" as proposed in PR #76593, as it directly addresses the root cause and has a low risk of introducing new issues.

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

  • Generated images saved successfully to media/tool-image-generation/
  • Feishu inbound pictures saved to media/inbound/ and parseable by AI

Still need to ship something?

×6

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

Back to top recommendations

TRENDING