openai/codex · error
failed to openpty
Error message
failed to openpty: {:?} What it means
open_unix_pty's call to libc::openpty returned a non-zero result; the message embeds the last OS error. The kernel refused to allocate a pseudo-terminal pair, typically due to fd exhaustion or missing /dev/ptmx permissions.
Solutions
- Retry after releasing file descriptors if the process table is exhausted
- Check /dev/ptmx permissions and pty availability on the host
- Fall back to pipe-based spawn when PTY allocation fails
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at codex-rs/utils/pty/src/pty.rs:448 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/fd3c00e2251916d0.
Report an issue: GitHub.
Appendix: source
Thrown at codex-rs/utils/pty/src/pty.rs:448
let mut size = libc::winsize {
ws_row: size.rows,
ws_col: size.cols,
ws_xpixel: 0,
ws_ypixel: 0,
};
let winp = std::ptr::addr_of_mut!(size);
let result = unsafe {
libc::openpty(
&mut master,
&mut slave,
std::ptr::null_mut(),
std::ptr::null_mut(),
winp,
)
};
if result != 0 {
anyhow::bail!("failed to openpty: {:?}", std::io::Error::last_os_error());
}
set_cloexec(master)?;
set_cloexec(slave)?;
Ok(unsafe { (File::from_raw_fd(master), File::from_raw_fd(slave)) })
}
#[cfg(unix)]
fn set_cloexec(fd: RawFd) -> std::io::Result<()> {
let flags = unsafe { libc::fcntl(fd, libc::F_GETFD) };
if flags == -1 {
return Err(std::io::Error::last_os_error());
}
let result = unsafe { libc::fcntl(fd, libc::F_SETFD, flags | libc::FD_CLOEXEC) };
if result == -1 {
return Err(std::io::Error::last_os_error());
}View on GitHub (pinned to 339751715c)