fix(node-host): decode Windows exec output with active code page#30652
fix(node-host): decode Windows exec output with active code page#30652Takhoffman merged 1 commit intoopenclaw:mainfrom
Conversation
Decode system.run stdout/stderr on Windows using the current console code page so non-UTF-8 shells (for example CP936/GBK PowerShell) no longer produce garbled text. Adds regression coverage for code page parsing and GBK output decoding. Closes openclaw#30640
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a603fc8c09
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const stdout = decodeCapturedOutputBuffer({ | ||
| buffer: Buffer.concat(stdoutChunks), | ||
| windowsEncoding, | ||
| }); |
There was a problem hiding this comment.
Avoid decoding all Windows output as console code page
runCommand now always decodes captured Windows output with windowsEncoding, which is derived from chcp and applied to every spawned process. On non-UTF-8 consoles, this mis-decodes tools that already emit UTF-8 bytes (for example Node-based CLIs and other cross-platform binaries), so valid UTF-8 output is converted into mojibake; this is a behavior regression from the previous UTF-8 decoding path for those commands. Restricting code-page decoding to cmd.exe-style output (or adding UTF-8 fallback heuristics per process) would avoid corrupting these cases.
Useful? React with 👍 / 👎.
Greptile SummaryThis PR fixes Windows command output decoding by detecting and using the active console code page instead of always assuming UTF-8. The implementation adds a Key changes:
Design strengths:
Confidence Score: 4/5
Last reviewed commit: a603fc8 |
|
PR #30652 - fix(node-host): decode Windows exec output with active code page (#30652) Merged via squash.
Thanks @Sid-Qin! |
…nclaw#30652) thanks @Sid-Qin Verified: - pnpm vitest run src/node-host/invoke.sanitize-env.test.ts src/node-host/invoke-system-run.test.ts Co-authored-by: Sid-Qin <53659198+Sid-Qin@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
) thanks @Sid-Qin Verified: - pnpm vitest run src/node-host/invoke.sanitize-env.test.ts src/node-host/invoke-system-run.test.ts Co-authored-by: Sid-Qin <53659198+Sid-Qin@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…nclaw#30652) thanks @Sid-Qin Verified: - pnpm vitest run src/node-host/invoke.sanitize-env.test.ts src/node-host/invoke-system-run.test.ts Co-authored-by: Sid-Qin <53659198+Sid-Qin@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…nclaw#30652) thanks @Sid-Qin Verified: - pnpm vitest run src/node-host/invoke.sanitize-env.test.ts src/node-host/invoke-system-run.test.ts Co-authored-by: Sid-Qin <53659198+Sid-Qin@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…nclaw#30652) thanks @Sid-Qin Verified: - pnpm vitest run src/node-host/invoke.sanitize-env.test.ts src/node-host/invoke-system-run.test.ts Co-authored-by: Sid-Qin <53659198+Sid-Qin@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…nclaw#30652) thanks @Sid-Qin Verified: - pnpm vitest run src/node-host/invoke.sanitize-env.test.ts src/node-host/invoke-system-run.test.ts Co-authored-by: Sid-Qin <53659198+Sid-Qin@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…nclaw#30652) thanks @Sid-Qin Verified: - pnpm vitest run src/node-host/invoke.sanitize-env.test.ts src/node-host/invoke-system-run.test.ts Co-authored-by: Sid-Qin <53659198+Sid-Qin@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
Summary
exec/system.runoutput was always decoded as UTF-8, so Windows shells running on legacy code pages (for example CP936/GBK) rendered Chinese text as garbled characters.src/node-host/invoke.tsnow resolves the active Windows console code page (chcp) once per process and decodes captured stdout/stderr buffers with the matching encoding before returning results.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
system.run/execoutput now preserves non-UTF-8 console text (e.g. GBK Chinese output) instead of showing replacement characters.Security Impact (required)
NoNoNoNoNoRepro + Verification
Environment
system.runpathSteps
exec/system.run.Expected
Actual
�/乱码).Evidence
pnpm exec vitest run src/node-host/invoke.sanitize-env.test.tspnpm exec vitest run src/node-host/invoke-system-run.test.tsHuman Verification (required)
chcpoutput; GBK decoding path; existing node-host system-run tests.Compatibility / Migration
YesNoNoFailure Recovery (if this breaks)
src/node-host/invoke.tsand test updates.Risks and Mitigations
chcpoutput may be unavailable in some shells.