Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

PTY output pollutes OpenCode session with ANSI escape sequences, breaking keyboard input on resume

オープン
#75 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@NAnD71 がすでに取り組んでいます。

2026年10月5日 から。

  • #76 @NAnD71 による — オープン

評価

難易度
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, or ESC]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 を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

shekohex/opencode-pty のほかの issue

shekohex/opencode-pty の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。