openai/codex · error · anyhow::Error

failed to resize console to

Error message

failed to resize console to {}x{}: HRESULT: {}

What it means

Fires when ResizePseudoConsole returns a non-S_OK HRESULT inside ConPTY::resize, meaning the Windows pseudoconsole could not be resized to the requested COORD dimensions. This typically happens if the console handle is invalid/closed or the OS rejects the size.

Solutions

  1. Verify the HPCON handle is still valid and the pseudoconsole has not been closed before resizing
  2. Check the HRESULT code (e.g. E_HANDLE, E_INVALIDARG) to identify the underlying Win32 failure
  3. Ensure the requested COORD width/height are sane (non-zero, within limits)
  4. Log the error and continue if a failed resize is non-fatal for the caller
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at codex-rs/utils/pty/src/win/psuedocon.rs:156 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of openai/codex@339751715c (2026-08-25). Data as JSON: /api/errors/31b2e81eb6dd15a2. Report an issue: GitHub.

Appendix: source

Thrown at codex-rs/utils/pty/src/win/psuedocon.rs:156

                output.as_raw_handle() as _,
                PSEUDOCONSOLE_RESIZE_QUIRK,
                &mut con,
            )
        };
        ensure!(
            result == S_OK,
            "failed to create psuedo console: HRESULT {result}"
        );
        Ok(Self {
            con,
            _input: input,
            _output: output,
        })
    }

    pub fn resize(&self, size: COORD) -> Result<(), Error> {
        let result = unsafe { (CONPTY.ResizePseudoConsole)(self.con, size) };
        ensure!(
            result == S_OK,
            "failed to resize console to {}x{}: HRESULT: {}",
            size.X,
            size.Y,
            result
        );
        Ok(())
    }

    pub fn spawn_command(&self, cmd: CommandBuilder) -> anyhow::Result<WinChild> {
        let job = Arc::new(JobObject::create()?);
        let mut si: STARTUPINFOEXW = unsafe { mem::zeroed() };
        si.StartupInfo.cb = mem::size_of::<STARTUPINFOEXW>() as u32;
        si.StartupInfo.dwFlags = STARTF_USESTDHANDLES;
        si.StartupInfo.hStdInput = INVALID_HANDLE_VALUE;
        si.StartupInfo.hStdOutput = INVALID_HANDLE_VALUE;
        si.StartupInfo.hStdError = INVALID_HANDLE_VALUE;

View on GitHub (pinned to 339751715c)