Skip to content

fix: force UTF-8 code page for OpenClaw gateway on Windows#13389

Open
SiinXu wants to merge 1 commit intomainfrom
fix/openclaw-gateway-encoding
Open

fix: force UTF-8 code page for OpenClaw gateway on Windows#13389
SiinXu wants to merge 1 commit intomainfrom
fix/openclaw-gateway-encoding

Conversation

@SiinXu
Copy link
Collaborator

@SiinXu SiinXu commented Mar 11, 2026

Summary

  • On Windows Chinese systems (CP936/GBK), OpenClaw gateway child processes output Chinese text in GBK encoding, causing garbled characters (U+FFFD) in chat responses
  • Prepend chcp 65001 when spawning the gateway on Windows to force UTF-8 code page for the entire process tree
  • Non-Windows platforms are unaffected

Closes #13384

Test plan

  • On Windows Chinese system, start OpenClaw gateway and verify Chinese text in chat responses displays correctly
  • On macOS/Linux, verify gateway still starts and functions normally

On Windows Chinese systems (CP936/GBK), the gateway's child processes
output Chinese text in GBK encoding, causing garbled characters in chat
responses. Prepend `chcp 65001` when spawning the gateway to force
UTF-8 encoding for the entire process tree.

Closes #13384

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Collaborator

@GeorgeDong32 GeorgeDong32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

This PR addresses two cross-platform compatibility issues effectively:

Changes Reviewed:

  1. Windows UTF-8 Encoding Fix: Using chcp 65001 to force UTF-8 code page before spawning the OpenClaw gateway on Windows
  2. Environment Variable Refactoring: Extracting gatewayEnv into a separate variable improves code clarity
  3. Import Cleanup: Combining type and function imports from child_process

Positives:

  • Clean platform-specific handling using isWin check
  • Good inline comment explaining the fix and referencing issue #13384
  • Non-Windows platforms maintain existing behavior (backward compatible)

Suggestions:

  • Consider adding explicit port validation before using this.gatewayPort in shell commands
  • Testing on actual Windows Chinese systems would be valuable

Overall, this is a well-crafted fix that solves the reported encoding issue without introducing side effects.

Reviewed by kimi-k2.5

import { hasAPIVersion, withoutTrailingSlash } from '@shared/utils'
import type { Model, Provider, ProviderType, VertexProvider } from '@types'
import type { ChildProcess } from 'child_process'
import { type ChildProcess, spawn } from 'child_process'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Good cleanup by importing directly alongside type. This avoids redundant import statements.

let startupError: string | null = null
let processExited = false

const gatewayEnv = { ...shellEnv, OPENCLAW_CONFIG_PATH }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Positive: Good refactoring by extracting into a separate variable. This improves readability and ensures both Windows and non-Windows paths use the same environment configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: OpenClaw garbled Chinese text on Windows

2 participants