openai/codex · error

is not a valid file descriptor

Error message

{ESCALATE_SOCKET_ENV_VAR} is not a valid file descriptor: {client_fd}

What it means

The escalate socket fd passed via ESCALATE_SOCKET_ENV_VAR could not be parsed as an integer file descriptor, so the escalation client cannot connect to its server.

Solutions

  1. Export the variable with the raw integer fd number as inherited from the parent process
  2. Verify the env var is set by the same code that created the socketpair
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at codex-rs/shell-escalation/src/unix/escalate_client.rs:23 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/f9708293f8fd0392. Report an issue: GitHub.

Appendix: source

Thrown at codex-rs/shell-escalation/src/unix/escalate_client.rs:23

use anyhow::Context as _;
use codex_utils_absolute_path::AbsolutePathBuf;

use crate::unix::escalate_protocol::ESCALATE_SOCKET_ENV_VAR;
use crate::unix::escalate_protocol::EXEC_WRAPPER_ENV_VAR;
use crate::unix::escalate_protocol::EscalateAction;
use crate::unix::escalate_protocol::EscalateRequest;
use crate::unix::escalate_protocol::EscalateResponse;
use crate::unix::escalate_protocol::SuperExecMessage;
use crate::unix::escalate_protocol::SuperExecResult;
use crate::unix::socket::AsyncDatagramSocket;
use crate::unix::socket::AsyncSocket;

fn get_escalate_client() -> anyhow::Result<AsyncDatagramSocket> {
    // TODO: we should defensively require only calling this once, since AsyncSocket will take ownership of the fd.
    let client_fd = std::env::var(ESCALATE_SOCKET_ENV_VAR)?.parse::<i32>()?;
    if client_fd < 0 {
        return Err(anyhow::anyhow!(
            "{ESCALATE_SOCKET_ENV_VAR} is not a valid file descriptor: {client_fd}"
        ));
    }
    Ok(unsafe { AsyncDatagramSocket::from_raw_fd(client_fd) }?)
}

fn duplicate_fd_for_transfer(fd: impl AsFd, name: &str) -> anyhow::Result<OwnedFd> {
    fd.as_fd()
        .try_clone_to_owned()
        .with_context(|| format!("failed to duplicate {name} for escalation transfer"))
}

pub async fn run_shell_escalation_execve_wrapper(
    file: String,
    argv: Vec<String>,
) -> anyhow::Result<i32> {
    let handshake_client = get_escalate_client()?;
    let (server, client) = AsyncSocket::pair()?;

View on GitHub (pinned to 339751715c)