[PR #686] fix: discard partial OSC/DCS/APC sequences on flush to prevent garbage text in input #713

Open
opened 2026-03-02 23:47:48 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/anomalyco/opentui/pull/686
Author: @bbartels
Created: 2/13/2026
Status: 🔄 Open

Base: mainHead: patch-1


📝 Commits (2)

  • 6c20852 Update stdin-buffer.ts
  • ea53e11 Add tests for OSC sequence handling in stdin buffer

📊 Changes

2 files changed (+145 additions, -0 deletions)

View changed files

📝 packages/core/src/lib/stdin-buffer.test.ts (+120 -0)
📝 packages/core/src/lib/stdin-buffer.ts (+25 -0)

📄 Description

Summary

Fixes https://github.com/anomalyco/opencode/issues/6147 — Windows Terminal sends unsolicited OSC queries (10/11/4) over SSH whose responses can arrive fragmented and leak into the TUI input field as garbage text like eeee/eeee/eeee.

Problem

When data arrives fragmented over SSH, the StdinBuffer timeout can fire mid-sequence. The flush() method emits the incomplete buffer as-is, which downstream parseKeypress() no longer recognizes as an escape sequence (since it may be missing the ESC ] prefix after the first chunk timed out separately). The payload then gets interpreted as regular text input.

Fix

Added isPartialEscapeSequence() check in flush() that silently discards incomplete OSC (ESC ]), DCS (ESC P), and APC (ESC _) sequences instead of emitting them as input. These sequence types are never valid keypresses.
CSI (ESC [) and SS3 (ESC O) are intentionally not discarded because a timed-out ESC [ could be a legitimate Alt+[ keypress.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/anomalyco/opentui/pull/686 **Author:** [@bbartels](https://github.com/bbartels) **Created:** 2/13/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `patch-1` --- ### 📝 Commits (2) - [`6c20852`](https://github.com/anomalyco/opentui/commit/6c208528431b784911604cf9407f2bf70f1e4de5) Update stdin-buffer.ts - [`ea53e11`](https://github.com/anomalyco/opentui/commit/ea53e1155082e950bc89f708dad0c9d535c2ef05) Add tests for OSC sequence handling in stdin buffer ### 📊 Changes **2 files changed** (+145 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `packages/core/src/lib/stdin-buffer.test.ts` (+120 -0) 📝 `packages/core/src/lib/stdin-buffer.ts` (+25 -0) </details> ### 📄 Description ## Summary Fixes https://github.com/anomalyco/opencode/issues/6147 — Windows Terminal sends unsolicited OSC queries (10/11/4) over SSH whose responses can arrive fragmented and leak into the TUI input field as garbage text like `eeee/eeee/eeee`. ## Problem When data arrives fragmented over SSH, the `StdinBuffer` timeout can fire mid-sequence. The `flush()` method emits the incomplete buffer as-is, which downstream `parseKeypress()` no longer recognizes as an escape sequence (since it may be missing the `ESC ]` prefix after the first chunk timed out separately). The payload then gets interpreted as regular text input. ## Fix Added `isPartialEscapeSequence()` check in `flush()` that silently discards incomplete OSC (`ESC ]`), DCS (`ESC P`), and APC (`ESC _`) sequences instead of emitting them as input. These sequence types are never valid keypresses. CSI (`ESC [`) and SS3 (`ESC O`) are intentionally **not** discarded because a timed-out `ESC [` could be a legitimate `Alt+[` keypress. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/opentui#713
No description provided.