openclaw - 💡(How to fix) Fix Write failed 错误提示频繁出现 - 文件实际写入成功但返回错误 [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#56205Fetched 2026-04-08 01:43:38
View on GitHub
Comments
0
Participants
1
Timeline
2
Reactions
0
Participants
Timeline (top)
mentioned ×1subscribed ×1

Code Example

# 可靠文件写入脚本
# 用途:确保文件写入成功,统一编码和行尾

param(
    [string]$Path,
    [string]$Content
)

# 1. 确保目录存在
$dir = Split-Path $Path -Parent
if (!(Test-Path $dir)) {
    New-Item -ItemType Directory -Force -Path $dir | Out-Null
}

# 2. 写入文件(UTF-8 without BOM, CRLF 行尾)
$utf8NoBom = New-Object System.Text.UTF8Encoding $false
$content = $Content -replace "`n(?!`r)", "`r`n"
[System.IO.File]::WriteAllText($Path, $content, $utf8NoBom)

# 3. 验证写入
if (Test-Path $Path) {
    $file = Get-Item $Path
    Write-Host "Success: $($file.Name) ($($file.Length) bytes)"
    exit 0
} else {
    Write-Host "Failed: $Path"
    exit 1
}
RAW_BUFFERClick to expand / collapse

问题描述

在使用 OpenClaw 进行文件写入操作时,频繁出现 "Write failed" 错误提示,但实际文件已经成功写入。

复现场景

  • 使用 write 工具创建或编辑文件
  • 特别是在编辑 MEMORY.md 等大型文件时
  • 错误出现时间不固定,偶发性

根因分析

经过深入调查,发现问题可能由以下原因导致:

  1. 工具响应超时或显示延迟 - 文件实际写入成功,但工具响应返回错误提示
  2. 编码/行尾不统一 - UTF-8 BOM vs without BOM,CRLF vs LF 导致匹配失败
  3. 验证机制缺失 - 写入后没有立即验证文件是否真正存在

临时解决方案

已创建可靠写入脚本 scripts/reliable-write.ps1

# 可靠文件写入脚本
# 用途:确保文件写入成功,统一编码和行尾

param(
    [string]$Path,
    [string]$Content
)

# 1. 确保目录存在
$dir = Split-Path $Path -Parent
if (!(Test-Path $dir)) {
    New-Item -ItemType Directory -Force -Path $dir | Out-Null
}

# 2. 写入文件(UTF-8 without BOM, CRLF 行尾)
$utf8NoBom = New-Object System.Text.UTF8Encoding $false
$content = $Content -replace "`n(?!`r)", "`r`n"
[System.IO.File]::WriteAllText($Path, $content, $utf8NoBom)

# 3. 验证写入
if (Test-Path $Path) {
    $file = Get-Item $Path
    Write-Host "Success: $($file.Name) ($($file.Length) bytes)"
    exit 0
} else {
    Write-Host "Failed: $Path"
    exit 1
}

建议修复

  1. 在 write 工具中添加写入后验证 - 写入后立即检查文件是否存在 + 大小
  2. 统一编码标准 - 全部使用 UTF-8 without BOM
  3. 统一行尾标准 - Windows 使用 CRLF,跨平台时自动转换
  4. 改进错误报告 - 区分"实际写入失败"和"验证超时"

环境信息

  • OS: Windows 11 (Windows_NT 10.0.26200)
  • Node: v24.14.0
  • OpenClaw: 最新版
  • Shell: PowerShell

影响

  • 用户体验差 - 频繁看到错误提示但实际工作已完成
  • 需要额外验证步骤 - 每次写入后手动检查文件
  • 可能导致不必要的重试操作

附件: 完整脚本已上传至 scripts/reliable-write.ps1

/cc @steipete

extent analysis

Fix Plan

To address the "Write failed" error in OpenClaw, we will implement the following steps:

  • Modify the write tool to include a post-write verification step.
  • Standardize encoding to UTF-8 without BOM.
  • Standardize line endings to CRLF on Windows and automatically convert for cross-platform compatibility.
  • Improve error reporting to distinguish between actual write failures and verification timeouts.

Code Changes

We will update the write tool to use the reliable-write.ps1 script as a reference. Here's an example of how to implement the verification step in PowerShell:

# Post-write verification
if (Test-Path $Path) {
    $file = Get-Item $Path
    Write-Host "Success: $($file.Name) ($($file.Length) bytes)"
    exit 0
} else {
    Write-Host "Failed: $Path"
    exit 1
}

For standardizing encoding and line endings, we can use the following code:

# Standardize encoding to UTF-8 without BOM
$utf8NoBom = New-Object System.Text.UTF8Encoding $false

# Standardize line endings to CRLF
$content = $Content -replace "`n(?!`r)", "`r`n"

# Write file with standardized encoding and line endings
[System.IO.File]::WriteAllText($Path, $content, $utf8NoBom)

Verification

To verify that the fix worked, we can test the updated write tool with the following steps:

  1. Create a new file using the write tool.
  2. Verify that the file is created successfully and the content is correct.
  3. Check the file's encoding and line endings to ensure they match the standardized settings.
  4. Test the write tool with different file sizes and contents to ensure it works consistently.

Extra Tips

To prevent similar issues in the future, it's essential to:

  • Implement thorough testing and verification for file I/O operations.
  • Standardize encoding and line endings across all platforms and tools.
  • Provide clear and accurate error reporting to distinguish between actual failures and verification timeouts.
  • Continuously monitor and improve the write tool to ensure it meets the required standards and user expectations.

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 Write failed 错误提示频繁出现 - 文件实际写入成功但返回错误 [1 participants]