ConPTY not emitting OSC sequences longer than 256 characters (Windows 10) #20087

Closed
opened 2026-01-31 07:03:07 +00:00 by claunia · 5 comments
Owner

Originally created by @segrey on GitHub (Jun 14, 2023).

Windows Terminal version

1.17.11461.0

Windows build number

10.0.19045.0

Other Software

No response

Steps to reproduce

You need Windows 10 to reproduce this. Not reproduced for me on Windows 11.

  1. Open forked GUIConsole.ConPTY. It runs the following PowerShell script under the hood:
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
[Console]::Write("1")
[Console]::Write("$([char]0x1B)]42;$("a" * 5)`a")
[Console]::Write("2")
[Console]::Write("$([char]0x1B)]42;$("b" * 250)`a")
[Console]::Write("3")
[Console]::Write("$([char]0x1B)]42;$("c" * 251)`a")
[Console]::Write("4")
[Console]::Write("$([char]0x1B)]42;$("d" * 252)`a")
[Console]::Write("5")
[Console]::Write("$([char]0x1B)]42;$("e" * 253)`a")
  1. Run it in Windows Terminal. The following will be printed:
PS C:\Users\serge\sandbox\terminal\samples\ConPTY\GUIConsole\GUIConsole.ConPTY\bin\Debug\net7.0> .\GUIConsole.ConPTY.exe
Starting OSC-seq-example.ps1
stdout (length=356):
1dee2345
Found 7 sequences:
ESC[2J
ESC[m
ESC[H
ESC]0;C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe^G
ESC[?25h1
ESC]42;aaaaa^G
ESC]42;bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb^G^Gd^Gee^G2345

Expected Behavior

Visible printed text should be 12345.
The output should contain 5 OSC escape sequences:

  1. OSC 42 ; a x5
  2. OSC 42 ; b x250
  3. OSC 42 ; c x251
  4. OSC 42 ; d x252
  5. OSC 42 ; e x253

Actual Behavior

Instead, the visible printed text is 1dee2345.
The output contains only the first two escape sequnces:

  1. OSC 42 ; a x5
  2. OSC 42 ; b x250

Seems ConPTY cannot emit escape sequences longer than 256 characters. Are there any workarounds?

Originally created by @segrey on GitHub (Jun 14, 2023). ### Windows Terminal version 1.17.11461.0 ### Windows build number 10.0.19045.0 ### Other Software _No response_ ### Steps to reproduce You need Windows 10 to reproduce this. Not reproduced for me on Windows 11. 1. Open forked [GUIConsole.ConPTY](https://github.com/segrey/terminal/tree/OSC-seq-longer-256/samples/ConPTY/GUIConsole/GUIConsole.ConPTY). It runs the following PowerShell script under the hood: ``` [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 [Console]::Write("1") [Console]::Write("$([char]0x1B)]42;$("a" * 5)`a") [Console]::Write("2") [Console]::Write("$([char]0x1B)]42;$("b" * 250)`a") [Console]::Write("3") [Console]::Write("$([char]0x1B)]42;$("c" * 251)`a") [Console]::Write("4") [Console]::Write("$([char]0x1B)]42;$("d" * 252)`a") [Console]::Write("5") [Console]::Write("$([char]0x1B)]42;$("e" * 253)`a") ``` 2. Run it in Windows Terminal. The following will be printed: ``` PS C:\Users\serge\sandbox\terminal\samples\ConPTY\GUIConsole\GUIConsole.ConPTY\bin\Debug\net7.0> .\GUIConsole.ConPTY.exe Starting OSC-seq-example.ps1 stdout (length=356): 1dee2345 Found 7 sequences: ESC[2J ESC[m ESC[H ESC]0;C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe^G ESC[?25h1 ESC]42;aaaaa^G ESC]42;bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb^G^Gd^Gee^G2345 ``` ### Expected Behavior Visible printed text should be `12345`. The output should contain 5 OSC escape sequences: 1. OSC 42 ; `a` x5 2. OSC 42 ; `b` x250 3. OSC 42 ; `c` x251 4. OSC 42 ; `d` x252 5. OSC 42 ; `e` x253 ### Actual Behavior Instead, the visible printed text is `1dee2345`. The output contains only the first two escape sequnces: 1. OSC 42 ; `a` x5 2. OSC 42 ; `b` x250 Seems ConPTY cannot emit escape sequences longer than 256 characters. Are there any workarounds?
claunia added the Issue-BugResolution-Duplicate labels 2026-01-31 07:03:07 +00:00
Author
Owner

@DHowett commented on GitHub (Jun 14, 2023):

Interesting!

It looks like this works with the version of ConPTY in Terminal 1.18!

image

(The debug panel on the right shows conpty's raw output before Terminal parses it for display on the left.)

The version of ConPTY shipped in Windows 10 is quite out of date compared to what ships in Terminal, and it's difficult for applications to get access to. We're tracking making that easier in #15065.

Unfortunately, you may need to wait until that one lands. Sorry! /dup #15065

@DHowett commented on GitHub (Jun 14, 2023): _Interesting!_ It looks like this works with the version of ConPTY in Terminal 1.18! <img width="868" alt="image" src="https://github.com/microsoft/terminal/assets/189190/9e6c781e-6ce3-406d-a3fd-0f122eb98978"> (The debug panel on the right shows conpty's raw output before Terminal parses it for display on the left.) The version of ConPTY shipped in Windows 10 is quite out of date compared to what ships in Terminal, and it's difficult for applications to get access to. We're tracking making that easier in #15065. Unfortunately, you may need to wait until that one lands. Sorry! /dup #15065
Author
Owner

@microsoft-github-policy-service[bot] commented on GitHub (Jun 14, 2023):

Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!

@microsoft-github-policy-service[bot] commented on GitHub (Jun 14, 2023): Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!
Author
Owner

@segrey commented on GitHub (Jun 15, 2023):

@DHowett Perfect, thanks for the quick response!

Probably, it's not needed as you've got my case right, but I feel like I should have clarified it a bit. My application similarly to the forked GUIConsole.ConPTY loads ConPTY from Windows system libraries. There is no such issue when the PowerShell commands (like [Console]::Write("HELLO$([char]0x1B)]42;$("c" * 1024)$([char]0x07)WORLD")) are run directly in Windows Terminal 1.17.11461.0. The problem occurs when they are run in PowerShell which is run with ConPTY loaded from Windows system libraries.

Thanks for https://github.com/microsoft/terminal/issues/15065. While it's unavailable yet, do you know if there are any workarounds for the ConPTY version shipped in Windows 10?

Oh, more importantly, how can I detect if a loaded ConPTY version contains the fix for this issue?

@segrey commented on GitHub (Jun 15, 2023): @DHowett Perfect, thanks for the quick response! Probably, it's not needed as you've got my case right, but I feel like I should have clarified it a bit. My application similarly to the forked [GUIConsole.ConPTY](https://github.com/segrey/terminal/tree/OSC-seq-longer-256/samples/ConPTY/GUIConsole/GUIConsole.ConPTY) loads ConPTY from Windows system libraries. There is no such issue when the PowerShell commands (like `[Console]::Write("HELLO$([char]0x1B)]42;$("c" * 1024)$([char]0x07)WORLD")`) are run directly in Windows Terminal 1.17.11461.0. The problem occurs when they are run in PowerShell which is run with ConPTY loaded from Windows system libraries. Thanks for https://github.com/microsoft/terminal/issues/15065. While it's unavailable yet, do you know if there are any workarounds for the ConPTY version shipped in Windows 10? Oh, more importantly, how can I detect if a loaded ConPTY version contains the fix for this issue?
Author
Owner

@DHowett commented on GitHub (Jun 16, 2023):

Unfortunately, I don't have a very good answer for those two questions. There isn't a workaround (I believe the bug is actually that on occasion, the console host receives the OSC in more than one WriteConsole call and we didn't have OSC fragment collection until #4870 landed (which shipped in Windows in build 19611.) It was pretty busted before that.

It's unfortunately not detectable. Any version you get from a prospective or potential nuget package will have the fix, and any version on Windows 10.0.20348 and above will have the fix. That's Server 2022... 🤔

@DHowett commented on GitHub (Jun 16, 2023): Unfortunately, I don't have a very good answer for those two questions. There isn't a workaround (I believe the bug is actually that on occasion, the console host receives the OSC in more than one `WriteConsole` call and we didn't have OSC fragment collection until #4870 landed (which shipped in Windows in build 19611.) It was pretty busted before that. It's unfortunately not detectable. Any version you get from a prospective or potential nuget package _will_ have the fix, and any version on Windows 10.0.20348 and above will have the fix. That's Server 2022... 🤔
Author
Owner

@segrey commented on GitHub (Jun 16, 2023):

Great, thanks for the details.

@segrey commented on GitHub (Jun 16, 2023): Great, thanks for the details.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#20087