[PR #15298] Make conhost act in VtIo mode earlier in startup #30575

Closed
opened 2026-01-31 09:41:38 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/15298

State: closed
Merged: Yes


We need to act like a ConPTY just a little earlier in startup. My relevant notes start here: https://github.com/microsoft/terminal/issues/15245#issuecomment-1536150388.

Basically, we'd create the first screen buffer with 9001 rows, because it would be created before VtIo would be in a state to say "yes, we're a conpty". Then, if a CLI app emits an entire screenful of text before the terminal has a chance to resize the conpty, then the conpty will explode during _DoLineFeed. That method is absolutely not expecting the buffer to get resized (and the old text buffer deallocated).

Instead, this will treat the console as in ConPty mode as soon as VtIo::Initialize is called (this is during ConsoleCreateIoThread, which is right at the end of ConsoleEstablishHandoff, which is before the API server starts to process the client connect message). THEORETICALLY, VtIo could Initialize then fail to create objects in CreateIoHandlers (which is what we used to treat as the moment that we were in conpty mode). However, if we do fail out of CreateIoHandlers, then the console itself will fail to start up, and just die. So I don't think that's needed.

This fixes #15245. I think this is PROBABLY also the solution to #14512, but I'm not gonna explicitly mark closed. We'll loop back on it.

TODO

  • I want to audit the uses of CONSOLE_INFORMATION::IsInVtIoMode before I commit to this.
**Original Pull Request:** https://github.com/microsoft/terminal/pull/15298 **State:** closed **Merged:** Yes --- We need to act like a ConPTY just a little earlier in startup. My relevant notes start here: https://github.com/microsoft/terminal/issues/15245#issuecomment-1536150388. Basically, we'd create the first screen buffer with 9001 rows, because it would be created _before_ VtIo would be in a state to say "yes, we're a conpty". Then, if a CLI app emits an entire screenful of text _before_ the terminal has a chance to resize the conpty, then the conpty will explode during `_DoLineFeed`. That method is absolutely not expecting the buffer to get resized (and the old text buffer deallocated). Instead, this will treat the console as in ConPty mode as soon as `VtIo::Initialize` is called (this is during `ConsoleCreateIoThread`, which is right at the end of `ConsoleEstablishHandoff`, which is before the API server starts to process the client connect message). THEORETICALLY, `VtIo` could `Initialize` then fail to create objects in `CreateIoHandlers` (which is what we used to treat as the moment that we were in conpty mode). However, if we do fail out of `CreateIoHandlers`, then the console itself will fail to start up, and just die. So I don't think that's needed. This fixes #15245. I think this is PROBABLY also the solution to #14512, but I'm not gonna explicitly mark closed. We'll loop back on it. #### TODO * [x] I want to audit the uses of `CONSOLE_INFORMATION::IsInVtIoMode` before I commit to this.
claunia added the pull-request label 2026-01-31 09:41:38 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#30575