openai/codex · error

process is not attached to a PTY

Error message

process is not attached to a PTY

What it means

A sentinel validation guard: resize_conpty_handle was asked to resize a session whose stored ConPTY handle slot (Arc<StdMutex<Option<HANDLE>>>) is None. That means resize was invoked either before the pseudoconsole was created or after the handle was taken/closed at process teardown, so there is no console to resize. The at-fault input is a resize request for a session with no attached PTY.

Solutions

  1. Only perform PTY operations such as resize on exec sessions created with a TTY; start the session with tty enabled.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at codex-rs/windows-sandbox-rs/src/unified_exec/backends/legacy.rs:287 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/71a4e009f31c36e1. Report an issue: GitHub.

Appendix: source

Thrown at codex-rs/windows-sandbox-rs/src/unified_exec/backends/legacy.rs:287

            CloseHandle(handle);
        }
    }

    if exit_code == 0 {
        log_success(&command, logs_base_dir);
    } else {
        log_failure(&command, &format!("exit code {exit_code}"), logs_base_dir);
    }
}

fn resize_conpty_handle(hpc: &Arc<StdMutex<Option<HANDLE>>>, size: TerminalSize) -> Result<()> {
    let guard = hpc
        .lock()
        .map_err(|_| anyhow::anyhow!("failed to lock ConPTY handle"))?;
    let hpc = guard
        .as_ref()
        .copied()
        .ok_or_else(|| anyhow::anyhow!("process is not attached to a PTY"))?;
    let result = unsafe {
        ResizePseudoConsole(
            hpc,
            COORD {
                X: size.cols as i16,
                Y: size.rows as i16,
            },
        )
    };
    if result == 0 {
        Ok(())
    } else {
        Err(anyhow::anyhow!(
            "failed to resize console: HRESULT {result}"
        ))
    }
}

View on GitHub (pinned to 339751715c)