[Bug] macOS 上 bash 工具执行含中文命令会损坏并超时(bash 3.2 PTY 数据损坏) #3391
Replies: 1 comment
|
I traced this against the At the pinned commit, Practical bounded workarounds:
A durable repair belongs at the serializer boundary: preserve ASCII as-is and encode each non-ASCII UTF-8 byte as I documented the evidence chain, recovery choices, and regression gates here: https://sandbaseai.github.io/deepseek-harness-handbook/macos-bash-nonascii.html Disclosure: this is an independent community handbook maintained by SandBase, not an official DeepSeek document. |
Uh oh!
There was an error while loading. Please reload this page.
问题现象
在 macOS 上,DSH 的
bash工具执行含中文(非 ASCII)的命令时,命令会被损坏并最终超时:echo 中文测试实际输出--------(中文被替换成 8 个连字符,与字符数无关)。git commit -m '优化下载命名'这类含中文的命令会一直卡到 300s 超时(timed out after 300 seconds),期间 bash 不打印完成标记、也不回到dsh>提示符。环境
/bin/bash --version:GNU bash, version 3.2.57(1)-release (arm64-apple-darwin25)packages/shell/tool-bash-persistent+packages/terminal/terminal-bash)根因
这是 node-pty 已知的 macOS bash 3.2 readline 数据损坏问题(node-pty issue #833)。node-pty 源码
unixTerminal.js里的注释也明确写了:DSH 的
tool-bash-persistent会把整条命令一次性快速写入 PTY,macOS 自带的 bash 3.2 在快速写入时损坏非 ASCII(多字节 UTF-8)字节,导致:-(实测 1~4 个中文字符都固定变成 8 个-);__DSH_PERSISTENT_BASH_END_*标记不打印、也不回到dsh>提示符;纯 ASCII 命令不受影响;
printf '\\xe4\\xb8\\xad'这类在 bash 端生成中文的写法也不受影响(命令本身仍是纯 ASCII)。修复方案
在
quoteForBash里把命令中的非 ASCII 字节(>= 0x80)转义成 ANSI-C 的\xHH,让写入 PTY 的命令保持纯 ASCII,从而规避 bash 3.2 的 readline 损坏:验证
echo 中文测试转义后为纯 ASCII:$'echo \xe4\xb8\xad\xe6\x96\x87\xe6\xb5\x8b\xe8\xaf\x95'eval -- ...能正确输出中文测试,退出码 0echo hi)输出不变,无回归影响node --check通过希望能帮到团队修复这个问题。
All reactions