Skip to content

fix(migration): handle non-UTF-8 files in OpenClaw migration#9145

Open
Tranquil-Flow wants to merge 2 commits into
NousResearch:mainfrom
Tranquil-Flow:fix/openclaw-migration-unicode
Open

fix(migration): handle non-UTF-8 files in OpenClaw migration#9145
Tranquil-Flow wants to merge 2 commits into
NousResearch:mainfrom
Tranquil-Flow:fix/openclaw-migration-unicode

Conversation

@Tranquil-Flow

@Tranquil-Flow Tranquil-Flow commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixed UnicodeDecodeError crash during hermes claw migrate on Windows systems with non-UTF-8 locales (e.g. GBK/cp936).

On Chinese/Japanese/Korean Windows, the default encoding is not UTF-8. The migration script crashed when encountering binary files (images, SQLite) or system-encoded text files, making it impossible to migrate from OpenClaw. This PR adds errors="replace" decoding (invalid bytes become U+FFFD instead of crashing) plus per-file try/except so a single bad file no longer aborts the whole migration.

Related Issue

Closes #8901

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

Five changes in openclaw_to_hermes.py, all consistent in approach:

  1. read_text() — added errors="replace" so invalid bytes become U+FFFD instead of crashing
  2. load_yaml_file() — added errors="replace" + UnicodeDecodeError in except clause
  3. parse_env_file() — added errors="replace"
  4. load_openclaw_config() — added errors="replace" + UnicodeDecodeError in except clause
  5. migrate_daily_memory() — added per-file try/except so one bad file doesn't abort the entire migration

How to Test

  1. Run pytest tests/skills/test_openclaw_migration.py -v — all 37 tests pass (5 new + 32 existing)
  2. New tests write actual non-UTF-8 bytes (GBK sequences, PNG header) to disk and verify graceful handling
  3. Fix is safe on all platforms (Windows non-UTF-8 locales are the primary target)

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS 15 (Darwin 24.6.0)

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Screenshots / Logs

pytest tests/skills/test_openclaw_migration.py -v
# 37 passed (5 new + 32 existing)

@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/cli CLI entry point, hermes_cli/, setup wizard labels Apr 27, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #8898 — both fix UnicodeDecodeError in OpenClaw migration for non-UTF-8 locales, targeting the same file (openclaw_to_hermes.py) with the same approach (errors='replace').

On Windows with non-UTF-8 locales (e.g. GBK/cp936), the migration
script crashed with UnicodeDecodeError when encountering binary files
or system-encoded text. All file-reading functions now use
errors="replace" and per-file error recovery so the migration
completes instead of aborting.

Closes NousResearch#8901
@Tranquil-Flow Tranquil-Flow force-pushed the fix/openclaw-migration-unicode branch from b828baa to e00c158 Compare May 25, 2026 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard P3 Low — cosmetic, nice to have type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenClaw migration crashes with UnicodeDecodeError on Windows (non-UTF-8 locale)

2 participants