openai/codex · error · anyhow::Error

SetHandleInformation failed

Error message

SetHandleInformation failed: {}

What it means

SetHandleInformation returned zero while marking a stdio handle inheritable, so the child process would not receive the standard stream. Often caused by a protected/invalid handle or insufficient rights to change handle flags.

Solutions

  1. Duplicate the handle with DuplicateHandle and set inheritability on the duplicate
  2. Verify the handle is valid and opened with appropriate access
  3. Retry with a freshly created pipe handle for that stream
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at codex-rs/windows-sandbox-rs/src/process.rs:77 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/f759adf039660c97. Report an issue: GitHub.

Appendix: source

Thrown at codex-rs/windows-sandbox-rs/src/process.rs:77

    let mut w: Vec<u16> = Vec::new();
    for (k, v) in items {
        let mut s = to_wide(format!("{k}={v}"));
        s.pop();
        w.extend_from_slice(&s);
        w.push(0);
    }
    w.push(0);
    w
}

unsafe fn ensure_inheritable_stdio(si: &mut STARTUPINFOW) -> Result<()> {
    for kind in [STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, STD_ERROR_HANDLE] {
        let h = GetStdHandle(kind);
        if h == 0 || h == INVALID_HANDLE_VALUE {
            return Err(anyhow!("GetStdHandle failed: {}", GetLastError()));
        }
        if SetHandleInformation(h, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT) == 0 {
            return Err(anyhow!("SetHandleInformation failed: {}", GetLastError()));
        }
    }
    si.dwFlags |= STARTF_USESTDHANDLES;
    si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
    si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
    si.hStdError = GetStdHandle(STD_ERROR_HANDLE);
    Ok(())
}

/// # Safety
/// Caller must provide a valid primary token handle (`h_token`) with appropriate access,
/// and the `argv`, `cwd`, and `env_map` must remain valid for the duration of the call.
// Low-level CreateProcessAsUserW wrapper mirrors the Windows API shape.
#[allow(clippy::too_many_arguments)]
pub unsafe fn create_process_as_user(
    h_token: HANDLE,
    argv: &[String],
    cwd: &Path,

View on GitHub (pinned to 339751715c)