From b89093031e0fb3c78c598ddabec767a0660dded8 Mon Sep 17 00:00:00 2001 From: Faur Ioan-Aurel Date: Sat, 25 Oct 2025 06:05:03 +0300 Subject: [PATCH] fix: initialize pseudo console with default size for SSH sessions (#20472) Resolved an invalid parameter error (-2147024809) during PTY creation on Windows 11 22H2 (but not only) when connecting via JetBrains Toolbox which spawns the native SSH client with `-tt` forcing PTY allocation even though there is no "terminal" on the client side to query its size. CreatePseudoConsole doesn't accept a 0x0 (zero width and zero height) console size and unfortunately, there is NO explicit documentation in the official Microsoft documentation that states the minimum valid values or explicitly prohibits 0x0. Looking at real-world implementations in the search results, all examples use reasonable non-zero values. I tested this with a local Windows VM registered to dev.coder.com i.e. externally managed workspace. Fixes: #20468 --- pty/pty_windows.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pty/pty_windows.go b/pty/pty_windows.go index 93fea12019..987ef02eb2 100644 --- a/pty/pty_windows.go +++ b/pty/pty_windows.go @@ -54,10 +54,19 @@ func newPty(opt ...Option) (*ptyWindows, error) { return nil, err } - consoleSize := uintptr(80) + (uintptr(80) << 16) + // Default dimensions + width, height := 80, 80 if opts.sshReq != nil { - consoleSize = uintptr(opts.sshReq.Window.Width) + (uintptr(opts.sshReq.Window.Height) << 16) + if w := opts.sshReq.Window.Width; w > 0 && w <= 65535 { + width = w + } + if h := opts.sshReq.Window.Height; h > 0 && h <= 65535 { + height = h + } } + + consoleSize := uintptr(width) + (uintptr(height) << 16) + ret, _, err := procCreatePseudoConsole.Call( consoleSize, uintptr(pty.inputRead.Fd()),