{"record":{"id":"651a4e84867e2c98","repo":"wezterm/wezterm","slug":"failed-to-resize-console-to-x-hresult","errorCode":null,"errorMessage":"failed to resize console to {}x{}: HRESULT: {}","messagePattern":"failed to resize console to (.+?)x(.+?): HRESULT: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"pty/src/win/psuedocon.rs","lineNumber":101,"sourceCode":"                input.as_raw_handle(),\n                output.as_raw_handle(),\n                PSUEDOCONSOLE_INHERIT_CURSOR\n                    | PSEUDOCONSOLE_RESIZE_QUIRK\n                    | PSEUDOCONSOLE_WIN32_INPUT_MODE,\n                &mut con,\n            )\n        };\n        ensure!(\n            result == S_OK,\n            \"failed to create psuedo console: HRESULT {}\",\n            result\n        );\n        Ok(Self { con })\n    }\n\n    pub fn resize(&self, size: COORD) -> Result<(), Error> {\n        let result = unsafe { (CONPTY.ResizePseudoConsole)(self.con, size) };\n        ensure!(\n            result == S_OK,\n            \"failed to resize console to {}x{}: HRESULT: {}\",\n            size.X,\n            size.Y,\n            result\n        );\n        Ok(())\n    }\n\n    pub fn spawn_command(&self, cmd: CommandBuilder) -> anyhow::Result<WinChild> {\n        let mut si: STARTUPINFOEXW = unsafe { mem::zeroed() };\n        si.StartupInfo.cb = mem::size_of::<STARTUPINFOEXW>() as u32;\n        // Explicitly set the stdio handles as invalid handles otherwise\n        // we can end up with a weird state where the spawned process can\n        // inherit the explicitly redirected output handles from its parent.\n        // For example, when daemonizing wezterm-mux-server, the stdio handles\n        // are redirected to a log file and the spawned process would end up\n        // writing its output there instead of to the pty we just created.","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/wezterm/wezterm/blob/08e5e0afc6007567d3d131bc2ec1382423c0d2da/pty/src/win/psuedocon.rs#L83-L119","documentation":"On terminal resize, wezterm calls ResizePseudoConsole with the new dimensions; a failing HRESULT is reported together with the requested size. ConPTY commonly rejects degenerate sizes (0 rows/cols) and can transiently fail during rapid resizes or while the conhost side is shutting down.","triggerScenarios":"Resizing to 0x0 or other out-of-range sizes; resizing during pty teardown; rapid successive resizes hitting ConPTY race conditions; conhost crash mid-resize.","commonSituations":"Dragging window edges back and forth aggressively; panes being closed while a resize event is in flight; embedders forwarding arbitrary dimensions.","solutions":["Clamp dimensions to at least 1x1 before calling resize","Treat resize failure as non-fatal: log and keep the last good size","Update Windows and wezterm; ConPTY resize quirks are patched over time","Map the HRESULT from the message against winerror.h to confirm which case it is"],"exampleFix":"// before: forward raw sizes\ncon.resize(size)?;\n// after: clamp first\nlet clamped = COORD { X: size.X.max(1), Y: size.Y.max(1) };\ncon.resize(clamped)?;","handlingStrategy":"validation","validationCode":"// embedders: never forward degenerate dimensions\nfn clamp_size(size: COORD) -> COORD {\n    COORD { X: size.X.max(1), Y: size.Y.max(1) }\n}","typeGuard":null,"tryCatchPattern":"// treat resize failures as non-fatal; keep last good size\nif let Err(err) = con.resize(clamp_size(size)) {\n    log::warn!(\"conpty resize to {}x{} failed: {err:#}\", size.X, size.Y);\n}","preventionTips":["Clamp rows/cols to >= 1 at every resize boundary","Coalesce rapid resize events before forwarding to ConPTY","Ignore resizes for panes already closing"],"tags":["windows","conpty","resize","pty"],"backgroundTag":"conpty-resize-failed","analyzedSha":"08e5e0afc6007567d3d131bc2ec1382423c0d2da","analyzedAt":"2026-08-20T04:47:31.434Z","contentChangedAt":"2026-08-20T04:47:31.434Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}