PTY output pollutes OpenCode session with ANSI escape sequences, breaking keyboard input on resume
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 30/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Estancado
- Stack tecnológico
- sqlite, typescript
- Área
- cli, developer-experience
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- TypeScript
- Estrellas
- 594
- Forks
- 61
- Merge medio
- 1 d 20 h
- PR fusionados (30 d)
- 3
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de shekohex/opencode-pty
-
[Bug]: exit notification delivery failures are silently swallowed — agent never wakes, no diagnosticAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
shekohex/opencode-pty#54 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
shekohex/opencode-pty#48 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 3/5 1-2 días Aptitud para principiantes 65/100
shekohex/opencode-pty#67 · 3 comentarios · 2 reacciones ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 4/5 3-5 días Aptitud para principiantes 56/100
shekohex/opencode-pty#66 ·
Los mantenedores suelen responder en 1 día
-
[Feature]: Setting to have the web ui running even without /pty-... commandPosiblemente ocupada @kumar-shivang la tomó hace 18 días. Abiertoenhancement
Dificultad 3/5 1-2 días Aptitud para principiantes 65/100
shekohex/opencode-pty#60 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de shekohex/opencode-pty
Issues similares
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
Small-tailqwq/dsh-deep-whale#187 ·
Los mantenedores suelen responder en 1 día
-
Tela Marca manda conferir o campo "Razão social", que em Portugal se chama "Denominação social"Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
melgarafael/DeskcommCRM#2503 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
0x80/isolate-package#218 ·
-
bug via-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
pingdotgg/t3code#16859 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
Los mantenedores suelen responder en 1 día