openai/codex · error · anyhow::Error

CreateProcessW ` ` in cwd ` ` failed

Error message

CreateProcessW `{:?}` in cwd `{:?}` failed: {}

What it means

Fires in spawn_command when the Win32 CreateProcessW call returns 0, meaning the child process for the given command and working directory could not be spawned. The error captures the OS error (path not found, access denied, invalid executable, etc.) alongside the command and cwd for diagnosis.

Solutions

  1. Confirm the executable path exists and is a valid PE binary the current user may execute
  2. Verify the cwd exists and is accessible
  3. Check the OS error code (e.g. ERROR_FILE_NOT_FOUND, ERROR_ACCESS_DENIED) for the precise cause
  4. Validate the environment block is well-formed (CREATE_UNICODE_ENVIRONMENT requires a double-NUL-terminated wide block)
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at codex-rs/utils/pty/src/win/psuedocon.rs:211 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/3fc7841af5fedffe. Report an issue: GitHub.

Appendix: source

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

                ptr::null_mut(),
                0,
                EXTENDED_STARTUPINFO_PRESENT | CREATE_UNICODE_ENVIRONMENT,
                env_block.as_mut_ptr() as *mut _,
                cwd.as_ref().map_or(ptr::null(), std::vec::Vec::as_ptr),
                &mut si.StartupInfo,
                &mut pi,
            )
        };
        if res == 0 {
            let err = IoError::last_os_error();
            let msg = format!(
                "CreateProcessW `{:?}` in cwd `{:?}` failed: {}",
                cmd_os,
                cwd.as_ref().map(|c| OsString::from_wide(c)),
                err
            );
            log::error!("{msg}");
            bail!("{msg}");
        }

        let _main_thread = unsafe { OwnedHandle::from_raw_handle(pi.hThread as _) };
        let proc = unsafe { OwnedHandle::from_raw_handle(pi.hProcess as _) };

        Ok(WinChild::new(proc, job))
    }
}

fn resolve_current_directory(cmd: &CommandBuilder) -> Option<Vec<u16>> {
    let home = cmd
        .get_env("USERPROFILE")
        .and_then(|path| Path::new(path).is_dir().then(|| path.to_owned()));
    let cwd = cmd
        .get_cwd()
        .and_then(|path| Path::new(path).is_dir().then(|| path.to_owned()));
    let dir = cwd.or(home)?;

View on GitHub (pinned to 339751715c)