PTY output pollutes OpenCode session with ANSI escape sequences, breaking keyboard input on resume
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 30/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- sqlite, typescript
- Lĩnh vực
- cli, developer-experience
Hướng nghiên cứu
Start by tracing the pty_read results and pty_exited notifications that write PTY output into the session; the issue does not name specific files or tests. Check how sanitizing those messages can leave the raw buffer untouched, and verify that ANSI/VT sequences no longer execute when a session is reopened while the Web UI / xterm.js stream remains raw.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Hi,
I ran into a really confusing issue where resuming an old OpenCode session made the TUI basically unusable — arrow keys, delete, and shortcuts stopped working, and the screen kept getting cleared/redrawn in weird ways.
The problem in one sentence: pty_read results and <pty_exited> notifications write raw PTY output (including ANSI/VT escape sequences) directly into the OpenCode session, and the TUI re-executes those sequences every time it renders the message.
Real impact
- Sessions that output terminal-mode sequences like
ESC[?9001h,ESC[?1004h,ESC[?25l,ESC[2J, orESC]0;...permanently poison the chat history. - Every time you open, resume, or fork the session, the TUI re-runs the sequences. In my case this meant the screen was cleared and the keyboard input mode was switched, so arrow keys / delete / shortcuts stopped working (typing via the IME still worked, which made it extra confusing).
- New sessions and unrelated sessions are fine; only the poisoned session is affected. Forking copies the bad messages, so the fork is also broken.
Reproduction
The simplest repro is to spawn anything that prints a terminal-mode sequence and then read or resume the session:
pty_spawn: command="printf", args=["\x1b[?9001h\x1b[?25ldone\n"], description="ansi repro"
pty_read: id=<pty-id>
After the pty_read returns, close and reopen the session. The TUI will re-execute ESC[?9001h and ESC[?25l when it renders that message.
A more realistic trigger is running a Playwright test suite or anything that uses a TTY-aware tool under a pseudo-terminal — the PTY gets the raw sequences, and they end up in opencode.db unchanged.
Environment
- Windows 11 + Windows Terminal
- opencode 1.18.34
- opencode-pty 0.4.0
Workaround
I confirmed the cause by finding parts in opencode.db that contain \u001b and replacing the escape byte with visible text:
sqlite3 ~/.local/share/opencode/opencode.db "UPDATE part SET data = replace(data, '\u001b', '[ESC]') WHERE data LIKE '%\u001b%';"
After that, the affected session resumed normally.
Suggested fix
Sanitize ANSI/VT escape sequences (CSI, OSC, and stray ESC) before writing PTY output into pty_read results or <pty_exited> notifications. The raw buffer can stay untouched so the Web UI / xterm.js stream still works. A config option (e.g. PTY_SANITIZE_OUTPUT=false) to keep raw output would be nice for debugging.
- Ngôn ngữ chính
- TypeScript
- Star
- 597
- Fork
- 65
- Merge trung bình
- 1 ngày 20 giờ
- Pull request đã merge (30 ngày)
- 3
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của shekohex/opencode-pty
-
[Bug]: exit notification delivery failures are silently swallowed — agent never wakes, no diagnosticĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
shekohex/opencode-pty#54 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
shekohex/opencode-pty#48 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 65/100
shekohex/opencode-pty#67 · 3 bình luận · 2 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 56/100
shekohex/opencode-pty#66 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Feature]: Setting to have the web ui running even without /pty-... commandCó thể đã có người làm @kumar-shivang đã nhận 19 ngày trước. Đang mởenhancement
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 65/100
shekohex/opencode-pty#60 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của shekohex/opencode-pty
Issue tương tự
-
bug(sight): the dashboard's text truncations split surrogate pairs and show broken charactersĐang mởcomponent:sight
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
agentic-os-org/ANOLISA#6738 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug Durable Agents Observability (AI Telemetry) status: needs triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
mastra-ai/mastra#26470 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
paperclipai/paperclip#15630 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[good first issue, hacktoberfest] ⛩️ Add new Theme: Sakura Latte (good-first-issue)Có thể đã có người làm @PGrayCS đã nhận hôm nay. Đang mởcommunity first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 78/100
lingdojo/kana-dojo#31937 · 1 bình luận · 5 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
feature/cohorts feature/feature-flags team/feature-flags
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày