Skip to content

[Bug]: Config file concurrent write race truncates openclaw.json to 61 bytes #89331

@q1387154-spec

Description

@q1387154-spec

Bug: Config file concurrent write race truncates openclaw.json

What happened

When the Gateway daemon and a CLI tool (or two Gateway processes) write ~/.openclaw/openclaw.json concurrently, the file can be truncated to ~61 bytes, corrupting the entire configuration and causing service interruption.

Environment

  • OpenClaw: 2026.5.28 (e932160)
  • OS: Windows 10.0.26200 (x64)
  • Node: v24.16.0

Reproduction

  1. Have Gateway running (it writes config on hot-reload/restart)
  2. Trigger a CLI config write at the same time (e.g., openclaw config patch or a gateway tool call from an agent session)
  3. Observe openclaw.json truncated to ~61 bytes

This has been observed at least twice in production use.

Root cause analysis

The config write uses an atomic-write pattern (write temp, fsync, rename), but there is no file-level locking to prevent two writers from racing. When both writers read the file at nearly the same time, one write overwrites the other's changes. In worst case, the temp file rename races with a read, producing a truncated file.

The missing-meta-before-write log entries on every config read suggest the meta field is stripped during reads, compounding the data loss.

Suggested fix

Add a proper file lock (e.g., proper-lockfile npm package) around all config read-modify-write operations in both the Gateway daemon and CLI tools. The lock should be:

  • Acquired before reading the config file
  • Held through the entire read-modify-write cycle
  • Released after the atomic rename completes

Impact

  • Severity: P0 — complete config loss, service interruption
  • Frequency: Rare but reproducible under concurrent access
  • Affected: All platforms (observed on Windows, likely affects Linux/macOS too)

Metadata

Metadata

Assignees

Labels

P0Emergency: data loss, security bypass, crash loop, or unusable core runtime.clawsweeper:needs-infoClawSweeper needs more reporter information before it can verify this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:crash-loopCrash, hang, restart loop, or process-level availability failure.impact:data-lossCan lose, corrupt, or silently drop user/session/config data.issue-rating: 🦪 silver shellfishThin issue quality; more reproduction proof or environment detail is needed.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions