anomalyco / anomalyco/opencode
[Windows] Shell tool hangs on non-UTF8 pwsh output (Thai/Unicode) even after the command completes
@Hona is already working on this.
Since Sep 11, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Description
Reported by an AI agent. This issue was filed by an OpenCode agent (model: deepseek-v4-flash) on behalf of a human user. All details below were observed directly by the agent during a real task.
Summary
On Windows, the shell tool can hang (never returns) when a PowerShell 7 command emits output containing Thai (or any non-ASCII) text — even though the command itself completed successfully.
Expected
Command completes and the tool returns the output (correctly decoded, or escaped).
Actual
The tool hangs indefinitely. Re-checking the filesystem showed the file operations had already completed — the hang is at the output/stream stage, not the work itself.
Hypothesis
pwsh writes bytes in the legacy console code page (874/1252); the tool decodes stdout as UTF-8. Thai bytes 0xE0–0xEF are UTF-8 lead bytes, so if a buffer chunk ends mid-sequence the decoder waits for a continuation byte that never arrives, and/or the stdout pipe is never closed -> deadlock.
Workaround
Prefix the command with [Console]::OutputEncoding=[System.Text.Encoding]::UTF8; $OutputEncoding=[System.Text.Encoding]::UTF8;. Also avoid printing non-ASCII to stdout — write to a temp file with -Encoding utf8 instead.
Impact
Any Windows user with non-ASCII filenames/content (Thai, CJK, ...). The agent appears frozen after a successful operation, which can trigger duplicate / unsafe retries.
คำแปลภาษาไทย (Thai translation)
รายงานโดย AI agent — OpenCode agent (โมเดล deepseek-v4-flash) รายงานแทนผู้ใช้ ข้อมูลทั้งหมดพบจากการทำงานจริง
สรุป: บน Windows เครื่องมือ shell อาจค้าง (ไม่คืนค่า) เมื่อคำสั่ง PowerShell 7 ส่ง output ที่มีข้อความไทย (หรือ non-ASCII) แม้ว่าคำสั่งจะทำงานเสร็จแล้ว
คาดหวัง: คำสั่งจบแล้ว tool คืนผล output (ถอดรหัสถูก หรือ escape)
เกิดจริง: tool ค้างไม่คืนค่า แต่เช็ค filesystem แล้วไฟล์ถูกแก้ไปแล้ว — ค้างที่ขั้นตอน output/stream ไม่ใช่ตัวงาน
สมมติฐาน: pwsh ส่งไบต์ตาม code page เดิม (874/1252) แต่ tool ถอดเป็น UTF-8 ไบต์ไทย 0xE0–0xEF เป็น lead byte ของ UTF-8 ถ้า buffer จบกลางลำดับ decoder จะรอ continuation byte ที่ไม่มีมา และ/หรือ pipe ไม่ปิด -> deadlock
ทางเลี่ยง: ขึ้นต้นคำสั่งด้วย [Console]::OutputEncoding=[System.Text.Encoding]::UTF8 และเลี่ยงพิมพ์ non-ASCII ออก stdout ให้เขียนลงไฟล์ temp ด้วย -Encoding utf8
ผลกระทบ: ผู้ใช้ Windows ที่มีชื่อไฟล์/เนื้อหา non-ASCII ทุกคน — agent เหมือนค้างหลังงานสำเร็จ อาจทำให้ retry ซ้ำโดยไม่ปลอดภัย
Plugins
No response
OpenCode version
1.17.11
Steps to reproduce
- Have files with Thai names, e.g.
เอกสารแนบเพิ่ม 09 - ....pdf. - Run a one-liner that lists them and prints the names to stdout:
Get-ChildItem -LiteralPath $dir -File | ForEach-Object { $_.Name } - The shell tool does not return.
Screenshot and/or share link
No response
Operating System
Windows (win32)
Terminal
PowerShell 7.6.5 (pwsh)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.