PTY output pollutes OpenCode session with ANSI escape sequences, breaking keyboard input on resume
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 30/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 停滞
- 技術スタック
- sqlite, typescript
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- TypeScript
- スター
- 594
- フォーク
- 61
- 平均マージ
- 1日 20時間
- マージ済み PR(30日)
- 3
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
shekohex/opencode-pty のほかの issue
-
[Bug]: exit notification delivery failures are silently swallowed — agent never wakes, no diagnosticオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
shekohex/opencode-pty#54 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
shekohex/opencode-pty#48 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 3/5 1〜2日 初心者へのやさしさ 65/100
shekohex/opencode-pty#67 · コメント 3 件 · リアクション 2 件 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 4/5 3〜5日 初心者へのやさしさ 56/100
shekohex/opencode-pty#66 ·
メンテナーはふだん 1 日以内に返信
-
[Feature]: Setting to have the web ui running even without /pty-... command対応中かも @kumar-shivang が 18 日前に担当しました。 オープンenhancement
難易度 3/5 1〜2日 初心者へのやさしさ 65/100
shekohex/opencode-pty#60 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
shekohex/opencode-pty の issue をすべて見る
似ている issue
-
refactor
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
tomnewport/memprot-topo#55 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
WalletConnect/walletconnect-monorepo#7368 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
BU-Spark/se-chem-apll#47 ·
-
embed: handleTurboSignMessage header comment says the signing page posts to '*' (it never does)オープンdocumentation
難易度 2/5 1時間未満 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 半日 初心者へのやさしさ 70/100
udistrital/paginaweb_root#23 ·