github / github/copilot-cli

ANSI escape stripping garbles output at PTY read boundaries

Đang mở
#2,103 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
area:terminal-rendering area:tools
Ngôn ngữ chính
Shell
Star
11.2k
Fork
1.9k
Merge trung bình
14 giờ 16 phút
Pull request đã merge (30 ngày)
6

Mô tả

## Describe the bug

The bash tool's ANSI-stripping logic garbles output when escape sequences are split across PTY read boundaries. Fragments like `1m`, `]8;;`, or URL text from OSC 8 hyperlinks leak into captured output. The bug is non-deterministic — the same command can produce different garbled lines or sometimes render cleanly.

## Affected version

1.0.6

## Steps to reproduce

Run this in a Copilot CLI session (no dependencies needed — pure bash):

```bash
for d in $(seq -w 4 17); do
printf '\e]8;;https://example.com/2026-03-%s\aDate-%s\e]8;;\a \e[1mA\e[22m \e[36mB\e[39m \e[32mC\e[39m \e[31mD\e[39m\n' "$d" "$d"
done
```

Run multiple times. Some runs will show garbled output on one or more lines, such as:
```
Date-13 A B C D
ttps://example.com/2026-03-14Date-14 A B C D ← URL leaked
Date-15 A B C D
```
or:
```
Date-14]8;; A B C D ← OSC fragment leaked
```

Other runs of the exact same command will be completely clean.

## Expected behavior

All escape sequences should be fully stripped in every run, producing 14 identical lines of `Date-XX A B C D`.

## Additional context

The stripping appears to process bytes as they arrive from each PTY `read()` call. Since reads don't align with writes, an escape sequence can be split across two reads. Neither contains the complete sequence, so the regex fails to match and leaves fragments in the output. The non-determinism (different lines garbled across runs, sometimes clean) confirms this is a read-timing issue, not a regex pattern bug.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.